ESPHome doorbell with some safeguards

Currently I’m migrating from Tasmota to ESPHome and wanted to use this opportunity to improve some things. I have a Sonoff TH16 that is being used as a doorbell; GPIO14 is connected to the button, this will trigger the relay of the Sonoff that triggers an “old-fashioned” doorbell. Within Home Assistant an automation will play sound on my Nest-speakers when the doorbell button is being pressed.

What I would like to accomplish is:
Whenever the doorbell button (GPIO14) is being pressed it should check if Home Assistant is available and if that’s the case it should trigger the automation in Home Assistant. If Home Assistant isn’t available then it should trigger the relay and try to trigger the automation in Home Assistant. What’s my best approach?

Use the api.connected: condition:

2 Likes

For the ones trying to achieve the same, be aware that there is a delay between the moment the doorbell button is being pressed and the moment the Nest-speaker will play your .mp3-file, some delivery drivers will knock on the door before the Nest-speakers have played the sound. So I’ve undone the Native-API-component-check. Thanks @zoogara for the tip, it was useful.

Have a look at this one’s yaml…
It has a bit different aproach; you can turn off the chime (relay), in which case only HA will react :wink: