I included a wake_on_lan button and the web server component in one of my ESP32 devices. So, presumably, the next time the power goes out at the house and I’m not home I can VPN into my network and restart my HA server via that ESP32. …my UPS needs some new batteries.
I’m trying to figure out a way to automate this so that if the ESP32 status binary sensor is off for 2 minutes the ESP32 will automatically send the WOL packet. Can someone help me out, please? I’ve tried on_... and I’ve tried Lambdas, and I’ve come up short. Perhaps it would be better to use api.connected?
The below yaml is working. I changed it to 5 minutes.
Maybe someone else will benefit from this. To be clear, this is the ESPHome yaml for an ESP32. Now, when the status changes the ESP32 checks again 5 minutes later, and if the ESP32 is still not connected to HA it sends a WOL to my server.
Edit: I realized that the ESP32 will likely boot up with a “false” status and thereby never experience the state change needed to trigger the WOL. So I’ve added this to the top of the yaml file:
Edit again: I replaced the on_state automation entirely with the on_boot automation, because I’m really only concerned with the ESP32 sending WOL when it powers on. But if I were to want to keep the on_state automation and incorporate a way to trigger a state change when the ESP32 powers on, I could add publish_initial_state: true to the status sensor. Just an FYI for anyone interested.