For a while I was playing with the idea to be able to mute the doorbell, and receive a notification on my phone when somebody is at the door. I have this old fashioned doorbell that’s ringing very loud:
So I ordered some extra Wemos D1 mini ESP’s and a relay shield and started coding. Since I’ve discovered ESPHome, I intended to use this as number 1 choice before coding manually 🙂
For the test setup I used a breadboard to figure out which pins to use and how the code response to it.
I’m using esphome for communication between the doorbell and homeassistant. In my design I wanted the doorbell to be able to work without interaction with homeassistant. Therefore I used the homeassistant sensor to be able to mute the doorbell. As long as this boolean is not true, the doorbell will ring. So no message to homeassistant and a message back to the doorbell, no extra delay 😉
esphome: name: deurbel platform: ESP8266 board: d1_mini wifi: ssid: "<SSID>" password: "<PASSWORD>" # Enable logging logger: # Enable Home Assistant API api: ota: switch: - platform: gpio name: "Deurbel Relay" id: relay internal: true icon: mdi:alarm-bell pin: number: D1 inverted: false binary_sensor: - platform: gpio pin: D2 name: "Deurbel" #device_class: window filters: # - delayed_on: 50ms # THIS DOES THE DEBOUNCE - delayed_off: 5000ms # THIS PREVENTS FROM MULTIPLE RANGS on_press: then: - if: condition: binary_sensor.is_off: mute # IF MUTE DONT RING then: - switch.turn_on: relay - delay: 250ms - switch.turn_off: relay - platform: homeassistant name: "Input Boolean From Home Assistant" entity_id: input_boolean.mute_doorbell id: mute - platform: status name: "Status deurbel"
It works! Next step: assembling the Wemos and the Relay shield. The relay on the shield is connected to the D1, so that remains the same in my code. For the trigger I used the 3.3v on the D2. D2 is shorted to the ground via a resistor, and is high when pressed on the doorbell. This resister is needed to make sure that the input is only high when doorbell is pressed and is low on release.
The schematic (on multiple requests 😉)
On many request, I’ll explain the working a little more. The relay replaces the button by the door. That part is shown on the right of the schematic. Of course we need a trigger and that’ll be the button by the door. That part is on the left of the schematic.
The relay has a N.O. and a N.C. That stands for Normal Open and Normal Closed. Normal open means that that pin/connector is open in the normal state of the relay (not powered). Normal closed means that that pin/connector is closed in the normal state. Therefore we need to use the normal open (N.O.) pin, so that the circuit is only closed when the relay gets power.
Using the N.C. would result in continuously ringing of the bell 😉
In the code I use, the trigger pin is D2. When D2 is low, the doorbell button/switch is not pressed. When the doorbell button/switch is pressed, the logic state of D2 will be high. Because it is connected via the switch to the 3v3 (please do use 3v3 and not 5v!! The logic ports of an ESP is 3v3 logic).
When not pressed, the port D2 must be low. To ensure it is low (and not floating between high and low) we need to use a resistor to pull the port down.