ESP Automation - Cannot Connect to Home Assistant

Hi all!
Hope you are fantastic.

I have a ESP32 running in EspHome and it controls a couple of relays.
My thought the other night is if we have a power cut then Home Assistant might not be able to tell this ESP running from batteries to close the solenoids!

What would be the best way to go about this?

  1. If you cannot talk to home assistant then close relays
  2. Home assistant asks to open them and then the closing relays is timed based maybe from a script?

Hi there, to check if there is connection between HA and esphome, you can use the Status Binary Sensor — ESPHome like below.

binary_sensor:
  - platform: status
    name: "Living Room Status"

Now like any binary sensor automation you can use it close relays or not.

For more I believe you can upload the script and explain the requirement.

You should check for api.connected on your esphome node and trigger to close the relays when it’s not connected anymore

can just use a on_turn_on action with a template switch to turn the relay on, have a delay and turn it off again

Thank you for the references
Didn’t think of using the Native API component