Connect wired alarm system sensors to SmartThings with a NodeMCU ESP8266 [deprecated]

Just a FYI for anyone using this, I made a couple minor updates to my code and documentation this morning based on some feedback from the community. It’s all on Github. Enjoy!

Nate, the write up is excellent. the only issue im experiencing now is the smart app not updating the device status. The testing with the pins show open and close on esplorer but its not getting updated to smartthings. I have went through the whole process twice re-doing the device handlers, devices and smartapp. Using the get and post test works perfect also. It seems that they may be an error in the background with the smartapp not communicating. any way to pull logs and show if its making communication with the smartthings api?

nevermind its working perfect now. I did the device handler, smart app allover again and its working. again, thanks for this write up.

I’m glad you got it working. I’m on the road today so sorry I haven’t been able help more. If you still have problems later feel free to DM me.

First of all - thanks for the excellent write up - I got most of the things done… struggled with a bad USB cable and almost gave up, but persevered and I have the firmware flashed…

Coming to the problem - I am unable to move forward on the Oauth - I keep getting the 500: Internal server error… Have been trying various things like making sure the cloud sensor smart app is saved and published… but havent had any luck…

Any other tips to debug this will be appreciated!

No thread hijack intended. Great work by @heythisisnate on his solution! Nothing but respect for his work, as it has opened my eyes to other possibilities.

Here is another possible option for those already familiar with the Arduino ThingShield platform. My new library does all of its communications via the hub. I am not saying one method is better than another. I am just providing this as an option for using a NodeMCU ESP8266 with SmartThings, via the Arduino IDE.

Re-did Step 5 ( Oauth code generation) and thing started to work!

I’ve redone everything twice now, and it all works until I test one of the pins and it will say “Front Door is 0” then keeps returning “HTTP client: Connection timeout” Any thoughts on what I screwed up?

check to make sure your Oauth steps were correct. this most likely means it cant communicate to the smartthings portal. At least this was my case and once i re-ran the process again it worked.

@ogiewon Thanks! Actually your ST_Anything 1.0 project was my inspiration for this. I got my first ST hub in early January and came across your posts/project around that time. It got me hooked on the idea of connecting ST to my wired alarm system. I was disappointed that the ThingShield could no longer be purchased, so thats when I started exploring options with the ESP8266. It’s great to see that your ST_Anything project now works via LAN, because it does look like it does a lot more than just simple contact/motion sensors and has quite a community following. Well done!

I’m very interested how your code sends network requests to the hub. I couldn’t find any ST documentation on that. Everything I read pointed to using OAuth for HTTP communication. Is this documented? Can you point me to the file in your Github that does the actual HTTP calls (I looked briefly, couldn’t find it)?

There are some distinct advantages of using OAuth API calls instead of direct to hub communication. You don’t have to set any static IP address assignments on your LAN. Also, the device doesn’t even have to be on the same LAN as your hub. This could be really useful if you wanted to monitor things in remote locations but not set up a whole new hub there.

Thanks for the note and keep hacking away on this stuff! You guys are a key part of what makes this community great. I also love the fact that you work on ST_Anything with your son. I very much hope to get my daughters into coding one day … but they’re still a little young for that. We’re focusing on reading first. :wink:

1 Like

@Nate_Newsome I have seen infrequent HTTP timeouts in normal operation (the code is setup to handle/retry in this case), but you shouldn’t be seeing every request timeout. I’m not sure exactly what could be causing that. A couple things to check:

  1. Are you using the right firmware version? @flyize reported similar HTTP timeout messages last week and using the firmware I provided in my Github fixed it.
  2. Is TLS/SSL enabled in your NodeMCU firmware? When it boots and connects you should see SSL: true near the build version output.
  3. Try removing the :443 from the end of the apiHost variable. It shouldn’t matter, but maybe this causes problems with HTTP connections. Port 443 is the default for SSL anyway.
  4. Don’t forget to add /event to the end of the url given to you from ST when setting the apiUrl variable.

If you can’t figure out the problem DM me a screenshot of your variables.lua file and I’ll see if I can spot anything.

@heythisisnate Thank you for putting this together and trouble shooting everyone’s issues.

I’m having an issue getting the init.lua file to run and get the following Error

lua: error loading module ‘credentials’ from file ‘credentials.lua’:
credentials.lua:1: unexpected symbol near '�’
stack traceback:
[C]: ?
[C]: in function 'require’
init.lua:1: in main chunk
[C]: ?

An example of my credentials.lua is

wifi_ssid = “MySSID”
wifi_password = “MyP@ssword!”
auth_token = “11aaa111-11a1-11a1-111a-a111a11a11aa”

I was wondering if the Special Characters in my password could be causing issues or if something else could be the roor? I do use @ and ! in my password.



Take a look in my new “SmartThings” v2.0 Arduino library and you will see the code that communicates with the hub. Also, in the “extras” folder of that library you will find the groovy Device Handler examples that correspond to the sketches found in the “Examples” folder.

The “SmartThings” library is truly a standalone package. My “ST_Anything” library depends heavily upon it, but users can indeed use the new “SmartThings” library without it.

And to answer your question about documentation, I have not found anything specific regarding this approach. I found another user’s example and based my work on his.

@CoffeyInOrlando I don’t think the @ or ! characters would be the problem. The error message indicates its on line 1. It looks like possibly your editor converted the double quotes surrounding the strings into “smart quotes” aka curly quotes. While these look cute for humans, they’re not so good for computer programs.

Try disabling smart quotes in your editor, or use a more coding-friendly editor like Sublime text.

1 Like

hey whats up Nate,

hope all is well, just want to pick your brain again. is it possible to
utilize the smoke detectors and siren that is integrated in my security
panel (see attached screenshot of wiring diagram). Would be cool if i can
add the smoke alarms and siren. Was thinking the smoke alarm would act
similar to contact and siren would need like an on and off function to

thanks again for all your help.

@Raymond_Lopez I added support for a wired smoke detector as you asked! Could you test it for me since I don’t have any such smoke detectors at my house?

The updated code is here:

You’ll need to add the new DeviceHander to SmartThings and also update the SmartApp code. Then, create the Smoke Detector device and choose the Device Type “NodeMCU Connected Smoke Detector”. After you’ve updated the SmartApp code and re-published, go into your SmartThings app, go to Automation -> SmartApps -> Cloud Sensor and you should be able to select the Smoke Detector(s) that you just added as devices to monitor.

The Lua code on the NodeMCU does not need to change. Just add the new Smoke Detector device to the list in the variables.lua file, and it should just work.

Please let me know if this works out. If so, I’ll merge it into master and update the documentation.


I will definitely test the smoke alarm once I get passed the contact and motion sensors. While I was trying to hook up the nodemcu to the alarm panel I noticed all my ground on the alarm panel have 2k ohm resistors but the zone wires do not.

I ran a cable to the d2 pin on the nodemcu to zone 1 on the alarm panel. This is the front door wired sensor, I then ran a cable from the ground on the panel to the ground on the nodemcu. I do not see anything working. Am I missing something here?

You can remove the resistors. They’re not needed.
You want to disconnect the wires from the alarm panel and just connect each pair of wires from each sensor directly to the digital pin & ground on the NodeMcu. We’re bypassing the alarm panel completely.

thanks Nate that worked. its functioning perfectly now. is there anyway to
leverage both the nodemcu and the alarm panel? I would like the alarm panel
still be aware of sensors open and close. anyway doing that?

It may be possible, but probably not easily. The reason why this works and is so simple is because the sensor circuits make a single closed loop. If you’re trying to connect it to two different loops, that makes it significantly more complicated and I’m not even sure how you would do so. Unfortunately it’s out of scope of this project.

In my opinion, those alarm panel systems are last century’s technology and there’s not much value in keeping it functioning. Personally, I eventually plan on ripping out the alarm panel from the wall in my house and replacing it with a tablet touchscreen with SmartThings running on it.