SmartThings interfacing with local REST service


(Tom Beech) #1


I’m developing a RESTful service to run on my tablet pc (which is mounted on the wall) so that I can control it from SmartThings. Primarily, I want to ensure i can turn the screen on / off within the rules of SmartThings.

I have my REST service running, but was just wondering if I am actually able to speak to services inside my local network, or if calls are made externally, and so I would need to forward appropriate ports and use my public IP to speak to the API.


(Lukas Greblikas) #2

Building LAN-Connected Device Types

Unfortunately your SmartApps and Device Types will be still executed in the cloud even when you can make local network calls directly to/from the hub.

(Tom Beech) #3

So the only way for me to interface with the rest service is to open it up to the outside world and secure it using some kind of authentication?

(Kevin Tierney) #4

You can interface with it locally, but what @Greblys is referring to is that the commands have to go through the ST servers before being sent from the hub so even though it is connected to your local network, if your internet goes down, it won’t work during the outage

(Tom Beech) #5

ah, OK- cool. I think the example API documentation refers to uPnP specifically… I’ll have to have a read of the documentation.

(Kevin Tierney) #6

There’s a section on REST requests there too

REST Requests

(Ben Lebson) #7

You’ll be using the hubAction command to pass commands to the device. Check out the Generic Camera Device type for an example of how to use this function (it’s kind of tricky):

Just as a note; Setting your Device Network ID (DNI) as the devices IP:PORT in Hex is very important. Also, you need to return the hubAction command if you are using it within another function.

(Tom Beech) #8

Thanks, i’ve got my device up and running via local http POST / GET commands. Cuts out a massive security hole in the system! The API docs are not very clear, but I got there in the end thanks to the community! :slight_smile:

(Euan) #9

Hi Tom,

I’m trying to do something similar. Is it possible to look at your code? I’m new to Groovy, and struggling to get it to work.

Many thanks