Home Assistant changed the details of its time zone implementation, starting w/ 2021.6.x. Specifically, it switched from the pytz package to Python’s new native zoneinfo library.
as you can see here, I did try the microsecond removal myself, but thought it hacky… though at the time I thought it showed only HH:MM and not :SS too… maybe not.
Indeed. I’m always confused about what device_class: timestamp actually expects.
I redid the test, and the UTC time correctly display in my local TZ w/o transformation.
Are you saying that the UTC time returned by MQTT is not actually UTC but local?
Then, it’s just wrong, and you have to “correct” it manually, indeed, no magic here.
OTOH, there might be a setting on whatever sends the message to set the correct TZ…
Where is it 2 hours off? The example I posted, using the datetime string you provided (Zulu time = UTC), clearly shows the resulting ISO8601 string remains as UTC.
what would be the exact remark I should bring across to the author here…
what is still confusing me is, that the Z is correct for the Utc time is 2 hours behind my zone, and when using that it shows the correct time difference.
My issue is to show that Z time in my local time
yes, in the template editor, but did you also use it in the frontend and using device_class: timestamp?
separate topic, trying to use the {{as_datetime(0|timestamp_utc).isoformat()}} jinja template in JS.
Python uses dt.utc_from_timestamp(0)
please help me translate this?
Having a hard time here, because the online tutorials dont use the jinja used here…
thanks
Both seem to show about the same time with the attribute being 19 seconds behind now, which is what I expect. If I convert both of those with as_timestamp, I get:
Now as timestamp: {{ as_timestamp(now()) }}
Attribute as timestamp: {{ as_timestamp(state_attr("sensor.my_sensor_name","LastUpdated")) }}
displays:
Now as timestamp: 1628155860.00095
Attribute as timestamp: 1628159441.0
This for some reasons is showing a difference of 3581 seconds. I’m assuming this is because of daylight savings and my current local time is +1, but I don’t want to just use a hacky -3600 bit of maths as this will break each time we switch from daylight savings. Where am I going wrong?
From a pure datetime perspective, it is correct.
Likely, whatever produced the “LastUpdated” attribute is wrongly configured, and thinks the date/time it has is utc rather than utc+1.
It’s actually a debate that Z means zulu time. There are references on wikipedia that state Z means zulu time, which apparently is GMT or UTC1, and there are references that state it means zero i.e. UTC. Either way, it seems that the user needs to figure this out for their application.