I can’t figure out what’s wrong with my HomeAssistant but if my server looses power there is some kind of time shift.
I prepared an example with bar light:
It’s turned on but the last change of state is described as ‘9 hours ago’. My timezone is corrent and if I check current time using template it shows correct time:
There are other implications of this behavior. For example, I have automatic lights based on brightness sensor. It looks like all automations are taking brightness value from the 9 hours past and think it’s middle of the night and turn on my lights when movement detected.
You are probably using a Raspberry device.
A Raspberry does not have an onboard Real Time Clock (RTC) and therefore the clock might be out of sync on restarts.
This can also happen on other computers if the RTC battery is dead.
The OS calls a time server (NTP) server on the internet and corrects the time then, but it might take long enough for your HA setup to have reacted on the wrong time.
If you are using a Raspberry device, then there is RTC modules available for it. The ones based on the DS3231 chip is considered extra good, because the drift when temperature is changing is taken into account in the design.
If you are not using a Raspberry device, then open up your server and see if you have a coin cell battery somewhere. Read the text on it and buy a new one of that type. Its typical something like CR2032 or the like.
The correct time is shown by now(), utcnow() or date command in the Ubuntu server but HA is shown ‘the last change’ time like now()-9h (check screenshot from the first post and I don’t know why.
Even if I just turn on my light it’s show as 9h ago last change
When the NTP client runs, then the RTC gets updated too, but if the battery is dead then it will not keep that time over longer or shorter periods with power off.
getting this very same issue and its driving me mad.
HAOS on Lenovo thinclient. now(), utcnow() and date command all fine. My config file is also all correct with my location but all logs and automation triggered times are 8 hours behind.