I wanted to connect my ordinary, wired, current doorbell to HA. And since my HA is running on a Raspberry Pi, I wanted to connect my doorbell button and doorbell chime to the GPIO interface of the RPi.
Of course 100+ others have connected a doorbell in 100+ ways, but my goals were to reuse the current components I had (Raspberry Pi, doorbell button, doorbell chime) and find a solution without soldering and as cheap as possible.
Then this would be the HA way to activate the chime when somebody is pushing the doorbell button:
- alias: 'Doorbell: Chime'
trigger:
- platform: state
entity_id: binary_sensor.doorbell_button
to: 'on'
action:
- service: switch.turn_on
entity_id: switch.doorbell_chime
- service: switch.turn_off
entity_id: switch.doorbell_chime
The possibilities would be endless:
- don’t chime in the night
- multiple pushes on the button resulting in chiming only once
- activate other things when somebody pushes the button
- use the chime in other automations
- etc.
Well, it worked. Let’s describe what I did.
Please note that my knowledge of electronic circuits is very limited. Most of the solution was found by combining various things on the internet. I could easily have blown up my RPi and you can do also. Check everything and be careful with your setup, because doorbell transformers can harm or hurt you, even with low voltages.
The old situation
This was the old setup: a doorbell button connected to a doorbell chime that was powered by a transformer.
I wanted to cut the wires somewhere between the button and the chime and connect all the wires somehow to some of the 40 pins of the GPIO interface of the Raspberry Pi. There is a component to set up sensors and switches in HA that use the GPIO:
Setting up the hardware and the wiring
There has to be an extra hardware component between the chime and the RPi, because the voltage of the chime is too high for the RPi to handle. I my case the doorbell transformer gives 8V. The RPi can handle max 5V directly. I bought an SPDT Relay.
This 2-Channel SPDT Relay has two single pole - double throw (SPDT) switches. It only requires low-voltage and low current signals to control those switches. Specifically, you can use 5V DC to control max.250V AC or 110V DC. Just what I needed, if you neglect the fact that I will use only one of the two switches. And for less than 10 euros including a nice transparant case and some wires.
This is my wiring schedule. Mind you, it’s on Bert&Ernie level. Blue is 8V, green is 5V, orange is 3.3V. You can see that the 8V is never reaching the RPi. You have to cut the current wiring between the button and the chime and reconnect both sides of the cut to the GPIO directly resp. to the SPDT Relay.
The green wires belong to the switch
in HA that controls the chime. The orange wires belong to the binary_sensor
in HA that senses the doorbell button. More details about the GPIO pin layout can be found here.
Here’s a picture of the relay that’s connected to the RPi. Of course there’s a piece of duct tape. Every DIY project has to have some.
How it should work
What happens if somebody pushes the doorbell button?
- When you press the button, the current starts to flow from pin 1 to pin 37 and the RPi will sense it.
- The
automation
in HA will trigger on thebinary_sensor
connected to GPIO 26 (pin 37) and will activate theswitch
connected to GPIO 4 (pin 7). - Current will start flowing and SIG1 of the SPDT Relay will sense it and switch the high voltage side of this component. Current will flow in the circuit that’s now created in the blue wires and the chime will ‘ding’.
- After a short time the
automation
will turn off theswitch
again. Current will stop flowing in the green wires, the relay will switch off the circuit in the blue wires and the chime will ‘dong’. *)
*) You can read ‘starts to ring’ for ‘ding’ and ‘stops to ring’ for ‘dong’ if you don’t have a ding-dong chime but a ringing chime.
Configuring HA
Now for the software side. You have to configure a couple of things. First the binary_sensor
for the doorbell button and the switch
for the doorbell chime.
binary_sensor:
- platform: rpi_gpio
pull_mode: 'DOWN'
ports:
26: Doorbell button
switch:
- platform: rpi_gpio
ports:
4: Doorbell chime
I’ve split the automation (form the top of the topic) in an automation and a script. In that way you can also use the activation of the chime better in other automations or UI buttons.
I added a condition
to restrict the chime to once each 10 seconds no matter how often the button is pushed.
automation:
- alias: 'Doorbell: Chime'
trigger:
- platform: state
entity_id: binary_sensor.doorbell_button
condition:
# At least 10 seconds between chimes.
- condition: template
value_template: >-
{%- if state_attr("script.chime_doorbell", "last_triggered") -%}
{{ as_timestamp(now()) - as_timestamp(state_attr("script.chime_doorbell", "last_triggered")) > 10 }}
{%- else -%}
true
{%- endif -%}
action:
- service: script.turn_on
entity_id: script.chime_doorbell
In the script I tried to use a delay
of 500 msecs, but that didn’t work. The delay became too large sometimes. The current script looks rather strange, but it helps to keep a consistent delay.
script:
chime_doorbell:
alias: 'Chime doorbell'
sequence:
- service: switch.turn_on
entity_id: switch.doorbell_chime
- service: input_boolean.turn_on
entity_id: input_boolean.dummy_delay
- service: input_boolean.turn_off
entity_id: input_boolean.dummy_delay
- service: input_boolean.turn_on
entity_id: input_boolean.dummy_delay
- service: input_boolean.turn_off
entity_id: input_boolean.dummy_delay
- service: input_boolean.turn_on
entity_id: input_boolean.dummy_delay
- service: input_boolean.turn_off
entity_id: input_boolean.dummy_delay
- service: input_boolean.turn_on
entity_id: input_boolean.dummy_delay
- service: input_boolean.turn_off
entity_id: input_boolean.dummy_delay
- service: input_boolean.turn_on
entity_id: input_boolean.dummy_delay
- service: input_boolean.turn_off
entity_id: input_boolean.dummy_delay
- service: switch.turn_off
entity_id: switch.doorbell_chime
input_boolean:
dummy_delay:
name: Dummy delay
initial: false
Have fun! Please help me to answer questions of users that need a more in-depth knowledge of electrical circuits.