I have searched the forum but I am unable to find what I am looking for.
What I want to do is perform X actions if I lose connect to an ESP32. I am using ESPHome. I would like to turn off X devices if I lose connect to an ESP32 providing sensor data. I dont see an obvious way to do this using an automation. Is there another way or a way to do it via an automation?
I have an automation for noticing when my D1 Mini hall thermostat goes down, which it does roughly twice a week due to memory issues with the OLED screen connected to it — and the ESPHome API reboot_timeout doesn’t seem to work.
The wifi reboot_timeout does, though, so my automation warns me that it’s down, turns off the heating (otherwise, if on, it would just keep running!), and blocks it from the wifi for 5 minutes (Unifi integration) which is enough to kick it back into life.
Here’s the automation — the 30 second delay gets around the HA startup problem, and when I deliberately restart the node with new code:
- alias: Hall sensor unavailable
trigger:
- platform: state
entity_id: sensor.hall_temperature
to: 'unavailable'
for:
seconds: 30
condition: []
action:
- service: notify.admin
data_template:
message: 'Hall temperature sensor offline! Trying to reconnect...'
- service: switch.turn_off
entity_id: switch.hall_temperature_sensor
- service: switch.turn_off
entity_id: switch.chc_central_heating_relay
- delay: 300
- service: switch.turn_on
entity_id: switch.hall_temperature_sensor
- service: notify.admin
data_template:
message: 'Done. If still offline, please solve manually.'
I dont have mqtt set up. It would seem if it is possible to do with a simple automation that would be easier? This is not mission critical stuff so a delay of 5-10 mins is not unreasonable to handle reboots etc.
That said - I set up an automation similar to what was shown above and it is not detecting the ESP32/sensor as unavailable… hehe
alias: Connect.loss ESP05 turn off SO01
description: Connect.loss ESP05 turn off SO01
trigger:
- platform: state
entity_id: sensor.05_temp
to: unavailable
for: 10s
condition: []
action:
- type: turn_off
device_id: 6d41b25dbe1d35a7a5997d31f3d29750
entity_id: switch.so01_relay
domain: switch
mode: single
I just copied what the GUI made for yaml. I tried it with quotes around unavailable in gui and it added 3 quotes to it in yaml. Weird. I will try changing the format of the for:
Care to expand? I dont see a ‘status’ trigger type in automations GUI for this. Nor do I see a way to set up a binary sensor in automations or devices. I am still pretty new to HA. I dont know what I dont know.
Ah ok so I add the binary node config to the yaml file for each device? That makes more sense. It is not clear as to context in the docs. I will try that in a bit. No more time to play right now.
Well for dummies like me it needs to say - add this to your yaml for the device. I am just a lowly luser trying to figure this out. Watching all the brain_rockets on here fly by. Or even better, a checkbox in the gui that says ‘add this binary sensor’. That would be slick!