last_updated and last_changed are not attributes. The are part of the state object, so the code to access them in your case is: states.sensor.kitchen_motion_sensor.last_updated or states.sensor.kitchen_motion_sensor.last_changed
kitchen_movement:
friendly_name: 'Last movement in kitchen'
value_template: "{{ states.sensor.kitchen_motion_sensor.last_updated.strftime('%d/%m/%Y %H:%M:%S') }}"
But I guess since it does show in the frontend now and I can format the time it is OK. So Thank you.
Still having problems with the time zone because it shows UTC time and I have configured the time zone in configuration.yaml but it does nothing to these timestamps. Do I have to somehow manually add the hours to the sensors last_updated value?
Here is what is seen in frontend and in States menu:
The frontend is in correct timezone and other one is UTC but minutes are wrong and frontend keeps changing every 5 minute or so. And if I reboot the Hass.io it will show the boot time as last_updated and not the actual last_update that is in States menu.
and here is the code
kitchen_movement:
friendly_name: 'Last movement in kitchen'
value_template: "{{ as_timestamp(states.sensor.kitchen_motion_sensor.last_updated) | timestamp_custom('%d.%m %H:%M') }}"
I think I solved it by changing the timestamp that HA receives. There was āTā in the middle of date and time and it was (python) split there but I just replaced āTā with āspaceā so HA sees it as correct timestamp. And if I use ā¦attributes.last_updated it shows the correct timestamp.
I will monitor situation
EDIT: so the last_updated was like this:
2018-07-23, 09:55:01
and now it is
2018-07-23 09:55:01
EDIT2: Now it seems to be working but the time zone problem is here again and it is showing utc
This will never go away. Every time home assistant or hassio is restarted, the last_updated and last_changed objects are set to the time in which the system restarted. This cannot be avoided. You could use the SQL sensor to grab the information possibly.
You need to use the template editor to see the status. You are looking at a datetime object and the display to the user is just that, a display.
If you want to get the time to look like the last_updated, you need to use custom_timestamp on it with the correct syntax.
kitchen_movement:
friendly_name: 'Last movement in kitchen'
value_template: "{{ as_timestamp(states.sensor.kitchen_motion_sensor.last_updated) | timestamp_custom('%Y-%m-%d, %H:%M:%S') }}"
What I donāt get it is that what is the last_updated field? Isnāt the last_updated field that is seen in States menu the attribute.last_updated? If I use the attribute.last_updated and try to change the way it looks it just shows āUnknownā but if I use last_update I can change the way it looks in the GUI but it changes not only on when movement is seen but on other times alsoā¦
The changing of last_update in the frontend might have something to do with the as_timestamp() since I have two sensors and I changed one to show UTC time and other show correct time with as_timestamp() and the second one is updating itself but the one with UTC time notā¦
The Xiaomi binary_sensor on door is with as_timestamp() too but it does not change itself.
The last_updated and last_changed fields are the 'Last time the sensor changed state this current run of home assistant". These values do not persist during shutdown.
As iām looking at this, I donāt think it is. I think this is on your device only. Iāve gone through all my sensors and none of them have a last_changed attribute that shows up in the states page. This may be why we are having the confusion.
Can you please go to the template editor and place the following code into it: