Hi folks,
Sorry this has turned in to a long post…
On Wednesday we had a planned power outage, and I shutdown HA before the outage, at 12:10 local time. The power was off for just over an hour, and when restored, the Raspberry Pi running HA restarted at about 13:17.
The following day (Thursday) I discovered that 3 time based actions that run overnight all ran 1 hour and 5 minutes late. These actions should run at 23:00 (Wednesday), 00:30 and 05:30 (Thursday) local time, but they actually ran at 00:05, 01:35 and 06:35 on Thursday, i.e they were 1 hour and 5 minutes late, and the system was offline for one hour and 5 minutes, which is too much of a coincidence for me!
I’ve reviewed the Supervisor and Host logs, and as expected, when the system restarts after the power cut, the system time is wrong, as the Pi does not have an internal (RTC) clock, so the time picks up from where it left off, i.e. around 12:10. After a while the system time changes from 12:13:43.924 to 13:19:21.213 when timesyncd runs and gets the correct time from a network time server (time.cloudflare.com).
2025-02-26 12:13:52.405 homeassistant NetworkManager[497]: <info> [1740572032.4050] device (veth158d6a3): carrier: link connected
2025-02-26 13:19:21.213 homeassistant systemd-timesyncd[576]: Contacted time server 162.159.200.123:123 (time.cloudflare.com).
However, the 3 time based automations all execute 1 hour an 5 minutes later than they should, despite the logbook entry showing the correct time that they should run. Here is the first example
It looks to me that after the system restarted, these 3 actions were scheduled, and some process compares the system time (e.g. 12:11 which has not yet been updated) and the desired execution time (e.g. 23:00), and calculate the difference as 10 hours and 49 minutes, which is then used as a countdown timer and runs the action when the timer reaches zero. Unfortunately in the meantime the system time has been updated, and advanced by an hour and 5 minutes, but the countdown timer doesn’t get updated, and so when the timer reaches zero, the action executes an hour and 5 minutes late. Does that makes sense ?
I found a few similar questions describing the same issue without any resolution, but because the issue resolves itself after a day, I imagine it is easy to just forget about it.
It’s now late enough on Thursday that the next set of automations has started, and the 23:00 executed exactly on time.
In the case of a power cut, my Pi will almost certainly reboot and HA will start running before my router and Broadband modem have finished rebooting, and so the HA will not be able to reach the NTP server and the system time will initially wrong. Although NTP / timesysncd will correct the system time, the time based triggers have already been created, with the wrong interval for the countdown timer.
If you got this far, thanks for reading ! Am I missing a setting in HA to resolve this issue, or is there another explanation, or is this a bug that I should report?