Wireless Doorbell with esphome and homeassistant



A short description for turning an ancient doorbell into a smart doorbell with esphome, homeassistant and mqtt

Flashing the esp-01

The esp-01 needs to be flashed with some firmware before we can use it. To start with, we just need a version of esphome and from then on we can use Over The Air updates (OTA) for our customisation.

Using the wiring guide from Franck Nijhof and the ESP Web Tools demo flash the chip with the basic esp-web-tools-example.

Doorbell Buzzer

The main doorbell is pretty much in line with Franck’s guide although I did add some extra mqtt configuration which will be covered below.

Wireless Chime

We can’t hear the main doorbell very well from the kitchen so I wanted to create an extra wireless chime. Here is how I went about it:

Use the esphome wizard to create a project

docker run --rm -v "${PWD}":/config -it esphome/esphome wizard doorbell_chime.yaml

Initial configuration for the chime

esphome:
  name: doorbellchime

esp8266:
  board: esp01_1m

# Enable logging

logger:

# Enable Home Assistant API

api:
  password: ""

ota:
  password: ""

wifi:
  ssid: "wifi"
  password: "wificode"

  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "wifi"
    password: "wificode"

captive_portal:

# Enable Web server.
web_server:
  port: 80

Add some extra lines so the esphome device will show up in homeassistant

# Sync time with Home Assistant.
time:
  - platform: homeassistant
    id: homeassistant_time

# Text sensors with general information.
text_sensor:
  # Expose ESPHome version as sensor.
  - platform: version
    name: DoorbellChime ESPHome Version
  # Expose WiFi information as sensors.
  - platform: wifi_info
    ip_address:
      name: DoorbellChime IP
    ssid:
      name: DoorbellChime SSID
    bssid:
      name: DoorbellChime BSSID

Deploying over the air

docker run --rm -v "${PWD}":/config -it esphome/esphome run doorbell_chime.yml > log.txt

There will most likely be an error message

INFO Successfully compiled program.
INFO Resolving IP address of doorbellchime.local

ERROR Error resolving IP address of doorbellchime.local. Is it connected to WiFi?
ERROR (If this error persists, please set a static IP address: https://esphome.io/components/wifi.html#manual-ips)
ERROR Error resolving IP address: Error resolving address with mDNS: Did not respond. Maybe the device is offline., [Errno -2] Name or service not known

If using DHCP search the log for ’esp-web-tools-example’ or just ’esp’. ie

tail -n 1000 -f /var/log/syslog | grep 'esp'

Add a local DNS record to pihole for doorbellchime.local. Don’t add to /etc/hosts, for some reason it doesn’t work.

Add to homeassistant

For me, the esp device was not automatically added so I needed to add a new esphome integration with the ip address in home assistant

Now we are off and running.

Tell the wireless chime that the doorbell button has been pressed

I am sure I could have used homeassistant to trigger the wireles chime, but I wanted to experiment with the two esp devices talking to each other using mqtt. The two devices share an mqtt topic (/doorbell). When the doorbell button is pressed, the main doorbell esp publishes a message on this topic and the wireless chime uses this to trigger the bell. It works amazingly well! These are the mqtt changes to the esp config files:

Main doorbell

# Enable mqtt to send a message to our wireless receiver
+mqtt:
+  broker: mqtt.host.name
+  port: 1883
+  topic_prefix: doorbell

# Binary sensor representing the
# Doorbell button push.
binary_sensor:
  - platform: gpio
    id: button
    name: Doorbell Button
    pin:
      # Connected to GPIO on the ESP-01S.
      number: GPIO2
      mode: INPUT_PULLUP
      inverted: true
    filters:
      # Small filter, to debounce the button press.
      - delayed_on: 25ms
      - delayed_off: 25ms
    on_press:
      # Only turn on the chime when it is active.
      then:
+        - logger.log: "Publishing on mqtt message"
+        - mqtt.publish_json:
+            topic: doorbell/chime
+            payload: |-
+              root["button"] = id(button).state;
+        - if:
            condition:
              - switch.is_on: chime_active
            then:
              - switch.turn_on: relay

Wireless chime

# Enable mqtt to send a message to our wireless receiver
+mqtt:
+  broker: mqtt.host.name
+  port: 1883
+  topic_prefix: doorbell
+  on_json_message:
+    topic: doorbell/chime
+    then:
+      - logger.log: "Ringing chime"
+      - switch.turn_on: relay
+      - delay: 3s
+      - switch.turn_off: relay

Wireless Doorbell Chime Version 0.1

{.left .image}

Here it is, reusing an Amazon USB 5v power supply…