Hi everyone, I’ve been exploring how to enhance my Home Assistant setup, and I came across a neat challenge that I wanted to share and get feedback on. I’ve been using a custom mushroom-template-card for a simple open/closed sensor, and while it works well, I wanted to add a ‘last changed’ feature that displays how long ago the state was updated, rather than just showing the absolute time.
Initially, I found a one-liner that gave me the exact time of the last change, but I was hoping for something a bit more dynamic, like ‘x minutes ago’ or ‘y hours ago’. I did some digging in the community and found that using template cards was the way to go, especially since I wanted to keep the battery badge icon functionality intact.
Here’s what I came up with:
yaml
{{ as_timestamp(states.binary_sensor.front_door.last_changed, default=0)|timestamp_custom(‘%d.%m.%Y %H:%M’, default=0) }}
This gives me the exact time, but I was curious if there was a way to make it more user-friendly. I stumbled upon some suggestions about using relative time formatting, which would be perfect for my needs. I tried a few different approaches, but I kept running into issues with the syntax and ensuring the badge icons still worked as intended.
I’d love to hear if anyone has tackled this before or has any tips on how to achieve this relative time display while keeping the rest of the card functionality intact. It would be a great addition to my setup, and I’m sure others might find it useful too! Thanks in advance for any insights or suggestions you might have.