Spook’s Time in State helper helps Home Assistant preserve state history
The Spook integration’s Time in State helper keeps the time an entity entered its current state through Home Assistant restarts and temporary device outages, helping stabilize time-based automations.
Home Assistant’s last_changed and last_updated properties can reset when the system restarts or a device becomes temporarily unavailable. That can make automations calculate the duration of a state incorrectly.
The Spook integration includes a Time in State helper that creates a timestamp sensor for when an entity entered its current state. The timestamp is designed to survive Home Assistant restarts and temporary connection problems.
The helper can support automations such as reminding users to close a window after it has remained open for a set period. It does not, however, detect state changes that happened while Home Assistant or the device was offline.
An observed attribute indicates whether the helper saw the state change. When it did not, the timestamp reflects when the change was first noticed rather than necessarily when it occurred; changes that happen and reverse while the system is offline may go entirely undetected.