Logbook timestamps consistently off by 6 minutes

I need some expert help please - I’ve been running HA on an RPi 4 for several years, but over the past few days I’ve noticed that every event that gets recorded is late by 5 or 6 minutes (i.e. this is not a timezone issue). For example, I will turn on a light at 11:16 (according to the actual time) but in the logbook and history it is recording it at 11:10. When the time actually changes to 11:16, the time sensor on my HA will report it is 11:10 (see image).


It is almost as if the HA (or the RPi) thinks it is the wrong time. I did some diagnostics with an add-on comparing it to an NPT and I found the following statement (see 3rd screenshot) “System’s initial offset: 327.972680 seconds slow of true”.

I did go to the developer tools and ran the following template:

{{ now() }}

And it still gave a resulting time that is 6 minutes before the actual time.

Does anyone know what this means? Somehow I need to figure out a way to change the time on my Home Assistant.

Most likely your machine is 6 minutes off. Try syncing the time using NTP.

I think I ended up fixing it, so I thought I’d give the answer for future generations:

The RPi4 gets its time from a network time protocol (NTP). It doesn’t have an internal clock I guess. I looked at my internet system (Eero 6 and ATT) and did a hard reset of everything network related and for some reason it worked.

Yes! The Raspberry Pi does not have an internal clock, and its clock (even when set on boot) deviates a lot. To aid in this, you need ntpd or systemd-timesyncd running on the device at all times (and I think OSes for the RPi ship with a systemd unit that sets the clock on boot via NTP), and these services take care of adjusting the clock drift so that the system stabilizes the clock into a steady advance. Of course, the services need time servers to be accessible, otherwise they can’t measure drift and compensate for it.

There is a on-boot service called soft-hwclock (for which I have a Fedora RPM build) that saves the clock when the RPi safely powers off, and restores it on boot. It obviously can’t set the clock to the actual time, but at least it prevents the clock from jumping backwards.