Something is wrong with time

Hello,

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:
obraz

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:

{{ as_timestamp(now()) | timestamp_custom('%H:%M:%S %d-%m-%Y', True) }}

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.

Wny ideas how to fix it?

If you go to templates in dev-tools, what is the output of

{{now()}}
{{utcnow()}}

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.

how can we use it with raspberry pi4 since gpio is disabled in HA now?

Ohh, I do not know actually.
I run HA on a laptop and use my RPis for other stuff.

Here is a discussion on the topic.

I think there might be some hope with

there is hope at the end of the tunnel.

2022-07-10 14:05:51.375318+02:00
2022-07-10 12:05:51.375341+00:00

@ WallyR
I don’t use Raspberry Pi. It’s Ubuntu server on Intel CPU.

use Chrony if you can install add-ons

Did you check your battery then?

Nope, but I checked system time and it’s equal to HA’s now() output

which is the correct time or the wrong time?

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.

Is +2:00 correct for you?

1 Like

yes, it’s correct

Hi,

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.

Does swapping the coin battery fix this?

What timezone are you in?

What is your timezone set to here Open your Home Assistant instance and show your general Home Assistant settings.

Thanks for your reply. I am in the Europe/London time zone.