I want to create a table that will show my binary sensors and the last time they tripped in a relative time.
For example, I want the table to show:
Sensor 1, 10 minutes ago
Sensor 2, 4 hours 10 minutes ago
Sensor 3, 6 days ago
On the binary sensors, the data that is logged is “last_tripped_time” which shows the number of seconds ago that the sensor was tripped. How can I use that data to populate a table like I mention above? I believe I can use the relative_time function, but documentation on that seems limited or I simply can’t find it.
Replace upstairs_temperature with your sensor name
Note: this works for me as I’m in British Summer Time timezone (I had to subtract 1 to days and hours). You may need to adjust for your toimezone
You need to “install” Custom-UI first: copy files: state-card-custom-ui.html, state-card-custom-ui-es5.html and state-card-custom-ui.html.gz to folder /config/www/custom_ui/
Now, it looks like the show_last_changed function resets every time that I restart HA. Is there any way that it can use the data from the binary_sensor itself?
For example, it shows here 33 min ago, which was the last time I restarted HA.
But that door hasn’t been opened in 3 days, based on the last_tripped_time
Any way to have it reference last tripped time field for the last_changed in custom ui?
The code might look a bit complicated, but all it is doing is iterating through all my zwave devices, and calculating the time. You could easily put that into a script or automation.