This article is also available in the following other languages / Dieser Beitrag ist auch in folgenden anderen Sprachen verfügbar: Deutsch

Building a smart door bell

2021-01-08 · christian · electronics, embedded, esphome, home assistant, smart home

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. :-)

Door bell in Home Assistant

Door bell

The door bell is a very simple 12V AC circuit. If you press the button, the electromagnet activates the doorbells chime.

Smarthome

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.

Circuit

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.

Circuit

Parts

  • 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.

Breadboard

Original Picture

ESPHome

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

The binary_sensor uses the pin connected to the optocoupler. Wether the door bell is pressed or not is published at the MQTT topic smarthome/floor/door_bell.

ESPHome allows it to create automations without Home Assistant as well. If the bell button is pressed, the on_press or on_release is controling the LED at pin 18.

Home Assistant

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.

Door Bell in Home Assistant

Many thanks to everyone, for answering my questions with a lot of patience. :-)


More


serverless.industries BG by Carl Lender (CC BY 2.0) Imprint & Privacy
4fa348d0 2024-08-31 14:04
Mastodon via chaos.social Mastodon via einbeck.social