I own Tuya Doorbell which recently got integrated into Home Assistant. However, it is still missing press event and is cloud only. I wanted to trigger an automation on when someone presses the doorbell, even if my internet (or cloud) is offline. I wasn’t able to find too many tutorials on how to do this, so below is my overview on how to achieve this.
After reading this, you will be able to:
- Detect when doorbell is pressed
- Ring the doorbell via Home Assistant
My doorbell communicates through 433mhz with in house unit. Meaning, this solution will also work for any doorbell communicating via 433mhz with an exception of rolling codes.
I am not going to cover every step in detail. Steps not covered in too much details have a lot of other more detailed guides available through google and youtube. I am going to cover parts which I needed to discover on my own.
Hardware needed: Sonoff 433 RF Bridge
1.) Flash Sonoff 433 RF Bridge with Tasmota, including the RF chip. This is not as hard as it first seems, no soldering or device modification is needed at all. You do not need to damage the lines for 3v3 and ground from usb when flashing the chip, just connect the 3v3 and GND lines just like when flashing tasmota.
2.) Make sure that your devices module is set up as Sonoff Bridge (25) and you have turned ON RF chip before closing up the device.
3.) Connect Tasmota to your MQTT server, note down your devices topic from MQTT settings, you will need this later. It should be in format of tasmota_* unless changed manually.
4.) Add tasmota integration for the device into Home Assistant
At this point you are pretty much set up HW wise, all you need now discover your doorbell RF code. For detecting the code, follow this part of the guide. Make sure to get a few codes of the same action (press doorbell multiple times) and select the most similar one. You can now use this code to make your doorbell ring by using this service:
service: mqtt.publish
data:
topic: cmnd/YOUR_TOPIC_YOU_NOTED_DOWN/rfraw
payload: B1_TO_B0_CONVERTED_CODE
Make sure to remove any spaces from B1_TO_B0_CONVERTED_CODE. In my case, doorbell always sent 3 individual codes spaced around 300ms apart. What I have done is converted all of those and simply chained them in a script like so:
ring_doorbell:
sequence:
- service: mqtt.publish
data:
topic: cmnd/MY_TOPIC/rfraw
payload: CONVERTED_CODE_1
- service: mqtt.publish
data:
payload: CONVERTED_CODE_2
topic: cmnd/MY_TOPIC/rfraw
- service: mqtt.publish
data:
payload: CONVERTED_CODE_3
topic: cmnd/MY_TOPIC/rfraw
mode: single
alias: Ring doorbell
You can now run the script and hopefully you will hear your doorbell ring! That is nice for training dogs not to bark, but how can we listen to doorbell press?
Your Tasmota integration exposes sensor sensor.tasmota_last_restart_time
. We will use this to turn on learning mode every time our device reboots, so that it always listens. We can do it with this simple automation:
id: '1640021011774'
alias: Turn on RF listener
description: ''
trigger:
- platform: template
value_template: '{{ as_timestamp(now()) - as_timestamp(states.sensor.tasmota_last_restart_time.state)
< 60 }}'
condition: []
action:
- service: mqtt.publish
data:
topic: cmnd/YOUR_TOPIC_YOU_NOTED_DOWN/rfraw
payload: '177'
mode: single
Now, go ahead and create a helper input_boolean entity. I called this Doorbell
. Add following automation below:
id: '1640017923836'
alias: Detect doorbell
description: ''
trigger:
- platform: mqtt
topic: tele/YOUR_TOPIC_YOU_NOTED_DOWN/RESULT
condition:
- condition: or
conditions:
- condition: template
value_template: '{{ ''CONVERTED_CODE'' in trigger.payload_json[''RfRaw''][''Data''] }}'
- condition: template
value_template: '{{ ''CONVERTED_CODE'' in trigger.payload_json[''RfRaw''][''Data''] }}'
action:
- service: input_boolean.turn_on
target:
entity_id: input_boolean.doorbell
- delay:
hours: 0
minutes: 0
seconds: 1
milliseconds: 0
- service: input_boolean.turn_off
target:
entity_id: input_boolean.doorbell
mode: single
This will turn on the helper input boolean on for one second, and turn it back off as soon as it detects RF code matching the conditions. In my case, only a part of the RF code was always the same, so I used that. Some doorbells or devices might be using multiple rolling codes (like 4 repeating), in that case just add more conditions into or section. As my second code, I added a random remote I had laying around for testing the automation so I do not have to go out every time.
Now you are almost finished, all you need now is an automation that does stuff on the helper input_boolean change. Below is mine.
- id: '1640018496945'
alias: Someone rang the doorbell
description: ''
trigger:
- platform: state
entity_id: input_boolean.doorbell
to: 'on'
condition: []
action:
- service: script.turn_on
target:
entity_id:
- script.someone_is_at_the_door_lights_bedroom
- script.someone_is_at_the_door_lights_office
- script.someone_is_at_the_door_lights_living_room_lamp
- script.someone_is_at_the_door_lights_kitchen_leds
- script.send_doorbell_photo
- service: tts.google_say
data:
entity_id: media_player.the_home
message: Someone is at the door!
mode: single
In my case:
- It sends FB message with photos from doorbell camera and 2 other cameras stating someone rang doorbell
- Sends notification to my Android TVs using notify android TV integration
- Blinks lights in every room, returning them to previous state
- Announces that someone rang a doorbell via my Google Homes.
Good luck!