Hi
After upgrading to 0.118 seems that the datetime in python script is returning UTC and not local time. Is this the case?
Any solution?
Thx
Hi
After upgrading to 0.118 seems that the datetime in python script is returning UTC and not local time. Is this the case?
Any solution?
Thx
More information:
In previous HA versions, calling the following returns correct local time:
"{{ as_timestamp(states('input_datetime.reminder2_date')) | timestamp_local }}"
in 0.118 I need to change it to UTC to get correct local time.
"{{ as_timestamp(states('input_datetime.reminder2_date')) | timestamp_utc }}"
Any idea why?
The good news is that it’s a known problem, there’s an open Issue in the Core repository, balloob is taking care of it and has created a PR to correct it. You can follow the discussion here:
Ended up here trying to find a way to get the current time in seconds in the local timezone in order to update my lights correctly in a circadian rhythm script I’ve written. Previously I used datetime.datetime.now()
, but that returned a datetime in UTC. Tried using the dt_util.as_local
, but that seemed to return the same datetime. Tried to use the dt_util.get_time_zone
in order to create a tzinfo object to pass to datetime.datetime.now()
, but that also failed because access to dt_util.get_time_zone
is restricted.
Finally realised that there is a dt_util.now()
function and looking at the source code, it seemed to use the default timezone! This actually works and I now am able to get the correct amount of seconds using datetime.timedelta(hours=now.hour,minutes=now.minute,seconds=now.second).total_seconds()
Shame there seems to be no documentation for the dt_util library and the documentation for the Python scripts is also rather minimal. Hope that others struggling with this issue find this and are able to solve their issues.