Quantcast
Channel: Configuration - Home Assistant Community
Viewing all articles
Browse latest Browse all 95365

Wrong time from sensor last changed query

$
0
0

@andyng wrote:

Hello,

I am having the problem when config Home Assistant.
I run HA on Odroid box. The lovelace UI always shows the timestamp of the sensor using UTC.

Here is the detail info:

{{ utcnow() }}
{{ now() }}
{{ utcnow().astimezone() }}
{{ now().astimezone() }}
{{ utcnow().tzinfo }}
{{ now().tzinfo }}
{{ now().astimezone().tzinfo }}

Return:

2019-11-07 15:53:46.504967+00:00
2019-11-07 09:53:46.505081-06:00
2019-11-07 09:53:46.505217-06:00
2019-11-07 09:53:46.505550-06:00
UTC
America/Regina
CST

Linux said:

timedatectl status

Return:

      Local time: Thu 2019-11-07 09:52:56 CST
  Universal time: Thu 2019-11-07 15:52:56 UTC
        RTC time: Thu 2019-11-07 15:52:57
       Time zone: America/Regina (CST, -0600)
 Network time on: yes
NTP synchronized: yes
 RTC in local TZ: no

I have a door sensor, and creat a query to grab last changed status:


- platform: sql
  scan_interval: 2
  queries:
    - name: living to garage door last opened
      query: "select last_changed from states where entity_id = 'binary_sensor.0x00158d000275ef5d_contact' and state = 'on' order by last_changed desc;"
      column: 'last_changed'
      value_template: "{{ as_timestamp(value) | timestamp_local }}"    

But it always show UTC time on Lovelace UI.
I tested in Developer tool > Template

{{ as_timestamp( states.binary_sensor['0x00158d000275ef5d_contact'].last_updated) | timestamp_local }}

And it returns the correct time with local time zone.

In configuration.yaml file, I already set the time zone:

time_zone: America/Regina

Am I missing something? Thank you :blush:

Posts: 9

Participants: 2

Read full topic


Viewing all articles
Browse latest Browse all 95365

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>