{"id":8,"date":"2021-04-19T21:22:15","date_gmt":"2021-04-19T21:22:15","guid":{"rendered":"https:\/\/www.atombrake.info\/?p=8"},"modified":"2021-04-19T21:22:17","modified_gmt":"2021-04-19T21:22:17","slug":"making-a-wireless-doorbell-smarter","status":"publish","type":"post","link":"https:\/\/www.atombrake.info\/index.php\/2021\/04\/19\/making-a-wireless-doorbell-smarter\/","title":{"rendered":"Making a wireless doorbell smart(er)"},"content":{"rendered":"\n<p>We have a pretty standard doorbell with a wireless chime, but living in a three floor house means the chime cannot be heard in all rooms. These doorbells usually run on 433MHz, which means we can use some cheap hardware to intercept the signals.<\/p>\n\n\n\n<p>In this project I have used a <a rel=\"noreferrer noopener\" href=\"https:\/\/www.raspberrypi.org\/\" target=\"_blank\">Raspberry Pi<\/a> with a <a rel=\"noreferrer noopener\" href=\"https:\/\/www.amazon.co.uk\/gp\/product\/B00P2UOU72\/ref=ppx_yo_dt_b_asin_title_o07_s00?ie=UTF8&amp;psc=1\" target=\"_blank\">NESDR Mini 2 USB RTL-SDR<\/a> to capture the wireless signal from the doorbell and activate a sensor in <a rel=\"noreferrer noopener\" href=\"https:\/\/www.home-assistant.io\/\" target=\"_blank\">Home Assistant<\/a>. Home Assistant then sends a notification to my mobile and plays a doorbell sound through my Google Assistants.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Pi Setup<\/h2>\n\n\n\n<p>First we will setup the Pi. I won&#8217;t go through the full setup, as there are many guides out there, but here is a very quick overview of the setup:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>I am using the <a rel=\"noreferrer noopener\" href=\"https:\/\/dietpi.com\/\" target=\"_blank\">DietPi<\/a> operating system<\/li><li>Once the OS is installed, you need to install <a rel=\"noreferrer noopener\" href=\"https:\/\/github.com\/merbanan\/rtl_433\" target=\"_blank\">rtl_433<\/a>. This is the software we will use to capture the signal, and then send it to Home Assistant via MQTT.<\/li><li>Plug in the RTL-SDR USB and reboot the Pi. <\/li><li>Test the SDR is working by running: <code>sudo rtl_433<\/code>. Any signals received and decoded will appear on screen, I usually get a stream of signals from the tyre pressure monitors of passing cars and a local weather station:<\/li><\/ul>\n\n\n\n<figure class=\"wp-block-image size-large\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"525\" height=\"207\" src=\"https:\/\/i0.wp.com\/www.atombrake.info\/wp-content\/uploads\/2021\/04\/image.png?resize=525%2C207&#038;ssl=1\" alt=\"\" class=\"wp-image-9\" srcset=\"https:\/\/i0.wp.com\/www.atombrake.info\/wp-content\/uploads\/2021\/04\/image.png?resize=1024%2C404&amp;ssl=1 1024w, https:\/\/i0.wp.com\/www.atombrake.info\/wp-content\/uploads\/2021\/04\/image.png?resize=300%2C118&amp;ssl=1 300w, https:\/\/i0.wp.com\/www.atombrake.info\/wp-content\/uploads\/2021\/04\/image.png?resize=768%2C303&amp;ssl=1 768w, https:\/\/i0.wp.com\/www.atombrake.info\/wp-content\/uploads\/2021\/04\/image.png?resize=1536%2C607&amp;ssl=1 1536w, https:\/\/i0.wp.com\/www.atombrake.info\/wp-content\/uploads\/2021\/04\/image.png?resize=2048%2C809&amp;ssl=1 2048w\" sizes=\"auto, (max-width: 706px) 89vw, (max-width: 767px) 82vw, 740px\" \/><figcaption>Example of signals received, showing the SDR is working.<\/figcaption><\/figure>\n\n\n\n<ul class=\"wp-block-list\"><li>If you test the doorbell now, it is unlikely that it will be decoded, as each doorbell uses a unique signal. Mine changes each time the pairing mode is activated, or the chime sound changed.<\/li><li>Press ctrl-C to exit rtl_433<\/li><\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Capture the signal<\/h2>\n\n\n\n<p>To capture the signal we will use the pulse analyser mode to capture the signal, this will analyse the signal from the doorbell and give us the details needed.<\/p>\n\n\n\n<p>Run: <code>sudo rtl_433 -A<\/code> and then activate the doorbell.<\/p>\n\n\n\n<p>In my case, the output was as follows:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"525\" height=\"545\" src=\"https:\/\/i0.wp.com\/www.atombrake.info\/wp-content\/uploads\/2021\/04\/image-1.png?resize=525%2C545&#038;ssl=1\" alt=\"\" class=\"wp-image-10\" srcset=\"https:\/\/i0.wp.com\/www.atombrake.info\/wp-content\/uploads\/2021\/04\/image-1.png?resize=987%2C1024&amp;ssl=1 987w, https:\/\/i0.wp.com\/www.atombrake.info\/wp-content\/uploads\/2021\/04\/image-1.png?resize=289%2C300&amp;ssl=1 289w, https:\/\/i0.wp.com\/www.atombrake.info\/wp-content\/uploads\/2021\/04\/image-1.png?resize=768%2C796&amp;ssl=1 768w, https:\/\/i0.wp.com\/www.atombrake.info\/wp-content\/uploads\/2021\/04\/image-1.png?resize=1481%2C1536&amp;ssl=1 1481w, https:\/\/i0.wp.com\/www.atombrake.info\/wp-content\/uploads\/2021\/04\/image-1.png?w=1539&amp;ssl=1 1539w, https:\/\/i0.wp.com\/www.atombrake.info\/wp-content\/uploads\/2021\/04\/image-1.png?w=1050&amp;ssl=1 1050w\" sizes=\"auto, (max-width: 706px) 89vw, (max-width: 767px) 82vw, 740px\" \/><figcaption>Full output of doorbell signal<\/figcaption><\/figure>\n\n\n\n<p>The important line is:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"525\" height=\"19\" src=\"https:\/\/i0.wp.com\/www.atombrake.info\/wp-content\/uploads\/2021\/04\/image-2.png?resize=525%2C19&#038;ssl=1\" alt=\"\" class=\"wp-image-11\" srcset=\"https:\/\/i0.wp.com\/www.atombrake.info\/wp-content\/uploads\/2021\/04\/image-2.png?resize=1024%2C38&amp;ssl=1 1024w, https:\/\/i0.wp.com\/www.atombrake.info\/wp-content\/uploads\/2021\/04\/image-2.png?resize=300%2C11&amp;ssl=1 300w, https:\/\/i0.wp.com\/www.atombrake.info\/wp-content\/uploads\/2021\/04\/image-2.png?resize=768%2C28&amp;ssl=1 768w, https:\/\/i0.wp.com\/www.atombrake.info\/wp-content\/uploads\/2021\/04\/image-2.png?w=1472&amp;ssl=1 1472w\" sizes=\"auto, (max-width: 706px) 89vw, (max-width: 767px) 82vw, 740px\" \/><figcaption>Flex decoder specification<\/figcaption><\/figure>\n\n\n\n<p>Save this line for later.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Setting up Home Assistant &amp; MQTT<\/h2>\n\n\n\n<p>It might be possible to do this by plugging the SDR into the device running Home Assistant, to simplify this step but I am running Home Assistant as a virtual machine running under Hyper-V which does not have USB pass-through.<\/p>\n\n\n\n<p>I&#8217;m not going to go through the full steps for setting up Home Assistant, as they are documented very well elsewhere.<\/p>\n\n\n\n<p>Once you have the basics setup, you&#8217;ll need to install the Mosquitto broker add-on through the supervisor menu, this allows home assistant to listen to MQTT messages on the network. You&#8217;ll then need to add the MQTT integration. If you are using the built in mosquitto broker, then the configuration of this is very simple. Finally you&#8217;ll need to create an account for MQTT logins. This doesn&#8217;t need to be an administrator, just a standard user.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Putting it all together<\/h2>\n\n\n\n<p>I have configured a system service on my Pi so rtl_433 starts on boot, and restarts on failure. The service calls a single line script which is as follows:<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\"><p>rtl_433 -R 0 -X &#8216;n=doorbell,m=OOK_PWM,s=352,l=692,r=5296,g=696,t=136,y=0&#8217; -F &#8220;mqtt:\/\/&lt;Home Assistant IP>:1883,user=&lt;username>,pass=&lt;password>&#8221;<\/p><\/blockquote>\n\n\n\n<p>Breaking this down:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>-R 0 tells rtl_433 not to run any of the built in decoders<\/li><li>-X &#8216;n=doorbell,m=OOK_PWM,s=352,l=692,r=5296,g=696,t=136,y=0&#8217; is the decoder captured in step 2 above. The n= can be anything.<\/li><li>-F &#8220;mqtt:\/\/&lt;Home Assistant IP>:1883,user=&lt;username>,pass=&lt;password>&#8221; tells rtl_433 to output in MQTT format, and gives the details of where to send the message.<\/li><\/ul>\n\n\n\n<p>When running the command, you should see that it successfully makes an MQTT connection:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"525\" height=\"106\" src=\"https:\/\/i0.wp.com\/www.atombrake.info\/wp-content\/uploads\/2021\/04\/image-4.png?resize=525%2C106&#038;ssl=1\" alt=\"\" class=\"wp-image-13\" srcset=\"https:\/\/i0.wp.com\/www.atombrake.info\/wp-content\/uploads\/2021\/04\/image-4.png?resize=1024%2C207&amp;ssl=1 1024w, https:\/\/i0.wp.com\/www.atombrake.info\/wp-content\/uploads\/2021\/04\/image-4.png?resize=300%2C61&amp;ssl=1 300w, https:\/\/i0.wp.com\/www.atombrake.info\/wp-content\/uploads\/2021\/04\/image-4.png?resize=768%2C155&amp;ssl=1 768w, https:\/\/i0.wp.com\/www.atombrake.info\/wp-content\/uploads\/2021\/04\/image-4.png?resize=1536%2C310&amp;ssl=1 1536w, https:\/\/i0.wp.com\/www.atombrake.info\/wp-content\/uploads\/2021\/04\/image-4.png?resize=2048%2C414&amp;ssl=1 2048w\" sizes=\"auto, (max-width: 706px) 89vw, (max-width: 767px) 82vw, 740px\" \/><figcaption>MQTT connection established<\/figcaption><\/figure>\n\n\n\n<p>Once this is running, head back to Home Assistant, to into the MQTT integration and click &#8220;configure&#8221;. This will allow you to run an MQTT listener.<\/p>\n\n\n\n<p>Initially start listening to all messages using the wildcard character #<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"525\" height=\"229\" src=\"https:\/\/i0.wp.com\/www.atombrake.info\/wp-content\/uploads\/2021\/04\/image-3.png?resize=525%2C229&#038;ssl=1\" alt=\"\" class=\"wp-image-12\" srcset=\"https:\/\/i0.wp.com\/www.atombrake.info\/wp-content\/uploads\/2021\/04\/image-3.png?w=870&amp;ssl=1 870w, https:\/\/i0.wp.com\/www.atombrake.info\/wp-content\/uploads\/2021\/04\/image-3.png?resize=300%2C131&amp;ssl=1 300w, https:\/\/i0.wp.com\/www.atombrake.info\/wp-content\/uploads\/2021\/04\/image-3.png?resize=768%2C335&amp;ssl=1 768w\" sizes=\"auto, (max-width: 706px) 89vw, (max-width: 767px) 82vw, 740px\" \/><figcaption>MQTT listener running<\/figcaption><\/figure>\n\n\n\n<p>This will output all messages which should initially just be the connection details from the Pi into Home Assistant. Pressing the doorbell will generate additional traffic, including message codes. These message codes are unique and what we will monitor for in Home Assistant.<\/p>\n\n\n\n<p>We need to create a binary sensor in configuration.yaml:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>binary_sensor:\n## Doorbell\n    - platform: mqtt\n      state_topic: \"rtl_433\/raspberrypi\/devices\/doorbell\/codes\/#\"\n      payload_on: \"{13}98e8\"\n      off_delay: 5\n      name: Doorbell<\/code><\/pre>\n\n\n\n<p>The bit which will need changing is the &#8220;payload on&#8221; code &#8211; this should be taken from the listener above.<\/p>\n\n\n\n<p>Once the file has been updated, save and restart Home Assistant. This will create a binary sensor which changes to &#8220;on&#8221; for 5 seconds when the doorbell is pressed.<\/p>\n\n\n\n<p>The next step is to use the sensor to generate alerts. I have setup two forms of alerts:<\/p>\n\n\n\n<ol class=\"wp-block-list\"><li>An alert on my Android phone (through the Home Assistant app)<\/li><li>Google homes playing a doorbell sound.<\/li><\/ol>\n\n\n\n<p>My automation looks like the following:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>alias: Doorbell\ndescription: ''\ntrigger:\n  - platform: state\n    entity_id: binary_sensor.doorbell\n    to: 'on'\ncondition: &#91;]\naction:\n  - service: media_player.volume_set\n    target:\n      device_id:\n        - Google Home 1\n        - Google Home 2\n    data:\n      volume_level: 0.75\n  - service: media_player.play_media\n    data:\n      media_content_type: audio\/mp3\n      media_content_id: 'URL of MP3'\n    target:\n      entity_id:\n        - media_player.kitchen_speaker\n        - media_player.office_speaker\n  - service: notify.mobile_app_phone_name\n    data:\n      data:\n        tag: doorbell\n        ttl: 0\n        priority: high\n      message: Doorbell\n  - wait_template: ''\n    timeout: '00:00:10'\n    continue_on_timeout: true\n  - service: media_player.volume_set\n    data:\n      volume_level: 0.25\n    target:\n      device_id:\n        - Google Home 1\n        - Google Home 2\nmode: single\n<\/code><\/pre>\n\n\n\n<p>Breaking this down, the trigger is the state of the sensor changing from &#8216;off&#8217; to &#8216;on&#8217;<\/p>\n\n\n\n<p>The actions in order are:<\/p>\n\n\n\n<ol class=\"wp-block-list\"><li>Set the volume on my google home speakers to 75%<\/li><li>Play the MP3 stored at the URL provided<\/li><li>Pop up an android notification<\/li><li>Wait 10 seconds<\/li><li>Set google home speakers volume to 25%<\/li><\/ol>\n\n\n\n<h2 class=\"wp-block-heading\">Further Work \/ Improvements<\/h2>\n\n\n\n<p>There are a few areas where I think this setup could be improved:<\/p>\n\n\n\n<ol class=\"wp-block-list\"><li>rtl_433 is resource intensive on my Raspberry Pi, I have done some basic reading that there may be a better way to compile it in a more optimised way<\/li><li>The Google Home notification stops any music currently playing, and doesn&#8217;t restart it. I would prefer to play the notification and then resume whatever was playing in the background, at the previous volume.<\/li><\/ol>\n\n\n\n<p>Thanks for reading, I hope this has been useful! If you have any comments, suggestions for improvements to this setup please leave a comment below.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>We have a pretty standard doorbell with a wireless chime, but living in a three floor house means the chime cannot be heard in all rooms. These doorbells usually run on 433MHz, which means we can use some cheap hardware to intercept the signals. In this project I have used a Raspberry Pi with a &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/www.atombrake.info\/index.php\/2021\/04\/19\/making-a-wireless-doorbell-smarter\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Making a wireless doorbell smart(er)&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[1],"tags":[2,4,3],"class_list":["post-8","post","type-post","status-publish","format-standard","hentry","category-uncategorized","tag-home-assistant","tag-raspberry-pi","tag-sdr"],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/paousE-8","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.atombrake.info\/index.php\/wp-json\/wp\/v2\/posts\/8","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.atombrake.info\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.atombrake.info\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.atombrake.info\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.atombrake.info\/index.php\/wp-json\/wp\/v2\/comments?post=8"}],"version-history":[{"count":1,"href":"https:\/\/www.atombrake.info\/index.php\/wp-json\/wp\/v2\/posts\/8\/revisions"}],"predecessor-version":[{"id":14,"href":"https:\/\/www.atombrake.info\/index.php\/wp-json\/wp\/v2\/posts\/8\/revisions\/14"}],"wp:attachment":[{"href":"https:\/\/www.atombrake.info\/index.php\/wp-json\/wp\/v2\/media?parent=8"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.atombrake.info\/index.php\/wp-json\/wp\/v2\/categories?post=8"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.atombrake.info\/index.php\/wp-json\/wp\/v2\/tags?post=8"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}