I am new to Home Assistant and just trying to build the view for my likings. But my problem is the Xiaomis Door/Windows sensor. The sensor is showing in Home Assistant fine, but I am unable to get the time when states has been changed to show in HA. These can be seen from Xiaomis Mi Home APP but is there way to get this data to show in HA?
You can use the states.sensor.xiaomi_sensor_name.attributes.last_changed in a template sensor if you want to display this, or you can use custom_cards to have ti displayed automatically as Iâve done:
Check my config to help you get started if you want to go to custom UI way:
I will try the template sensor method first! So basically it should work if I follow the template sensor guide and just put the âstates.sensor.xiaomi_sensor_name.attributes.last_changedâ in it? Modified with the sensor name obviously.
For some reason it does not work. I only get it to show âClosedâ. When I click the icon open, it says there that â31 minutes agoâ but I am not able to get this information to show in the card instead or with the state âClosedâ/âOpenâ.
Any ideas how I can get the text changed to the time?
Can you format your code (check the blue bar on top of this page)
Your value template line is missing the curly braces value_template: {{states.binary_sensor.NAME.attributes.last_changed}}
I added the {{ }} but for some reason that seems to kill my installation. I tried two times and on both times I have to reformat my SD-card and start on fresh installation and restore snapshot. Might be coincidence but this has only happened when I reboot after adding the {{ }}.
Thatâs a coincidence.
Whenever you make a change in config and save, you should check your config from the front end as itâll tell you if something is wrong before you restart ha and potentially block it from starting.
Worst case scenario ha wonât start but it should not freeze your OS.
If you need to get data from any ha entity you need the curly braces.
Besides the curly braces you also need to put the entire expression in quotes. And obviously change NAME to the actually object_id of the binary_sensor youâre using. Lastly, last_changed is not under attributes:
I have sensor that has last.updated time in format â2018-07-23,08:55:39â and when I use this attribute in frontend it shows as [â2018-07-23,08:55:39â].
I would like to it be in the format 23/07/2018 08:55:39 but when I use â.strftime(â%d/%m/%Y %H:%M:%Sâ)â it changes the timestamp in frontend to âUnknownâ.
This is in template sensor. The code is:
kitchen_movement:
friendly_name: 'Last movement in kitchen'
value_template: "{{ states.sensor.kitchen_motion_sensor.attributes.last_updated }}"
but if I change it to
kitchen_movement:
friendly_name: 'Last movement in kitchen'
value_template: "{{ states.sensor.kitchen_motion_sensor.attributes.last_updated.strftime('%d/%m/%Y %H:%M:%S') }}"
it shows âUnknownâ for some reason.
The device is sensor also and it has timestamp in its attributes.
Does anyone have any idea why it does this?
EDIT: Also the time zone is wrong in the front panel, it shows everything in UTC eventhough I have configurated time_zone in homeassistant: