A reminder to close a window needs more than an “open” reading. It needs the time the window opened. If the sensor briefly goes offline, Home Assistant can start the clock over when it reconnects. A helper from the Spook integration solves that problem: Time in State can retain the original opening time.
A How-To Geek writer ran into the problem with an automation that compares indoor and outdoor dew points. It suggests opening the windows when doing so would lower indoor humidity, then uses a window sensor to schedule a reminder to close them after a set interval. A sensor dropout pushed the reminder back, leaving the windows open longer than intended.
The issue is what Home Assistant’s timestamps record. The last_changed timestamp tracks changes in an entity’s main state. Switch on a light and dim it an hour later, and last_changed still shows when you switched it on. The last_updated timestamp tracks changes to attributes as well as the main state, so it shows when you dimmed the light.
After a Home Assistant restart, both timestamps can show when the entity became available again. A sensor that goes offline and reconnects also gets fresh timestamps, even if the window hasn’t moved.
Install the latest version of Spook, then select Time in State from Home Assistant’s list of helpers. Choose the window sensor and name the helper. It creates a separate timestamp sensor that records when the window sensor entered its current state. Use that timestamp to calculate when the close-window reminder is due. If the window stays open through a restart or dropout, the reminder can keep counting from the original opening time.
The helper still can’t see a window close while Home Assistant or the sensor is offline. To interpret its timestamp, check the helper’s observed attribute. A value of true means the helper saw the change; false means it didn’t. If the helper finds the window closed after an outage, a false reading means the timestamp marks when it discovered the closure. The window could have closed at any point during the outage. If it closed and reopened before the sensor reconnected, neither change will show up.




Discussion