$5 DIY Wireless MQTT Smart Home Window Sensors

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
today on the hookup we're gonna learn how to make some super small super cheap battery powered wireless MQTT window sensors back in the 1990s and early 2000s every new house got a wired security system installed in it basically for free the idea was that the security companies would easily make their money back with monthly monitoring fees so they could take a little bit of upfront costs for putting the wires in the wall fast forward to 2018 and most monitoring companies are utilizing wireless sensors instead of installing wired systems and the days of free installation are long gone my house was built in 2012 and adding a security system was going to add upwards of $1,500 to the cost of the build at the time we didn't have a whole lot of money to spare so we passed I'd love to go back in time and tell my past self to install as much wiring in the walls as possible but c'est la vie I've now got various wired microcontrollers around my house monitoring the outside doors but I was struggling with a solution for the windows I don't use a home automation hub for ZigBee or z-wave protocol although I probably should and I didn't really want to open up the bag of words that's the Xiaomi system this left me with very few options but to build my own solution so I did the total cost of each sensor is just over $5 if you buy the parts from Amazon but you could build them under three if you bought all your stuff from Aliexpress I was way too impatient to wait for that shipping so I bought them off Amazon for this project you'll need some of these bare Reed switches some ESP o1 microcontrollers 2032 batteries and some high value resistors I use 10k you'll also need a soldering iron a USB to TTL adapter and access to a 3d printer there's Amazon links to all these items down in the description let's look at the design this read switch here is a normally closed switch meaning it only breaks the circuit when it's close to a magnet this read switch connects directly to the ground pin on the ESP o1 and the negative terminal of the cr2032 battery the PAS terminal of the cr2032 is connected to the 3.3 volt pin of the ESP and that pin is jumped with a 10k resistor to the enable pin on the ESP o1 which pulls it high which is required for normal operation all this stuff sits nicely in a small 3d printed enclosure by the way I also 3d printed the magnet enclosures I'm using those small buckyball magnets to trigger my switch but almost any kind of magnet will do for this here's how you make it first load up my Arduino sketch from down in the description put in your Wi-Fi information and your MQTT information remember to set a unique identifier for the MQTT client and the MQTT topic for each window don't forget what you call your topics make sure you write them down next you'll flash the program to your ESP o1 using a USB to TTL adapter hook up the pins according to this diagram the wiring looks complicated but it's actually not too bad TX is the transmission pin and Rx is the receive pin essentially the transmission pin from the adapter goes to the receive pin on the ESP and vice versa the 3.3 power from the adapter is hooked to the 3.3 input on the ESP and also the chip enable pin on the ESP the ground is hooked up to the ground pin on the ESB and then also you to GPIO zero because when you ground GPIO zero that puts the esp8266 into flash mode so it's ready for a new program after you've got your program loaded you can use your MQTT client of choice to make sure it works just power up the chip and you should see an open message pop up in about 4 seconds to the topic that you chose and then you after you unplug it a closed message should pop up a few seconds later once we're sure it's working we can start fitting it into this enclosure you can desolder the pins on the ESP o one by pushing them through the top using a hot soldering iron once they're pushed through you can pull them out individually with a pair of nippers to set up the read switch you'll need to cut off the normally open leg and bend the normally closed leg so that it sits underneath the battery bend the other leads so that you can connect it to the ground pin on the ESP O one to figure out what Payne is normally open and which is normally closed just connect the two sides to a multimeter and check for continuity you want to keep the two pins that are connected when there's no magnet nearby next place a high value resistor between the VN pin and the enable pin this just pulls that pin high so that the chip operates normally solder a thin wire onto the VN pin and place it so that it makes contact with the positive side of the battery I put a dab of solder on the end of my wire and gave it a slightly larger point of contact but that's probably unnecessary one optional step is to break off the power indicator LED with pair of nippers to reduce the current draw even further I don't actually think this makes a large difference for our project since we're actually cutting the power to the chip when the window is closed instead of utilizing something like deep sleep as the final step you can put the battery in to test it although I do recommend that you keep the battery out until it's time to install them in the windows basically the way these work is when a bad guy opens up the window they move the reed switch away from the magnet which closes the switch and provides power to the ESP oh one turning it on the ESP boots up connects to your Wi-Fi and sends an open message to your window status topic before putting itself into a deep sleep I've set the last will and testament in this program to publish a closed MQTT message with a retain flag after the ESP eo1 powers off this will happen about five seconds after that original open message this essentially just gives your window a default state as closed in-home assistant let's talk about the disadvantages of this solution number one the time from power on until the sensor message hits home assistant is just under four seconds which is a little bit slow but given their placement it would take a really skilled thief to be able to disable the chip before the message actually got sent number two the cr2032 starts out with about three point two volts fresh out of the package the ESP o1 requires at least three volts to boot and establish a Wi-Fi connection this translates to around 20 open messages before the battery is drained beyond the point that the Wi-Fi radio can operate for me this is no big deal because in the six years we've been in this house we've opened each of the windows significantly less than 20 times if you open and close windows a lot or leave your windows open then these sensors probably aren't going to work out for you number three out of the ten ESP Oh ones that I bought from Amazon one of them was unusually power-hungry and refused to boot up at all off the battery it worked no problem when I plugged it into a 3.3 volt power supply but even after removing the onboard led it was still too current hungry to connect to Wi-Fi that was probably just a manufacturing defect and nothing to worry about okay so I just told you why you shouldn't build these things let's talk about why you should number one they're dirt cheap at three to five dollars per sensor we're talking about outfitting your whole house for the cost of a single ZigBee or z-wave window sensor number two you made them and they're working on your home network only they don't need to phone home to China they're not going to introduce some subscription fees sometime in the future and they're really easy to fix and replace if needed number three their Wi-Fi so no hub is required my only problem with Wi-Fi is Wi-Fi congestion caused by the thirty some devices on my home network but these devices are going to be powered off 99.9 percent of the time so they're not going to contribute to any of the congestion in my house number four the battery is disconnected when the window is closed no deep sleep no microcurrent draw it's an open circuit this means that your 2032 batteries should last years and years as long as the window isn't opened I made my first one of these around two months ago so I don't have super long term data on it but the engineer in me says that the battery should last just as long in a closed window sensor as it should in an unopened package there's links to everything needed for this project down in the description below if you enjoyed this video please consider subscribing also big thanks to Ben and bro automation for getting me to finally pull the trigger and jump into home assistant and thanks to dr. Zee's for motivating me to make these videos thanks for watching the hook-up [Music]
Info
Channel: The Hook Up
Views: 140,659
Rating: undefined out of 5
Keywords: home assistant, smart home, diy, mqtt, arduino, esp8266, security, window sensors, wireless, wifi
Id: BoYVr2UwWWg
Channel Id: undefined
Length: 8min 41sec (521 seconds)
Published: Wed Apr 04 2018
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.