Home assistant system time goes bad after a power outage

I have been using time based automations for a while and they form part of the integral automations I have currently. However, I have observed something about the system time. Anytime there is a power outage, the time stops at the time of outage and continues when the power is back on. I have tried resetting at the developer tool section using the Input_datetime.set_datetime service but to no avail. I wonder what happens to the time when there’s a power outage and does anybody who experiences this have a work around?

What do you mean by this?

If you mean that your system time is behind the actual time by the length of the power outage has reset to 1970 then Home Assistant has a problem reaching an NTP server to adjust the time. EDIT: See Christoff’s reply below.

If however you mean that your missed time triggers are not firing when home assistant resumes - that is the expected behaviour. The triggers occur at the time not after the time.

If you require missed time triggerss to be actioned this is available from a custom scheduler component (time triggers missed by restarting/offline will still trigger on restart). See:

Are you using a Raspberry Pi? It doesn’t have a (battery backed) real time clock and needs an active Internet connection to get current time using NTP. Until done, time will be 1. Jan. 1970

Thank you Tom for your response. I actually mean the section you striked out in your response. The actual time is behind by the length of time the power outage lasted. And anytime I restart my HA instance by power cycling my RasPi 4, the system clock goes back to the time of the outage.

Also thank you for your resource on missed time triggers. I have been looking for something like that recently. Would check it out

Yes I use a RasPi 4 for my HA. And no the system clock does not reset to 1970. It starts from the time of the outage. Is there a way to manually set the system time as a work around?

Can you specify the „system time“, you are referencing to? System time for me is what you get when you run date command on the host. Never seen that it stops and continues.

It‘s either Jan 1st 1970 (no RTC, no network) or current time (RTC or NTP).

The PI’s OS includes a utility called fake-hwclock that writes the current time out as a file periodically (and at shutdown) then loads it back in when the machine starts again.

This is obviously a silly thing to rely on for a time-based Home Automation system.
e.g., if the power is out for many hours, and now your lights are going on/off at odd times of the day because the clock is so far off.

For my Pi (running HA Core, so I can tinker with the underlying OS), I’ve added a battery-backed clock on the I2C bus and the OS loads time from it at startup. That way, even if it can’t get to an NTP source, it’ll at least be running within a second of actual time.

HomeAssistantOS for the Pi needs internal support for such a thing.