can you share your code?
Hi @attila_ha,
Bringing this up from a while back. Iām looking at this code it would only check the condition of the api.connected when your motion is detected. I imagine this works great for checking if you have a connection at the time of motion. However, is there a way to trigger on the not api.connected state after the light is on?
My use case is a bit different as Iām controlling my HVAC furnace. HA turns on a relay and it stays on as long as HA calls for heat. But if I lose connection to the api after the heat is turned on, it will continue to stay on until it reconnects and sees the call for heat is off. Your failover control currently delays for 90s, but even if increase this to 20m, I think it would turn off the heater relay creating a āsaw toothā effect or just turning off the heat completely.
Is there a way of making it check every 5m to see if itās still connected to the api and if it is, then do nothing, but turn off the relay if it has lost the connection? Effectively an api watchdog?
Hi @poldim,
I hope I understood correctly what you described, I did address similar concerns at a different node I had that was turning on/off a transistor which was turning on a heater.
First, make sure if the ESPHome node shuts down, it turns off the heater. This can happen for reboots from updates or if it wants to reset itself.
on_shutdown:
then:
- switch.turn_off: <id_of_your_switch>
As for a periodic check when it loses connection, you can make a script that periodically checks the condition and acts accordingly. I cannot make a working example, as I donāt have this exact use-case, and I donāt want to suggest you something thatās not working, but in short you need to start a script when the node starts up, then call the script again at the end of the script and do some checks for the API in the middle.
esphome:
[other options]
on_boot:
- script.execute: connection_watchdog
script:
- id: connection_watchdog
mode: queued
then:
[check here for the API connection and start/stop the relay accordingly]
- delay: 300s
- script.execute: connection_watchdog
Why make it so complicated ? I had that issue as I use some shelly cloud relay (esp based) for lights control and wanted it to be working even without network/wifi or ha as itās light in stairs and bedrooms ! so I made the automation (including for timers) in ESP and I can see states or interact/force them in ha but in all matters it works by itself. Isnāt it easier ? and also makes less processing and basic logic to handle in HA !
Any chance you could share this code @vincen ?