Help getting started with ST (custom Arduino+Ethernet device: how to connect it to ST?)

I am a ST noob and need help adding an unsupported device.

I have developed a Garage door monitor using an Arduino and Ethernet shield.
I can get the state of the garage door (via a contact sensor) by accessing the web server running on the Arduino.
The Arduino is also capable acting as web client.

Here is where I need the community’s help. I don’t know what I need to create in ST (device handler, virtual device, Smart App, etc) to get the garage door status on the dashboard.

Here is what I looking to achieve:

  1. The garage door monitor updates the ST (via a web request) on a state change (door open/closed)
  2. ST shows the garage door status and have the ability to send a web request to the garage door monitor to open/close

Where do I begin and thanks for the help!

There are a couple of different ways to do this, and hopefully other community members will chime in.

One of the simplest ways would be to create a virtual switch which represents the Arduino. Then its status would show up in the SmartThings app.

So now you’ve got a virtual switch and you want to create bidirectional communication.

For anything complicated, see the developer docs at the link at the top right of this page.

For just a simple on/off, you can use the free IFTTT maker channel as a “man in the middle.”

You have your device send to the IFTTT maker channel as the “if” in an IFTTT recipe and use turning on the virtual switch in the smartthings channel as the “that.” Set up a separate recipe for the off.

You can then do exactly the same thing in the opposite direction: have turning on the virtual switch in the smartthings channel then send something via the maker channel as the that. And again you would need two recipes, one for on and one for off.

The big question with IFTTT is always how much lag Will there be? At my house it’s a pretty consistent eight seconds, which works for most of my use cases, but it varies from person to person and some people have a lot more lag.

The IFTTT maker channel method probably isn’t what you want to do in the long term, as there are more direct methods, but at least it would give you a proof of concept and some initial functionality while you’re looking into the other methods. :sunglasses:

And eventually you would want to write your own custom device type handler for the virtual switch so that you could have the appropriate labels (open/close instead of on/off), add some capabilities, etc.

@JDRoberts , thanks for the advice.

Once I create the simulated switch, how does the switch get the state data?
Will I need to create endpoints via a SmartApp to get IFTTT to work?

No, SmartThings already has an IFTTT channel, so you just use that. :sunglasses:

If you haven’t used IFTTT before, see:

SmartThings IFTTT channel. These options are immediately available to you, no additional coding required.

I don’t know of a way for the device to ‘push’ it’s status to SmartThings but you can poll it using a local http request by using hubAction in a custom devicetype.

For the IFTTT maker channel, you just have to hit it with a web request for the IF, and it can send a web request for the THAT.

So…you could hit your IFTTT account with a web request and have that turn on your switch in the SmartThings channel.

Or turn on your SmartThings switch, ST will report that to IFTTT ( no additional coding required), then have that switch being turned on send a web request to your device from the IFTTT maker channel.

Thanks @JDRoberts.

I played around with your suggestion and the main issue is that the Arduino is not public facing. For security reasons, I do not want to make it public.

@blebson, that’s what I was trying to figure out. Where to put the code for polling/receiving statuses.

From what I’ve read so far, here is my understanding:

  1. In order for the Arduino to “push” it’s status change to ST, that would have to be done via a web service endpoint as part of a SmartApp?
  2. Creating a new device type and using the hubAction will allow the device to get the current state?
1 Like

You should still be able to have the device report to smartthings via IFTTT, I believe.

You wouldn’t be able to get the information to come back the other way (from IFTTT to the device) if it’s not public.

I use this method to tie iBeacons to SmartThings, but it’s a one-way conversation.

I believe you’d need to create a web services smartapp in order to push the status to SmartThings.

A hubAction DTH would send a GET/POST request to the webserver and then parse the response. I am currently doing this with a Raspberry Pi, though I am sending commands to it rather than updating the status.

I am stuck on getting the hubAction DTH to parse the response.

I’ve set my device network id to equal the hex version of the IP:PORT (c0a80104:22b8) of the device that I created based on the DTH.

The device is making the GET call, but I do not see that parse() is even being executed.
The only thing that I have in parse() for now is “log.debug xxx” and I am not seeing it come through the live logger.

Am I supposed to be setting the device network id of the device the same as the IP address of the web server that I am sending a GET request to?

This is what you need, I use this to control http end point of nodemcu. Work within LAN.

The control is one way currently, no polling of response from http server.

1 Like

@CSC, I tried the code that you provided, but I still can not get the DTH to run the parse statement. Here is the output from the live logging:

 4:05:34 PM: debug GET /GetLeft HTTP/1.1 
Accept: */* 
User-Agent: Linux UPnP/1.0 SmartThings 
Content-Type: application/x-www-form-urlencoded 

  4:05:34 PM: debug The method is GET
  4:05:34 PM: debug The Header is [HOST:, Content-Type:application/x-www-form-urlencoded]
  4:05:34 PM: debug path is: /GetLeft
  4:05:34 PM: debug The device id configured is: C0A80104:22B8
  4:05:34 PM: debug ---ON COMMAND--- /GetLeft

I set the DNI to the hex value of the server that I am doing a GET on as per other discussions.

What am I missing?

So just to confirm, when you put into a web browser you get a response/page with a result?

1 Like

Man, do I feel dumb…apparently I’ve been trying to reach the server on the wrong port all this time. It is 88 and not 8888.

@blebson, if you didn’t ask, I would have totally missed it.

Using the correct port, produces the results I was looking for.

Thanks for all your help!

1 Like

Glad to hear you got it working, often a fresh set of eyes is all you need to figure out an issue!

1 Like

So the virtual http switch help? Or you hv different solution? Do share it ti benefit the rest :smiley:

1 Like

Yes, the virtual http switch helped.

Thanks for all of the help.

1 Like

I was working on the same Garage project a while back and I made it work without virtual switches, IFTTT etc.

You can find my code here:

Works perfectly for me for many months now.

Direct communication ST - Arduino.
Arduino pushes events to ST.
ST can poll/refresh if needed.
Can detect if Arduino is offline - Will show Unknown state in ST.
I also attached temperature sensor to Arduino to know temperature in the garage. You can cut that part out.
Also I didn’t want plain REST APIs to open my garage and was experimenting with SHA256 encrypted password and it turned out pretty good.

Few notes on very important settings:

  1. in Device Handler settings you have to input Arduino IP address, Port as well as MAC address. MAC address must be all uppercase with no columns. e.g. DEADBEEFFEED
  2. You must have static IP address for your ST hub and hardcode that IP address in Arduino code for it to be able to PUSH to ST hub:
    // Smartthings hub information
    IPAddress hubIp(192,168,0,50); // smartthings hub ip
    const unsigned int hubPort = 39500; // smartthings hub port

Would be happy to help if you have any questions.

p.s. I borrowed a lot of code from @Charles_Schwer . Thank you, Charles!


That’s pretty cool. Thanks.

I glanced over your code and can’t figure out how ST is setup to receive statuses.

Is that done in the DTH or SmartApp?

When is the Arduino MAC utilized?

Everything is done in DTH. there is no smartapp.

device.deviceNetworkId = settings.mac;

From my experiments I figured out how it works:

  1. you set device.deviceNetworkId = settings.mac; Now ST knows that your DTH is associated with physical device which MAC address is DEADBEEFFEED for example.
  2. Device (Arduino) issues a POST http request to hubIP:39500 with some data (I used JSON) (see sendNotify(EthernetClient client) in arduino code)
  3. ST Hub listens on port 39500 for any incoming http requests.
  4. ST Hub receives POST requests and determines that it is incoming from some device with MAC address DEADBEEFFEED for ex.
  5. Because DEADBEEFFEED is associated with our Garage DTH, ST parses and sends that request to parse() method of Garage DTH.
  6. Do your magic in parse() method.
1 Like