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

(Nate Clark) #1

Update July 20, 2017:

Thanks to tremendous support from this community, this alarm system integration project has evolved into a DIY kit project that we’re calling Konnected Security. Please see the latest Release Announcement here

The open-source source repo has also moved to konnected-io/konnected-security on Github

Original Post below:

The house I live in was built in the early 90s and came with a built-in home security system. I’m not interested in using the outdated alarm system panel, but I wanted to connect the contact sensors in my doors and the motion sensor in my house to SmartThings. I learned about the NodeMCU ESP8266, a small, cheap, programmable development board that has WiFi built in. I set out to connect my door and motion sensors to the NodeMCU and program it to update SmartThings every time a change is detected.

This was my first time using any sort of development board, and I have zero electrical engineering experience. I am, however, a software developer by profession, and lua programming looked familiar to me, so I was hopeful I could make it work. I’m also new to SmartThings, but have spent enough time here on these forums that I figured I could make things work. A few evenings of work later, and it works great!

I bought a NodeMCU board from Amazon for less than $10 and started playing with it:

I basically opened up the alarm system panel in my house and identified the pairs of wires that went to each door and motion sensor, and redirected those to the NodeMCU board. Each sensor is connected to a GPIO pin on the board, and the software I wrote sets up a listener that makes an HTTP POST to the SmartThings API every time a change is detected on the sensor.

I’ve also written a SmartApp and two device handlers (one for a contact sensor and one for motion sensor) for SmartThings.

I’ve had it working for a few days now and it works just about perfectly! The response time is very quick (less than a second) to update the state of the sensor in the SmartThings app.

The code for the NodeMCU and Smarthings is here:
If there’s interest, I’ll spend some time writing more documentation or how-to guide. Getting code running and debugging on the NodeMCU was tricky at first for a noob like me.

Some pictures:

[RELEASE] Konnected Security 2.0 - Connect Wired Alarm System Sensors and Siren to SmartThings - big update and new name!
Using existing Home Security System (Honeywell, Vista, etc) Sensors with Smartthings
My home is wired for a security system. Any way to take advantage of this to integrate a security system into ST?
Announcing the "ST_Anything" Arduino/ThingShield Project
Wired system with smart Things? (Existing wires, no devices--what now?)
Using Existing Door Sensors of Alarm
Multiple Device Handlers talking to a single Rest API
Basic Device Handler for IP garage door sensor--help needed
Smart Things integration with existing (inactive) ADT system
Convert Your Wired Alarm System into a SmartThings Smart Home Monitor System for Under $25 with NodeMCU ESP8266 (2017)
Connect any wired alarm system to SmartThings with Konnected - funded on Kickstarter in 2 hrs!
Wireless plunger sensor
Convert Your Wired Alarm System into a SmartThings Smart Home Monitor System for Under $25 with NodeMCU ESP8266 (2017)
[Deprecated as of Apr 8, 2018] Smart Home Monitor Exit and Entry Delays (Version1)
Hardwiring Motion/Multipurpose Sensors?
(Dan) #2

Very nice work!

(Marcos) #3

Awesome job @heythisisnate

I was able to use your code to integrate ST with my current wired sensors.

(Dima) #4

Setting up a NodeMCU is a bit complicated for someone like me.
Is it possible to attach all the wires from the old alarm to a zwave or zigbee sensor of some sort and connect the sensor to ST?

Integrating a wired alarm to work with smartthings
(Nate Clark) #5

@mparentes Thank you! I’m very happy to hear that you’ve been able to use it. Please share more details of your experience. One issue that I’m dealing with is that occasionally I think a request is dropped or possibly received out of order, and the sensor state gets stuck in the wrong position. For example, if I open and close a door several times in quick succession, a HTTP request to SmartThings should trigger in order for every open and close. Sometimes, however, the sensor is stuck in the open state. I think this may be due to a bug in the error handling/queuing of requests in my Lua code. Can you tell me if you’ve had any similar problems?

@copperz I don’t know, it’s probably possible, but I don’t know of any such sensors and even if they were available, it would probably cost a lot more than the $8 NodeMCU board. I’ve considered the idea of re-selling NodeMCU boards to people with my software pre-loaded onto it. Is this something you’d be interested in? Would you pay for this convenience? I totally understand that flashing a NodeMCU is a little bit advanced for someone who does not have a development background.

(Dima) #6

@heythisisnate yes, potentially.

(Adrian) #7

This is excellent. I was actually thinking to do the same with my old wired alarm. Im travelling at the moment and hard to read much beyond your intro. Have you thought about controlling the alarm and strobe as an output as well? What are you doing on end of line resistors?

(Nate Clark) #8

Hi @dradprice3, I don’t think I have a siren or strobe in my setup at my house, but I’m sure it probably could be done. To be clear, I’m bypassing the alarm system panel entirely and just using the wiring for the sensors.

What are you doing on end of line resistors?

Um … nothing. I’m not an electrical engineer, I’m a software guy. I don’t know anything about resistors, so I decided to just try plugging in the wires directly to the NodeMCU and see if it works. It does! Maybe this is a grave noob mistake, but so far so good. From what I’ve read the ESP8266 has an “internal pullup resistor” which I am enabling in the code, but I’m not even 100% sure what this means.

(Kevin) #9

The pull-up resistors help to make sure the voltage at the ESP input is in a clear hi or low, 1 or 0, state. Without them, it might possibly “float” somewhere in between hi and low, or bounce around creating open close events unexpectedly.

(Kevin) #10

I’m only seeing one picture if you meant to post more :slight_smile:

(Nate Clark) #11

I’m only seeing one picture if you meant to post more :slight_smile:

Since I’m a SmartThings community noob, the website only let me post one picture. There are a couple more on my Github project (linked above).

(Amauri Viguera) #12

I’m not entirely sure this is what @dradprice3 meant. End-of-line resistors are often used in alarm systems to make sure that the wiring hasn’t been compromised.

You basically have a resistor in series with a device, which gives the panel itself an indication that the contact is open (no voltage) or “closed and secured” – by taking into account that the resistor in the line reduces the voltage. Without the resistor, you could fool the panel by creating a short in the line after the contact. If the panel doesn’t care about voltage it would just see that the loop is closed and wouldn’t know that the wiring has been compromised.

(Kevin) #13

I haven’t figured out your approach here, I’ve been using @Jason_Bush’s example. I don’t see where you create a SmartThings endpoint for the ESP8266 to post to?

With Jason’s there is a DH for the whole ESP which creates difficulties handling multiple contact sensors. With yours you have multiple DH plus a smartapp for each ESP. My preference would be to have one DH because in my head I want to hook as many sensors to each ESP as possible :wink:

I’m more of an EE / embedded software guy :slight_smile: I am not familiar with LUA, I’ve been using Arduino/C on mine.

(Kevin) #14

I think you are right, I was referring specifically to the ESP pullups Nate asked about. I wasn’t familiar with the alarm system end-of-line resistors. I think in order to use end-of-line resistors as you describe, you have to detect 3 states (hi/mid/lo) which can’t be done on a ESP GPIO pint (I don’t think???). You would need an analog input for each contact sensor; ESP only has one.

(Nate Clark) #15

@kevin The endpoint is created by the SmartApp. See:
There’s documentation on how this works here:

If you’re using my Lua code, you’ll just have to edit the variables.lua file and update the apiEndpoint variable to the SmartApp endpoint that you get back after completing OAuth flow as documented here:

The only reason for multiple device handlers is that I’m using two different types of devices (Motion sensor and contact sensor) and they have different ST capabilities/attributes. If you only have contact sensors, you only need the one device handler to handle as many sensors as you can fit on the ESP.

I wasn’t familiar with Lua before this project either, but it feels a lot like Javascript which I do have 10+ years of experience with. It was surprisingly easy to figure out! I’m sure a similar thing could be written using Arduino too, it’s just not my cup of tea.

I hope this helps. Let me know.

(Kevin) #16

Maybe I mis-spoke a bit, you have to add 3 contact sensor devices that use your one DH. I’m hoping for one device for each ESP, with one DH (which has multiple contact sensors in it). For comparison, like a SmartThings multisensor has several capabilities in it… we don’t have to add a separate device for each capability.

Not knocking your work by any means :slight_smile: It seems like a nice straight forward example! Thanks for sharing!

(Nate Clark) #17

Gotcha. I think I understand what you’re asking, but I still don’t see how you could have only one device for three different doors that you want to monitor. I understand the example of a multisensor which does have a few different capabilities on the same device, but in this case each device only has one capability (contact sensor). Yes, in my example I set up three different devices, each using the single device handler, so that each door opening/closing can be monitored independently.

(2exclusive) #18

I would be interested in purchasing this board with your code already loaded. Can you also provide a write up to modify once received also? I currently have 8 window contact sensors and 3 door sensors. Would the module be able to handle that? Thanks in advance

(Jack Duffy) #19

Yes, I would be interested in purchasing.
Thank you

(Nate Clark) #20

@jackduffy @Raymond_Lopez @copperz I’m glad there’s interest! At this point I’m not really ready to distribute. Mainly because I can’t think of a good way to securely load your credentials … I’d need your WiFi password, SmartThings OAuth token, and device ids to fully preload the NodeMCU. I think this might be tricky, and you’d probably want to test it out using your computer anyway.

@Raymond_Lopez With a total of 11 sensors, I think you’d need at least 2 NodeMCU boards (maybe three). The board has 13 GPIO pins, but in my experimentation I found that many of them don’t work well or cause strange problems on the device. It took a lot of trial and error, but I found 4 or 5 pins that work consistently. It shouldn’t be a problem at all to have multiple boards all posting to the same SmartApp.

I’m planning on writing up step-by-step setup instructions with a lot more how-to detail in the coming week and packaging up my code for a release. I hope to make it easy enough for even a non-programmer to set up.

Also, I think I solved the sensors out-of-sync problem that I described the other day! I improved my lua code to better handle HTTP timeouts, which I observed occasionally. The latest code is up on my Github: