ESPHome based doorbell

The working
The default ESPHome YAML code
The adjusted “dinging” ESPHome YAML code
The automation code

The working

With version 1.3, the ESPHome based doorbell is finally ready! The ESPHome Doorbell is a very simple modification to an existing hat: Relay Hat. I made some modifications to be able to use the doorbell power, to power the Wemos D1.

The working is quite simple. Normally the power supply, the bell and push button is placed in one loop/circuit. When the button is pressed, the circuit is closed and the bell will ring.

In the way I’ve designed my very first smart “dumb” doorbell, I needed to connect each component (power supply, doorbell and push button) separate to be able to accomplish full control on the doorbell.

This way the power supply is powering the ESPHome Doorbell, the push button is to trigger a binary sensor in ESPHome, and the relay is switching on and off the doorbell.

Code

Default ESPHome yaml code

This is the default ESPHome YAML code for 1-on-1 action: Doorbell pushed, relay on; Doorbell released, relay off. Most common for a standard “ring” bell.

esphome:
  name: doorbell
  platform: ESP8266
  board: d1_mini

wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_password


# Enable logging
logger:

# Enable Home Assistant API
api:

ota:

time:
  - platform: homeassistant
    id: homeassistant_time

text_sensor:
  - platform: version
    name: Doorbell ESPHome Version
  - platform: wifi_info
    ip_address:
      name: Doorbell IP
    ssid:
      name: Doorbell SSID
    bssid:
      name: Doorbell BSSID

sensor:
  - platform: uptime
    name: Doorbell Uptime
  - platform: wifi_signal
    name: Doorbell WiFi Signal
    update_interval: 60s

globals:
  - id: chime
    type: bool
    restore_value: true
    initial_value: 'true'

switch:
  - platform: gpio
    pin:
      number: D1
      inverted: false
    name: "Doorbell Relay"
    id: relay
    internal: true
    icon: mdi:alarm-bell
  - platform: restart
    name: "Doorbell Restart"
  - platform: template
    name: Doorbell Chime Active
    id: chime_active
    restore_state: false
    turn_on_action:
      - globals.set:
          id: chime
          value: 'true'
    turn_off_action:
      - globals.set:
          id: chime
          value: 'false'
    lambda: |-
      return id(chime);
    
binary_sensor:
  - platform: gpio
    pin:
      number: D5
      mode: INPUT_PULLUP
      inverted: true
    name: "Doorbell"
    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:
        if:
          condition:
            - switch.is_on: chime_active
          then:
            - switch.turn_on: relay
    on_release:
      # On release, turn of the chime.
      - switch.turn_off: relay        

  - platform: status
    name: "Status Doorbell"

Adjusted code for “DingDong”

In some cases, like for my own use, another action can be used. I like that when somebody pushes the doorbell, my “DingDong” bell goes 3 time:

esphome:
  name: doorbell
  platform: ESP8266
  board: d1_mini

wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_password


# Enable logging
logger:

# Enable Home Assistant API
api:

ota:

time:
  - platform: homeassistant
    id: homeassistant_time

text_sensor:
  - platform: version
    name: Doorbell ESPHome Version
  - platform: wifi_info
    ip_address:
      name: Doorbell IP
    ssid:
      name: Doorbell SSID
    bssid:
      name: Doorbell BSSID

sensor:
  - platform: uptime
    name: Doorbell Uptime
  - platform: wifi_signal
    name: Doorbell WiFi Signal
    update_interval: 60s

globals:
  - id: chime
    type: bool
    restore_value: true
    initial_value: 'true'

switch:
  - platform: gpio
    pin:
      number: D1
      inverted: false
    name: "Doorbell Relay"
    id: relay
    internal: true
    icon: mdi:alarm-bell
  - platform: restart
    name: "Doorbell Restart"
  - platform: template
    name: Doorbell Chime Active
    id: chime_active
    restore_state: false
    turn_on_action:
      - globals.set:
          id: chime
          value: 'true'
    turn_off_action:
      - globals.set:
          id: chime
          value: 'false'
    lambda: |-
      return id(chime);
    
binary_sensor:
  - platform: gpio
    pin:
      number: D5
      mode: INPUT_PULLUP
      inverted: true
    name: "Doorbell"
    filters:
      - delayed_on: 50ms
      - delayed_off: 3000ms # prevents from re-ringing within 3 seconds
    on_press:
      then:
        if:
          condition:
            - switch.is_on: chime_active
          then:
            - switch.turn_on: relay
            - delay: 400ms
            - switch.turn_off: relay
            - delay: 400ms
            - switch.turn_on: relay
            - delay: 400ms
            - switch.turn_off: relay
            - delay: 400ms
            - switch.turn_on: relay
            - delay: 400ms
            - switch.turn_off: relay            

  - platform: status
    name: "Status Doorbell"

Automation

When somebody is ringing the doorbell, I’d like two extra action to run, besides ringing the doorbell itself (that doesn’t need automation, that’s handled via the hat itself.

Send a notify

Whenever somebody is ringing the doorbell, I’d like to get a notification on my phone via the Home Assistant app. Of course any kind of notification can be addressed.

Flash a light group

A second action I’d like to automate, is to flash a certain group of lights. That way I get besides an audible notification, also a visual notification. In that group I can add any light I wish to flash.

The automation

The automation I use is the following simple few lines of code. It’s triggered by the binary sensor and activates the two automations. Of course you can choose any automation you like yourself.

- id: '<random id>'
  alias: Notify Doorbell
  description: ''
  trigger:
  - platform: state
    entity_id: binary_sensor.doorbell
    from: 'off'
    to: 'on'
  condition: []
  action:
  - service: notify.mobile_app_iphone_me
    data:
      title: Deurbel gaat
      message: Er belt iemand aan
  - service: light.turn_on
    data:
      flash: short
    target:
      entity_id: light.notify
  mode: single

Muting the doorbell

In the ESPHome YAML code there is a switch defined: switch.doorbell_chime_active. This is automatically added to Home Assistant when the doorbell is added.

That switch is enabled by default. By toggling it off, the doorbell will be muted. That’s all, no extra action required.

Of course, this can be automated. Mute the doorbell after 20:00 in the evening and enable it again after 7:00 in the morning. Me personally, I’m not a big fan for that. First of all, I don’t have kids and secondly, more important, if something happens, I want people, neighbors, or anyone else to warn me in case of emergency.

For those who like the alarm bell icon, I’m using “mdi:alarm-bell” for the icon 🙂