"Internal" time wrong

Thanks for getting back, so does that mean {{ now().astimezone().tzinfo }} should have returned UTC or AEST?

Is there a way to set the environment / HassOS timezone when running HassIO on a Pi? There is a command interface via Configurator. SSH does not seem to have any time options when issuing commands to host. Thanks

I’m having the same issue. Did you manage to solve it?

The Hassio UI is showing the correct Sydney time
But the Log file is showing UTC time

How can I change the OS time?

@Milster @RKor

I have no idea how to set the environment’s time zone when using hassio & hassos. I use a venv install. But if you search this forum you should be able to find it. I know it’s been discussed a zillion times.

OK, thanks. Love Life360 btw!!!

1 Like

I’m having a similar problem, though I first noticed it with alerts - alerts I set for 2 minutes fire 7 hours (my time zone difference) and 2 minutes later.

Running the time zone commands in template editor seems to indicate astimezone is UTC, but tzinfo is America/Los_Angeles

{{ now() }}
{{ now().astimezone() }}
{{ utcnow().astimezone() }}
{{ now().now() }}
{{ now().today() }}
{{ now().utcnow() }}
{{ utcnow() }}
{{ now().tzinfo }}
{{ now().astimezone().tzinfo }}
{{ utcnow().tzinfo }}
2019-05-31 11:26:19.773069-07:00
2019-05-31 18:26:19.773223+00:00
2019-05-31 18:26:19.775135+00:00
2019-05-31 18:26:19.775495
2019-05-31 18:26:19.775705
2019-05-31 18:26:19.775898
2019-05-31 18:26:19.775936+00:00
America/Los_Angeles
UTC
UTC

It seems that somehow my Python environment has the wrong time zone. However, I have no idea how to fix this.

My previous thread, in case there’s useful info there:

I was able to change the timezone in my config.yaml and now my timed alerts are firing every 2 minutes as expected instead of every 7 hours and 2 minutes.

I’d much rather be able to actually use the time zone I’m in, but at least I have a work around for now.

I have a similar error like above, but I’m not sure exactly where the problem is.

Running Hassio
Got my recorder running on mariadb as an addon from hassio
Timezone is set to Europe/Stockholm in configuration.yaml.

Everything in the GUI is correct, looking at the history of a device shows the correct time, but if I do a value_template on the “last_changed” attribute, that time is 2 hours wrong. (seems to be using UTC time).

I just did a reebot of my server at 21:10 (24h time) and below template gives me “19:10”

value_template: "{{ states.binary_sensor.ytterdorr_las.last_changed.strftime('%H:%M') }}"

But looking at the gui, the time of last_changed is correct at “21:10”.

Is this to be expected? If so, how could I write my value templates to show me the correct time?


{{ now() }}
{{ now().astimezone() }}
{{ utcnow().astimezone() }}
{{ now().now() }}
{{ now().today() }}
{{ now().utcnow() }}
{{ utcnow() }}
{{ now().tzinfo }}
{{ now().astimezone().tzinfo }}
{{ utcnow().tzinfo }}
2019-09-05 21:18:55.749530+02:00
2019-09-05 21:18:55.749606+02:00
2019-09-05 21:18:55.749749+02:00
2019-09-05 21:18:55.749854
2019-09-05 21:18:55.749914
2019-09-05 19:18:55.749967
2019-09-05 19:18:55.749976+00:00
Europe/Stockholm
CEST
UTC

Yes, this is to be expected, because that attribute (and most others) are expressed in UTC. Try this:

{{ as_timestamp(states.binary_sensor.ytterdorr_las.last_changed)|timestamp_custom('%H:%M') }}

By default timestamp_custom outputs the time in the local time zone.

1 Like

Aah, thanks alot for the example as well!

Is it possible to update the home assistant documentation? I think this would be great to add somewhere

Can anyone explain why my desktop Chrome browser shows time off of UTC while my phone Chrome browser shows it correctly off of PTC?

Relevant YAML:

input_datetime:
  airbnb_deadbolt_unlocked_by_guest_user_3:
    name: Last Unlocked by Guest (User 3)
    has_date: true
    has_time: true
    icon: mdi:account-key

sensor:
- platform: template
  sensors:
    deadbolt_last_unlocked_by_guest:
      value_template: >-
        {{ states.input_datetime.airbnb_deadbolt_unlocked_by_guest_user_3.last_updated.strftime('%Y-%m-%dT%H:%M:%S') }}
      friendly_name: 'Last Unlocked by Guest'
      device_class: timestamp

automation:
  trigger:
    platform: state
    entity_id: sensor.airbnb_deadbolt_alarm_level
    to: '3'
  action:
  - service: input_datetime.set_datetime
    data_template:
      entity_id: input_datetime.airbnb_deadbolt_unlocked_by_guest_user_3
      date: >
        {{ now().timestamp() | timestamp_custom("%Y-%m-%d", true) }}
      time: >
        {{ now().timestamp() | timestamp_custom("%H:%M:%S", true) }}

Lovelace:

          - entity: sensor.deadbolt_last_unlocked_by_guest
            secondary_info: last-changed
            format: relative

I’m posting this in hopes it will help someone:

Trying these two:

{{ states.input_datetime.airbnb_deadbolt_unlocked_by_guest_user_3.last_updated.strftime('%Y-%m-%dT%H:%M:%S') }}
{{ as_timestamp(states.input_datetime.airbnb_deadbolt_unlocked_by_guest_user_3.last_changed)|timestamp_custom('%Y-%m-%dT%H:%M:%S') }}

Gave me:

2019-10-03T16:36:43
2019-10-03T09:36:43

So I updated the template sensor:

    deadbolt_last_unlocked_by_guest:
      value_template: >-
        {{ as_timestamp(states.input_datetime.airbnb_deadbolt_unlocked_by_guest_user_3.last_changed)|timestamp_custom('%Y-%m-%dT%H:%M:%S') }}
      friendly_name: 'Last Unlocked by Guest'
      device_class: timestamp

And it’s solved:

@pnbruckner - Apparently I didn’t check my phone last time but it’s showing -7 hours now (time without applying the timezone) while my laptop is showing the time with the time zone applied (ie - 8 seconds).
Do you have any thoughts on why there could be this discrepancy?

I posted the views above that appear to show both browsers are calculating the same numbers when using the templates dates.

Also looking for this file.

guys i got same issue but i don’t know how to fix it
take a look on this snapshot

What issue? The timestamps in the database are in UTC. That’s not an issue. What problem do you think you have?

all i understand that it Hassio is using UTC while writing in the database as default ,i want to change the writing in database instead of UTC to EET ,do u know to change that? @pnbruckner

No, because you can’t. Why do you want to do this?

the history that i read from database i want to view it but it give me UTC ,and i want in EET ,it will force me to make changes in my query @pnbruckner or if u have another idea

Maybe you need to describe where and how this querying of the database will be done. Are you doing this in Home Assistant (HA), or in something else? If you’re doing it in HA, there might be another way to solve your problem. Again, it would be helpful to understand what you’re ultimately trying to achieve.