Hi All,
I’m using recorder component for fetch data into the MySQL. Now I discovered a strange behavior - time for last_changed for sensors is stored into the DB in UTC format. Any ideas how to fix this?
1 Like
You can’t fix it because it is not broken. This is how HA works. All backend times are in UTC. HA converts times to local time for display on the frontend.
1 Like
Thanks for quick reply. So I have to format it into the SQL.
here is the quick example how to get latest movement of the motion sensor:
- platform: sql
db_url: !secret db_mysql
queries:
- name: 'Last move'
query: "SELECT convert_tz(last_changed, 'UTC', @@session.time_zone) as last_changed FROM states WHERE entity_id = 'binary_sensor.motion_sensor_samsung_motion' and state='on' ORDER BY last_changed DESC LIMIT 1;"
column: 'last_changed'