New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
now().timestamp() not returning correct value #23422
Comments
Hi, BR |
Well something has changed because this used to work:
Now I have to use:
The timestamp for now() used to be the number of seconds from the epoch to the current local time. Now it has become equivalent to the timestamp for utcnow(). |
Looks like, but i think now it is correct. |
Mmmh this one works on my 0.92.0. I am in timezone +0200
|
In the template editor what do you get for:
Edit:I'm a bit reluctant to update to 0.92.0 considering the flood of bug reports. |
1556261835.273354 |
That's the problem. Until recently they weren't identical. The timestamp for now() used to include the local offset. |
{{ utcnow() }} And that is definitly correct now. |
Yep. Mine too. now() includes the offset but now().timestamp() does not. And I'm 100% sure it used to because I have templates that depend on the offset being included in the timestamp that were working perfectly. Unfortunately I did not notice when they stopped working as they run heaters and recently it has been too warm for them to come on automatically. |
That is correct. Maybe an issue with strptime in 0.91.4 that local timezone is not considered? If you agree that my short template (based on yours) is nearly identically. Than is issue seems to be fixed with 0.92.0 |
No you're missing the point. The timestamp was not the difference between the epoch and UTC for These two templates used to evaluate to different timestamps (differing by the local offset)
Now they dont for some reason. |
Ok, that the source i referenced: docs.python.org
|
Definitions are not the issue. I can only say it so many times: These were different:
Now they are not. Can we please have the local offset added back to now().timestamp(). |
@awarecan, @MartinHjelmare |
That is complex. You have system timezone, the timezone defined in your configuration.yaml, and the timezone pass in now() method. Bottom line, the Python native datetime object don't have tzinfo, e.g. it is local time, no timezone information. However, the way HA |
@awarecan thanks for clarification |
I like the sound of that. The only problem is that |
Latest change of this file was 9 Oct 2018 |
@tomlut, you said:
It has everything to do with strptime, and the time zone settings in HA and the environment in which HA runs. As I explained here, one issue is naive datetime objects vs aware datetime objects. As @awarecan, said, in HA, both So, in your old setup, when you got different results with In your new setup they do agree, so that's good. (Well, it's good if they agree because the clock and the time zone settings in both HA and the underlying environment in which HA runs are correct.) I think the bottom line is, your templates use both naive and aware datetime objects, which makes them vulnerable to incorrect time zone settings, even more so than usual. |
Phil is correct. This was a system (HassOS, not home assistant) time zone setting problem and the issue that caused with naive datetime objects. An update to 0.92.0 corrected this time zone setting and my original templates are working again. Thank you all for your assistance. |
Home Assistant release with the issue:
0.91.4
Last working Home Assistant release (if known):
Unknown
Operating environment (Hass.io/Docker/Windows/etc.):
Hassio NUC image
Component/platform:
https://www.home-assistant.io/docs/configuration/templating/
Description of problem:
The following two templates return the same value:
1556243287.686556
1556243287.686613
These however do not return the same value:
2019-04-26 01:48:07.686663+00:00
2019-04-26 11:48:07.686674+10:00
This has rendered my previously functional time templates incorrect and I now have to add my timezone offset in seconds to the now() timestamp.
Problem-relevant
configuration.yaml
entries and (fill out even if it seems unimportant):Traceback (if applicable):
Additional information:
The text was updated successfully, but these errors were encountered: