{"id":358,"date":"2018-06-13T12:56:34","date_gmt":"2018-06-13T16:56:34","guid":{"rendered":"http:\/\/www.thesmarthomehookup.com\/test_install\/?p=358"},"modified":"2023-02-08T17:14:29","modified_gmt":"2023-02-08T22:14:29","slug":"diy-wireless-smart-doorbell-program-esp8266-nodemcu-with-arduino-or-esphomeyaml","status":"publish","type":"post","link":"http:\/\/www.thesmarthomehookup.com\/test_install\/diy-wireless-smart-doorbell-program-esp8266-nodemcu-with-arduino-or-esphomeyaml\/","title":{"rendered":"DIY Wireless Smart Doorbell: Program ESP8266 NodeMCU with Arduino or ESPHomeYAML"},"content":{"rendered":"<p><iframe width=\"560\" height=\"315\" src=\"https:\/\/www.youtube.com\/embed\/xCQoOZNdaGY\" frameborder=\"0\" allow=\"autoplay; encrypted-media\" allowfullscreen=\"\"><\/iframe><\/p>\n<p><strong>MQTT Doorbell and Door Sensor<\/strong><\/p>\n<p>Today on the hookup we\u2019re going to modify a cheap wireless doorbell from amazon to make an MQTT connected doorbell that interfaces with home assistant to send notifications and images.<\/p>\n<p>The ring doorbell is pretty cool, but a few things about my smart home setup made me decide against buying it.&nbsp; First, I do not have a wired doorbell on my house, so I would have had to use the battery operated version, which I\u2019ve not heard great things about.&nbsp; Second, I already have a camera pointed at my front door, so adding another camera on the doorbell seemed like overkill.&nbsp; And third, I\u2019ve tried to craft my smart home to function primarily on my local network and avoid cloud services whenever possible so internet outages don\u2019t render the system useless and this allows me to keep with that theme.<\/p>\n<p>I figured there was no reason to reinvent the wheel here, so I headed over to amazon to get a super cheap wireless doorbell.&nbsp; 11 dollars and two days later I had this doorbell by the company 1 by 1,&nbsp; now I actually built this project over a year ago, so I asked 1 by 1 to send me a free one to take apart for this video, but they never responded up so I went ahead and just bought another one, you guys are worth it right?<\/p>\n<p>We\u2019re going to combine this thing with an ESP8266 nodeMCU board to give it wifi capabilities.&nbsp; I specifically selected the battery version of this doorbell because I knew it ran off 2 double AA batteries, or the equivalent of 3 volts, which happens to be a voltage my NodeMCU can supply.&nbsp; They make a version of this with an AC wall plug that includes the transformer from 120V AC to 3v DC, but I didn\u2019t want to mess with mains voltage for this project, so I just went with the battery powered one.<\/p>\n<p>Out of the box the doorbell has 3 modes: LED only, LED plus sound, and sound only.&nbsp; Our modified version is going to use the LED output to determine whether the doorbell has been pressed to send notifications.&nbsp; We\u2019re also going to add an MQTT switch to silence the doorbell chime, and optionally a reed switch to detect the state of the front door.&nbsp; This plastic container will make a great housing for our project, but if you want to use a different enclosure it\u2019s a good idea to label the buttons on the board so you don\u2019t forget what they do\u2026 don\u2019t ask me how I know that.<\/p>\n<p>Lets get this thing wired up.&nbsp; Here\u2019s the schematic for this creation.&nbsp; We\u2019re going to hook up the LED output to pin D0 because this pin on the ESP8266 has a built in pull-down resistor, which means we don\u2019t need to add one ourselves.&nbsp; We\u2019ll connect D4 to the base of our transistor to control whether the chime is active, and we\u2019ll also hook up our reed switch to both D3 and Ground.&nbsp; We can power the whole thing using a USB micro cable plugged into a 5V wall brick.&nbsp; The small doorbell PCB is powered the 3v3 pin and the ground pin on the NodeMCU.<\/p>\n<p>The actual code is pretty simple.&nbsp; We use a NodeMCU as an MQTT client and monitor one of the GPIO pins for a high signal that corresponds to the LED.&nbsp; If that pin goes to HIGH we\u2019ll send an MQTT message to Doorbell with the message Ding.&nbsp; You can obviously change this to any message you want to fit in with your MQTT schema. Since the LED flashes on and off twice and we only want to be alerted one time by each doorbell ring there\u2019s a little bit of code here that limits the number of messages sent to 1 every 6 seconds.<\/p>\n<p>The other functionality of this code is to silence the doorbell.&nbsp; If you send the message \u201csilent doorbell\u201d to the topic \u201cdoorbell\/commands\u201d it will turn off the speaker on the device and will only trigger the notification.&nbsp; If you send \u201caudio doorbell\u201d to the same topic it will activate that switch and the doorbell will play through the speaker and notify you.<\/p>\n<p>The last functionality I\u2019ve included is a reed switch that can monitor your front door.&nbsp; This is a wired reed switch, so you\u2019ll need to put the doorbell unit somewhere close to the door where you can also run a wire to the door. If you do choose to use it it will send the MQTT message Open to the topic doors\/front if the door opens and Closed to door\/front when it closes.&nbsp; Each of these messages uses a retain flag so if your home assistant instance restarts it the status of the door will be resent once home assistant subscribes to the door\/Front MQTT feed.&nbsp;&nbsp; The rest of the doorbell will still work perfectly fine even if you don\u2019t wire up this reed switch, so if you don\u2019t want to&nbsp; use it you can skip it.<\/p>\n<p>To add this into home assistant we\u2019re going to add a few things to our configuration.yaml file.&nbsp; We\u2019re going to make an MQTT sensor for the doorbell with an expire after value of 10 seconds, and an MQTT switch to silence the doobell with the commands and state topics specified in the code, last we\u2019ve got that optional MQTT binary sensor for the front door, you\u2019ll only need to put this entry in if you wired up the reed switch.<\/p>\n<p>&nbsp;<\/p>\n<p>Now that home assistant knows when the doorbell rings, lets make a fancy automation to include an image from an existing home assistant camera in the message.&nbsp; We\u2019re going to use the binary sensor \u201cdoorbell\u201d as a trigger, we\u2019re going to call my ios notification as an action, and we\u2019re going to utilize this super secret URL that contains a JPEG snapshot to get an image into that notification.&nbsp; I\u2019ll include a copy of this YAML in the description.&nbsp; If you want to see how to do this and more in NodeRED make sure to check out my mastering node-red series.&nbsp; All that\u2019s left to do now is test it out.<\/p>\n<p>First we\u2019ll flip the chime switch on, then ring the doorbell.<\/p>\n<p>Next lets turn the chime off and ring the doorbell again.<\/p>\n<p>Lets do a couple opens and closes of the front door to test out our reed switch.<\/p>\n<p>Perfect.<\/p>\n<p>I wrote this Arduino code for you, and I really think writing Arduino is a great skill to have if you\u2019re into tinkering with electronics so I REALLY want to encourage you to try and step through my code and figure out what\u2019s going on.&nbsp; However, if you aren\u2019t interested in learning to code in Arduino I\u2019m also going to show you how to set this up in hassio without having to mess with the Arduino IDE at all.<\/p>\n<p>Start by heading into your hassio page and we\u2019re going to add otto winter\u2019s repository.&nbsp;&nbsp; He has created a tool called esphomeyaml which will program our esp8266 and esp32 devices for us.&nbsp; After installing the addon go ahead and click on start, and then open web ui.&nbsp; If you use a dynamic DNS service you\u2019ll need to either forward this port on your router (which I wouldn\u2019t recommend), or go to the actual ip of your hassio device.&nbsp; If you\u2019ve used node-red you\u2019ve had to deal with this before, same thing, different port.<\/p>\n<p>We\u2019re going to set up a new device and call it doorbell, note here that you need to use only lowercase letters or it will throw an error.&nbsp; In the next step you need to specify the board you\u2019re going to use, we are using a nodemcuv2, but the rest of the board definitions can be found by clicking on the links in this text box.&nbsp; In the third step enter your wireless SSID and password.&nbsp; Fourth you\u2019ll put in your MQTT broker address login and password, for me my mqtt ip is the same as my hassio ip since I run mosquito as a hassio addon.&nbsp; After clicking done you\u2019ll now have a new file generated in your hassio config esphomeyaml folder.&nbsp; Open that file up in your favorite text editor, I\u2019m going to use notepad++.&nbsp; When you open this file up it should look familiar, we\u2019re going to program our ESP8266 in the same way we write yaml for our configuration file, which if you\u2019re like me means you\u2019re mostly going to copy and paste stuff.<\/p>\n<p>We\u2019re going to set up the same features as before.&nbsp; A binary sensor for our doorbell, on D0 with an input pulldown, a binary sensor for the front door on pin D3 with an input pullup, and a switch on pin D4.&nbsp; After we\u2019ve added this stuff we can hit save and head back over to our hassio addon, plug in our nodemcu to our pi using a USB micro cable and restart the addon.&nbsp; This step is necessary to allow the board to be recognized over USB.&nbsp; Once the addon restarts open up your web ui and click validate, and if all is well click upload.&nbsp; Go grab a drink, because this step takes a while.<\/p>\n<p>While this thing is uploading we can add a few lines to our configuration.yaml file to enable MQTT discovery.&nbsp; By doing this our switches and sensors that we just configured on our nodeMCU will add themselves automatically after a restart of home assistant.&nbsp; Add discovery true, and discovery prefix home assistant under mqtt and you\u2019re all set.<\/p>\n<p>By now our nodemcu should be all programmed, go ahead and head back over to the esphomeyaml addon and check to make sure your sensors are working.&nbsp; If you connect a wire to D0 and 3V3 it should trigger \u201con\u201d and if you connect a wire between D3 and ground it should trigger \u201con\u201d.&nbsp; If all is good you can go ahead and restart home assistant and your sensors will be there.<\/p>\n<p>In the Arduino code we were able to limit the amount of times the doorbell triggers, since esphomeyaml is more of a generic system we\u2019re not going to be able to do that, but we can figure fix that issue in node red after the fact.&nbsp; Again, if you want to get into DIY electronics stuff I highly recommend you learn Arduino, but esphomeyaml is a pretty neat tool if you just want to make a few sensors the quick and easy way.<\/p>\n<p>Hopefully you were able to pick up a few useful things from this video.&nbsp; The description has all of the parts you need to make this project as well and the Arduino code and the esphomeyaml code.&nbsp; If you\u2019re wondering where the backup video I mentioned a few weeks ago is, things got a little weird and I\u2019m trying to figure some stuff out before I post the video.&nbsp;&nbsp; If you enjoyed this video, please consider subscribing, and as always, thanks for watching the hookup.<\/p>\n<p>I know everyone has a different home setup, so this project may not be directly applicable to yours, but I hope this gave you some ideas of how you can use a NodeMCU to repurpose dumb devices and connect them to your home assistant instance.&nbsp; Amazon links to all the items I used are in the description.&nbsp; If you enjoyed this video please consider subscribing, and as always, thanks for watching the hookup.<\/p>\n<h3>Links:<\/h3>\n<p>Project parts list from amazon:<br \/>\nWireless Doorbell: <a href=\"https:\/\/amzn.to\/2JO7CEB\">https:\/\/amzn.to\/2JO7CEB<\/a><br \/>\nNodeMCU: <a href=\"https:\/\/amzn.to\/2HmqcyH\">https:\/\/amzn.to\/2HmqcyH<\/a><br \/>\n2n2222 NPN Transistors: <a href=\"https:\/\/amzn.to\/2sSRVmb\">https:\/\/amzn.to\/2sSRVmb<\/a><br \/>\nReed Switches: <a href=\"https:\/\/amzn.to\/2y6QTbd\">https:\/\/amzn.to\/2y6QTbd<\/a><\/p>\n<p>Essentials:<br \/>\nHook Up Wire: <a href=\"https:\/\/amzn.to\/2JsDtuF\">https:\/\/amzn.to\/2JsDtuF<\/a><br \/>\nSecurity Sensor Wire: <a href=\"https:\/\/amzn.to\/2l5HxD6\">https:\/\/amzn.to\/2l5HxD6<\/a><br \/>\nSoldering Iron: <a href=\"https:\/\/amzn.to\/2JuTQa6\">https:\/\/amzn.to\/2JuTQa6<\/a><br \/>\nWire Cutters: <a href=\"https:\/\/amzn.to\/2Ls4Imr\">https:\/\/amzn.to\/2Ls4Imr<\/a><\/p>\n<p>Arduino code: <a href=\"https:\/\/github.com\/thehookup\/Wireless_MQTT_Doorbell\/blob\/master\/Doorbell_CONFIGURE.ino\">https:\/\/github.com\/thehookup\/Wireless_MQTT_Doorbell\/blob\/master\/Doorbell_CONFIGURE.ino<\/a><br \/>\nArduino based configuration yaml: <a href=\"https:\/\/github.com\/thehookup\/Wireless_MQTT_Doorbell\/blob\/master\/configuration_additions.yaml\">https:\/\/github.com\/thehookup\/Wireless_MQTT_Doorbell\/blob\/master\/configuration_additions.yaml<\/a><br \/>\nArduino based Node-RED flow: <a href=\"https:\/\/github.com\/thehookup\/Wireless_MQTT_Doorbell\/blob\/master\/arduino_nodered_flow.txt\">https:\/\/github.com\/thehookup\/Wireless_MQTT_Doorbell\/blob\/master\/arduino_nodered_flow.txt<\/a><\/p>\n<p>Otto Winter&#8217;s Repository: <a href=\"https:\/\/github.com\/OttoWinter\/esphomeyaml\">https:\/\/github.com\/OttoWinter\/esphomeyaml<\/a><br \/>\nESPHomeYAML Documentation: <a href=\"https:\/\/esphomelib.com\/esphomeyaml\/\">https:\/\/esphomelib.com\/esphomeyaml\/<\/a><\/p>\n<p>ESPHomeYAML Code: <a href=\"https:\/\/github.com\/thehookup\/Wireless_MQTT_Doorbell\/blob\/master\/doorbell_CONFIGURE.yaml\">https:\/\/github.com\/thehookup\/Wireless_MQTT_Doorbell\/blob\/master\/doorbell_CONFIGURE.yaml<\/a><br \/>\nMQTT Autodiscovery YAML: <a href=\"https:\/\/github.com\/thehookup\/Wireless_MQTT_Doorbell\/blob\/master\/MQTT_discovery.yaml\">https:\/\/github.com\/thehookup\/Wireless_MQTT_Doorbell\/blob\/master\/MQTT_discovery.yaml<\/a><br \/>\nESPHomeYAML Node-RED Flow:<a href=\"https:\/\/github.com\/thehookup\/Wireless_MQTT_Doorbell\/blob\/master\/esphomeyaml_nodered_flow.txt\">https:\/\/github.com\/thehookup\/Wireless_MQTT_Doorbell\/blob\/master\/esphomeyaml_nodered_flow.txt<\/a><\/p>\n<p>Wiring Schematic Doorbell PCB: <a href=\"https:\/\/github.com\/thehookup\/Wireless_MQTT_Doorbell\/blob\/master\/doorbell_pcb_schematic.jpg\">https:\/\/github.com\/thehookup\/Wireless_MQTT_Doorbell\/blob\/master\/doorbell_pcb_schematic.jpg<\/a><br \/>\nWiring Schematic NodeMCU: <a href=\"https:\/\/github.com\/thehookup\/Wireless_MQTT_Doorbell\/blob\/master\/NodeMCU%20schematic.jpg\">https:\/\/github.com\/thehookup\/Wireless_MQTT_Doorbell\/blob\/master\/NodeMCU%20schematic.jpg<\/a><\/p>\n<p>Music by www.BenSound.com<\/p>\n","protected":false},"excerpt":{"rendered":"<p>MQTT Doorbell and Door Sensor Today on the hookup we\u2019re going to modify a cheap wireless doorbell from amazon to make an MQTT connected doorbell that interfaces with home assistant to send notifications and images. The ring doorbell is pretty cool, but a few things about my smart home setup made me decide against buying [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":2608,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[5],"tags":[],"class_list":["post-358","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-tutorials"],"acf":[],"mb":[],"mfb_rest_fields":["title","gutenberg_elementor_mode"],"_links":{"self":[{"href":"http:\/\/www.thesmarthomehookup.com\/test_install\/wp-json\/wp\/v2\/posts\/358","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.thesmarthomehookup.com\/test_install\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.thesmarthomehookup.com\/test_install\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.thesmarthomehookup.com\/test_install\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"http:\/\/www.thesmarthomehookup.com\/test_install\/wp-json\/wp\/v2\/comments?post=358"}],"version-history":[{"count":4,"href":"http:\/\/www.thesmarthomehookup.com\/test_install\/wp-json\/wp\/v2\/posts\/358\/revisions"}],"predecessor-version":[{"id":2363,"href":"http:\/\/www.thesmarthomehookup.com\/test_install\/wp-json\/wp\/v2\/posts\/358\/revisions\/2363"}],"wp:featuredmedia":[{"embeddable":true,"href":"http:\/\/www.thesmarthomehookup.com\/test_install\/wp-json\/wp\/v2\/media\/2608"}],"wp:attachment":[{"href":"http:\/\/www.thesmarthomehookup.com\/test_install\/wp-json\/wp\/v2\/media?parent=358"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.thesmarthomehookup.com\/test_install\/wp-json\/wp\/v2\/categories?post=358"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.thesmarthomehookup.com\/test_install\/wp-json\/wp\/v2\/tags?post=358"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}