I’ve been working with Home Assistant for a few months now and I’ve really enjoyed setting up my smart home. One thing I’ve noticed is the behavior of template binary sensors, especially when it comes to restarts. I have a few occupancy sensors set up using templates, and I’ve noticed that after a restart, they sometimes reset to an ‘off’ state, which can be a bit of a nuisance.
For example, I have a sensor in my living room that uses a motion sensor with a 120-minute delay off. The idea is that once motion is detected, the lights stay on for 120 minutes before turning off. However, if I restart Home Assistant for any reason, the sensor resets, and the lights turn off immediately, even if someone is still in the room.
I did some research and found that adding a delay_on or delay_off should help retain the state by storing a timestamp attribute. This way, when Home Assistant restarts, it can use the previous state and timestamp to determine the correct state and remaining time. I tried implementing this, and while it helps, I’m still experiencing occasional issues.
I’d love to hear from others who have tackled this problem. Have you found a reliable way to maintain the state of template binary sensors through restarts? Any tips or tricks would be greatly appreciated! ![]()