[OBSOLETE] Convert Your Wired Alarm System into a SmartThings Smart Home Monitor System for Under $25 with NodeMCU ESP8266 (2017)

@Simon_Knight could I see a screenshot of your device info page?
https://graph-eu01-euwest1.api.smartthings.com/device/show/6fdd6821-6ddc-4028-8864-############

@TylerDurden I saw this in the product description for those 5V relays from Amazon U.K.:

But, your concern definitely makes sense. I honestly don’t know. I’m not an EE either. I’m sure @Vyker will find out and let us know.

Ah, good observation, I must not have dug into the deeper description. I would definitely be interested to know if it works for @Vyker … Considering the listing claims it will work, and my formal electronic circuit education is over 25 years old, and consisted of high school physics, I’m probably wrong in my conclusions. :slight_smile:

Here’s a good explanation for “opto-isolation” of relays modules:

https://arduino-info.wikispaces.com/RelayIsolation

100% isolation is mostly required to reduce EMI from heavy loads (like motors) which can cause interference with Arduino (or ESP8266.) The website above shows the “ideal wiring solution” but is not required for normal operation. A shared ground wire “should” not be an issue (however never connect 2 positive voltage sources together, as current will always flow from one to the other!)

Please do not try to power the coil of the relay directly from the ESP8266, as it’s digital output pins aren’t capable of supplying enough current. Only power the opto-isolator of the relay module.

Hey Dan, what do you mean this this? Can you explain it in layman’s terms for those of us who don’t really understand electricity :slight_smile:. I’ve had flawless success with my relays powered by the “3V3” pin on the ESP, and the trigger IN on the relay connected to one of the digital pins. Is this what you mean?

Nate,

I’ve got it figured, but am not sure why your original code doesn’t work for me. have 6 wired motion sensors, no contact sensors, and an alarm siren. I started from scratch, re-authorised everything, and was still getting the 500 error with live logging showing:

java.lang.NullPointerException: Cannot execute null+null @ line 55

The error arises from line 55 of your code:

def allSensors = contactSensors + motionSensors + smokeDetectors - null

If I remove the contact and smoke detectors, changing line 55 to:

def allSensors = motionSensors

It works fine.

Thanks for all the hard work and speedy responses - this makes a great base to a smart-things based alarm!

Nate,

Let me try to explain… In general, the NodeMCU ESP8266 boards are not capable of outputing very much current. Each ESP8266 digital pin can source ~12mA and sink ~20mA. Sourcing means they are outputting 3.3V while sinking means that are providing a Ground.

The 3.3V voltage regulator on the NodeMCU boards is responsible for converting the USB or Vin 5V down to 3.3V to be used by the ESP8266 chip. This voltage regulator is rated for ~300mA [Update: It appears that different boards use different 3.3v regulator chips. Some output as much as 1000mA!]. Thus, if all pins are sourcing 12mA of current to whatever they are attached to, you end up consuming ~120mA of the 300mA just with digital outputs. In addition to this workload, the ESP8266 CPU needs power, especially to transmit WiFi signals. This can be as much as an additional 170mA.

Thus, between the ESP8266’s CPU, WiFi, and Digital output pins, you’re already at ~290mA of the 300mA the NodeMCU’s 3.3v regulator can provide.

Thus, my statement that it is fine to use a digital output of the NodeMCU board to trigger the opto-isolator of a relay board. But I recommend strongly against trying to power the magnetic coil of the relay directly from the NodeMCU’s 3.3v pins. A relay can use 75mA to 120mA of current to keep the relay “on”. This is too much for the NodeMCU’s 3.3v regulator chip to handle, in addition to all of the other work it has to do just to keep the ESP8266 running smoothly.

Therefore, the safest and most robust approach is to power the relay’s magnetic coil from a different voltage source. Again, you still use a NodeMCU digital pin to trigger the opto-isolator on the relay board.

Using the LoLin NodeMCU Base board, can can tap into it’s voltage regulator to get power for the relay’s magnetic coil. However, I believe that base board’s regulator is only capable of outputting 5v. I believe all of the 3.3v power is an output of the NodeMCU board’s 3.3v regulator. I am not 100% certain of this! A simple test if to take a base board, remove the NodeMCU board from it, and then power the base board on. Using a multimeter, check the voltages at the various voltage terminals to see if anything other than 5V is supplied by the base board. I believe the base board simply supplies 5v to the Vin pin on the NodeMCU board. If so, I would use the base board’s 5v source to power the relay board’s magnetic coil.

Hope this helps explain it.

UPDATE: I found the datasheet for the 3V relay used on the relay board Nate has been using. It states that the coil will draw 120mA when the relay is activated. http://www.lemicro.cn/rar/SRD(T73).pdf. So, if someone was to add 2 of these relays, both powered off of the NodeMCU’s 3.3v pin, you’d consume 240mA of the onboard voltage regulator’s 300mA. Not a good idea.

[UPDATE: As I noted above, some NodeMCU boards actually have a 1000mA 3.3v voltage regulator chip on them. If so, then you should be able to run the relays directly from the 3.3v pin on the NodeMCU board. Look for the AMS1117 marking on the voltage regulator chip to see if yours is capable of 1000mA.]

2 Likes

Good morning. I’m excited to give this project a try! I have one question. How strong is the wifi signal on the NodeMCU board. My alarm panel is in the basement and on the opposite side of my house from my router and Smartthigns hub. Will the wifi on the board be able to cover that distance? Thanks.

There is a small integrated antenna on the board. The question, I guess, is how good your WiFi signal is at the location of your alarm panel? Can you get a reliable signal on your phone/tablet at that location?

@Simon_Knight I’m glad you solved it. I understand what the problem is now. I will fix this in a future release.

The wifi radio is not very strong. You’ll probably want to test it before hooking everything up. The NodeMCU firmware has a function wifi.sta.getrssi() that will tell you the wifi signal strength. This is a number between -100 and 0. Closer to 0 is better. -80 is probably the minimum required to work at all. -75 is acceptable. -50 or more is excellent.

I get about -60 and my panel is in a closet about 25ft from my wifi router.

A wifi signal extender or second access point might be necessary for you.

Thanks for the response. I just bought a new router with great range so I’ll test it out and ho[e I don’t have to buy an extender.

For anyone looking at relays for wiring up their alarm I found this one on Amazon and it’s Prime eligible so you can get it in 1 to 2 days instead of waiting a month to get it like the other recommended relay.

https://www.amazon.com/gp/product/B01ICYMF08/ref=ox_sc_sfl_title_1?ie=UTF8&psc=1&smid=A1OB26G8TSLEZQ

Nevrmind on the above relay. I see now that it needs 5VDC instead of 3VDC to operate.

Rob, if you have the LoLin version NodeMCU with the base, you can get a 5V output from the base, so these should work. If you have the Amica version NodeMCU, it only has 3.3V output.

@heythisisnate thanks again for the quick replies. I am getting the LoLin base. I was reading the conversation above about using the 5V pin on this base and does seem like it will work as long as it has the 1000mA voltage regulator on it that ogiewon was talking about.

Rob,

I was referring to the voltage regulator on the NodeMCU ESP8266 board, not the base. If the NodeMCU ESP8266 board has the 1000mA 3.3v regulator, you should be able to safely use the relay that Nick has been using. Just don’t try hooking up more than a few of them.

If you’re using the LoLin Base, it will have a 5v regulator chip on it. This 5v can be used to drive a typical 5v relay board (like the one you linked earlier, assuming it’s INPUT can be triggered by 3.3v). The NodeMCU ESP8266 board’s digital output pin would then activate the opt-isolator chip on the relay board at 3.3v.

Hope this clears it up.

Yes that clears it up, mostly. Does the power supplied to the ESP8266 supply that 5V to the LoLin board or do I have to also supply a seperate power supply to the board. I guess my confusion comes from the fact that the LoLin board has a port to plug in it’s own power supply.

Correct, you supply power to the LoLin Base board from a wall-wart style power supply. Probably a 9VDC 1 to 2 Amp power supply. The LoLin Base Board’s 5V regulator takes the 9VDC, and converts it to 5VDC. This 5VDC is then supplied to the NodeMCU ESP8266 board via the “Vin Pin”. This “Vin” pin then supplies 5VDC to the NodeMCU ESP8266 boards 3.3V regulator. The 3.3V regulator then supplies 3.3V to the ESP8266 chip, as well as to the various 3.3VDC pins on the NodeMCU ESP8266 board, which in turn supply 3.3VDC to the LoLin Base Board’s 3.3VDC pins.

What I am not sure of is how safe it is to have the USB cable connected at the same time as external power to the LoLin Base. Both of these attempt to supply 5VDC to the NodeMCU board. Has anyone with powered LoLin base tried USB debugging at the same time?

Thanks for all of your electrical advice, @ogiewon! I’m learning a ton here. A few follow-up points:

  1. I’m going to do some testing tonight with my multimeter to find out (a) if the 3.3v output on the LoLin base have power independent of the NodeMCU board and (b) the current draw of the 3V relays that I’ve been using.

  2. @Rob_Lisska you’re going to want to power the base directly to the power-in (either the pins or the DC power plug, see diagram below), and the base will power the board with the correct voltage. The LoLin base is marked with 6V - 24V on the back, so I assume it accepts input voltage anywhere in that range. I am powering my with 12V directly from the alarm panel aux out and it works fine. You only need one power supply.

  1. No issues using the USB cable while the board is powered via the base. I’ve done this dozens of times already.

  2. @ogiewon I understand your concern now about powering the relays via the ESP. I don’t think it’s too much of an issue for this particular project, because all the GPIO pins are in input mode except for the one powering the siren relay. I suppose if you had more than a couple relays, it could be problematic. Anecdotally, my relay is working flawlessly since I set it up. Thank you for clarifying.

  3. I’m working on gathering and consolidating all this feedback in this thread and creating a Wiki with documentation with everything we’ve learned. Thank you all so much for sharing your feedback and results! I’m so impressed with how quickly this project has blown up in popularity.

  4. I’ve had so much fun with this project so far, and I’ve had so many other ideas of things I can do with these NodeMCU boards. I’ve already got one set up to control my irrigation sprinklers. I’m thinking about a thermostat project, too. Stay tuned!

2 Likes