Smart Doorbell - notify HA when ESP returns from deepsleep

Dear all

In our multi-appartment building we have an old doorbell system (1970s) from Koch (Model K933UP). My goal is to be able to open the main-door from HA without modifying the existing system too much.

I started based on the following project: https://www.reichelt.com/magazin/en/build-smart-doorbell-arduino/

I used a D1 mini board with a relay shield as ESP and configured it appropriately with ESPhome.

As I use a 18650 battery as power source, I put the ESP into deep sleep when not in use.

Once the bell rings, the D1 is woken up from deep sleep and connects to wifi (which happens quite fast). However it takes some time till HA connects again and you can control the entities via HA. Is there any way to speed this part up?

Maybe using mqtt can be faster because the ESP know the IP of the broker. With HA protocol, is HA how find new ESP’s

Thanks - I just had another idea: notify HA via a webhook once the device is online.

I therefore used the web_server functionality on the ESP and the automation/webhook/script functionality on HA.

The config looks as follows on the ESP side:

  on_boot:
    - while:
        condition:
          not:
            wifi.connected
        then:
        - delay: 1s
    - http_request.post: http://192.168.1.253:8123/api/webhook/door-opener-esp?action=on
  on_shutdown:
    - http_request.post: http://192.168.1.253:8123/api/webhook/door-opener-esp?action=off

And on HA:

automations.yaml - expects action=[on|off]

alias: Toggle door opener ESP helper-state when webhook is called
description: ''
trigger:
  - platform: webhook
    webhook_id: door-opener-esp
condition: []
action:
  - service: 'input_boolean.turn_{{ trigger.query["action"] }}'
    data: {}
    entity_id: input_boolean.door_opener_esp_online
mode: single

configuration.yaml

shell_command:
  turn_on_door_buzzer: curl -X POST http://192.168.1.38/switch/relay/turn_on
  turn_off_door_buzzer: curl -X POST http://192.168.1.38/switch/relay/turn_off

scripts.yaml

door_opener_4s:
  alias: Door Opener 4s
  sequence:
  - condition: state
    entity_id: input_boolean.door_opener_esp_online
    state: 'on'
  - service: shell_command.turn_on_door_buzzer
    data: {}
  - service: tts.google_say
    data:
      entity_id: media_player.sonos_bedroom
      message: Door has been opened.
  - wait_template: ''
    timeout: 00:00:04
    continue_on_timeout: true
  - service: shell_command.turn_off_door_buzzer
    data: {}
  mode: single
  icon: mdi:door-open