ESP8266 Node MCU - Temp, Contact, Water Sensor

Let me start by saying I’m not a dev by any means, I just wanted to share what i got working. This is not a tutorial, more like a list of things I used.

Over the last few months I have wanted to get my ESP8866’s into smartthings somehow. I’ve read a bunch of posts and didn’t really find anything complete. There’s a thread on here somewhere that I started from. The dev that posted the original code disappeared and I took his posted code and modified it to work for my needs.

I made a contact sensor and a water sensor. Both sensors use the same arduino code, but have different device handlers.

Quick materials needed

  • Node MCU 12e ESP8266
  • CATALEX water sensor
  • Door reed switch
  • DS18B20 Temperature sensor
  • Arduino IDE

Load the .ino file to the arduino, you will need to setup the ip address and wifi settings. I only tested this on static settings, not dhcp.

Make sure you can access the webserver by the below URL’s. xxx=last octet of your ip address
http://192.168.100.xxx:9060/getstatus
http://192.168.100.xxx:9060/getTemp

Load up the device handler in smartthings.

Add a new device and choose the recently added device type. Use the mac address for "Network ID"
Edit the preferences and Set the IP,Port and Mac address of your ESP8266

If all went correctly…it should be working. Like I said, I’m not a dev. Feel free to critique, change, suggest anything you would like. I’m hoping others would be able to step in and help out if people want to use this.

Also, I don’t really understand Github, but here is the repo(I hope).

https://github.com/gopherxx/smartthings-sensor/tree/master/smartthings-sensor

-Thanks

9 Likes

Thanks for posting this. I’ve been toying with other similar ESP8266 options. As soon as I get some time, I’m going to load your code and see how it works for me. I’m a little surprised this does not have more responses…

I hope it works for you! I’m playing with some MQTT now, but I love the simplicity of this and there is no need for a server in the middle.

That’s why I like the native 8266 implementations. No server to worry about

Great to see some other ESP8266 users :slight_smile: Are you just polling the ESP8266 from ST then?

I didn’t write the original code, but the esp sends an update if the contact sensor or temp state is changed. You can also refresh temp from the app. I wanted to get the ability to refresh the sensor state from the app, but I just haven’t been able to get it right. I’m not a dev and this is about as much code as I get into at this point. I’m still learning right now.

Just as someone else said, it is AWESOME to see another ESP8266 fan working with ST. I have ESP-01’s and ESP12E’s all over the house and have been relying on IFTTT recipes for some of my REED sensor notifcations and rules, which has worked flawlessly I have to admit. But…integrating them with ST would add a whole new level of geeky goodness! I’ll definitely keep an eye out on this site and add to it as I start ‘playing’.

I didn’t think devices could send data to the ST hub unless OAUTH was setup via a SmartApp (separate from the DH). Quick glance at this code seems to send data directly to the ST hub.

Can you post link to the code you used, I’m just curious if there is more discussion of OAUTH there.

Thanks!

I think these integrations with the ESPs directly end up responding to a web request and the data is pushed to the ST server then. Its not pushed from the ESP to ST as much as requested from the ESP.

Take a look at the sendnotify section of the arduino, it sure appears to send an update. If you look at the device handler, the parser seems to handle the incoming messages. I can confirm that if I open the sensor, smartthings is updated immediately, no delay whatsoever. I do know that if the mac is not specified, you do not get the updates at all. Only the refresh pulls will work in that case.

Take a look at this thread. The current code is similar, but I have noticed a few slight changes as he updates it from time to time in GitHub.

The code I based mine on was from another member that had it saved, but this is the base for it all. I think there is another thread about temperature as well under his profile.

That’s incorrect. The NodeMCU pushes data to ST hub. There’s no polling necessary in this case.

I stand corrected. As I look closer, I see the push. Sorry for the misinformation.

No need to be sorry on this thread! I think it’s awesome to have a discussion where we can all learn and validate our thoughts.

This is GREAT! I fired up one of my NODEMCU’s last night and created the device with the dummy temp reading and all is working nicely. I plan on adding real-deal sensors to it over the Christmas break and will let you know how all goes. Thank you again for sharing your progress with us…this really is VERY COOL! Hope all have a most excellent Holiday!

Good to hear. Were you able to get DHT11’s working with it? I was going to work adding support for it today, but my “real” job needs me :slight_smile:

That’ll be my next move…getting the DHT11 fired up on it. I started working on the sketch last night and hope to have it running in the next day or two.

I took a first stab at DHT11 support, haven’t been able to get the the device handler yet. New esp code is in my github link. I doubt I’ll have time to do much with it anymore today. Seems to work for me though.

The code looks real good, you added the Humidity to it I see as well. I had not gotten that far so very cool. I’ll load up your code as well and go from there. If I make any progress on the device handler, etc…I’ll share it here as well.

would you be doing a detailed write up for noobs like me? thanks in advance