My ESP32 is configured to wake up from deep sleep based on a magnetic reed switch opening and closing and then goes back to sleep after 2s.
This works perfectly and it shows the state of the switch ( which is configured as binary sensor) correctly initialized in the logs, it connects to wifi and sets up the HA api, however its state as seen by my Home Assistant instance is very flakey - sometimes it gets updated and sometimes it doesn’t.
How can I fix this? Can I perhaps publish the state periodically somehow or some other alternative?
I have tried 5s, which didn’t change anything. From the logs it is definitely connecting to wifi in under a second each time.
Tried 10s and it seems better. I guess the issue is not connecting to wifi, but connecting to the HA instance which can sometimes take a little longer.
In an ideal world I’d wait until it connects to HA and sends the data and then immediately go back to sleep (instead of waiting some relatively long time and hoping for the best). Is that possible?