The idea to include my door bell into Home Assistant has existed since 2018. I’ve asked a colleague who is an electican how to do this.
A few days later he gave me a schematic and tried to explain it to me, but I couldn’t understand it’s function.
As you can see on last weeks posts, I finally fought through it and got it working. :-)
The door bell is a very simple 12V AC circuit. If you press the button, the electromagnet activates the doorbells chime.
I’m using Home Assistant for a long time now. New in my setup is ESPHome, which allows it to confgure sensors on ESP32 boards whithout writing any additional code.
The challenge was now to connect the 12V AC door bell to one of the 3.3V DC GPIO Pins of the ESP32.
The circuit consists of three components.
The AC signal is rectified (sorry, german post) with a diode and a capacitor, afterwards a resistor limits the current flow so that a LED can be connected.
Instead of a simple LED we use a optocoupler. A optocoupler consists of a LED and a phototransistor. It allows to control one circuit from another one.
So door bell and ESP32 are isolated from each other. The ESP32 requires it’s own 5V power source.
The output pins of the optocoupler are connected to the ESP32, it’s just like a simple switch.
- 1x 1N4001 Rectifier Diode
I had this diode laying around, it should be possible to use any other rectifier diode.
- 1x Capacitor 220µF 25VDC
Somehow it is possible to calculate the required capacitor (recommended), or you take a look to the oscilloscope (sorry, german post) to measure which capacitance is the most fitting (lazy method).
- 1x CNY17-2 Optocoupler
The optocoupler model was choosen by my colleague. It should be possible to use any other model as well.
- 1x 820 Ohm Resistor (For a 12V door bell)
Take a look to the data sheet of the optocoupler and calculate the size of the resistor afterwards just as you do it with normal LEDs.
- 1x 12k Ohm Resistor
Pull-Down resistor for the input signal on the ESP32.
As I mentioned earlier, ESPHome enables us to use sensors without writing any additional code. Which component is used in which way is described with YAML.
ESPHome communicates with the “outside world” via MQTT. I use the Mosquitto Broker for this.
esphome: name: esp_floor platform: ESP32 board: nodemcu-32s wifi: ssid: "ExampleWifi" password: "password1" binary_sensor: - platform: gpio pin: number: 26 mode: INPUT_PULLDOWN name: "Door Bell" state_topic: smarthome/floor/door_bell filters: - delayed_off: 100ms on_press: then: - output.turn_on: led18 on_release: then: - output.turn_off: led18 output: - platform: gpio id: led18 pin: number: 18 mqtt: broker: 192.168.1.1 username: esphome password: password1 discovery: True discovery_retain: True topic_prefix: smarthome/floor
binary_sensor uses the pin connected to the optocoupler. Wether the door bell is pressed
or not is published at the MQTT topic
ESPHome allows it to create automations without Home Assistant as well. If the bell button is pressed,
on_release is controling the LED at pin 18.
And now the best part. The auto discovery of new components in Home Assistant. The MQTT broker is connected to Home Assistant as well. ESPHome creates meta data topics which enables Home Assistant to create the sensor on it’s own.
The door bell binary sensor can now be used to create notifications, for example.
Many thanks to everyone, for answering my questions with a lot of patience. :-)