Basically think of the fact that the .: | should start at the same place you would place any other entry under style: see how in my example the mushroom-shape-icon$: | and the .: | start at the same indentation?
I’m no guru, but I was looking for this a few days ago to show when a door was opened/closed. I’m not sure if it’s what you’re looking for, but I put…
{% if is_state(config.entity, 'off') %}
Closed {{ relative_time(states.binary_sensor.basement_door_state.last_changed) }} ago
{%else%}
Opened {{ relative_time(states.binary_sensor.basement_door_state.last_changed) }} ago
{%endif%}
What you have both posted works just fine but isnt super accurate. For example i have a sensor that states last changed 2 days 1 hour 55m ago. With you templates it only gives me 2 days ago.
I prefer the below. While it is long it also gives better accuracy. But of course to each their own
{%- set time = (as_timestamp(now()) - as_timestamp(states.binary_sensor.bedroom_wardrobe_right_contact.last_changed)) | int %}
{%- set minutes = ((time % 3600) // 60) %}
{%- set minutes = '{}m'.format(minutes) if minutes > 0 else '' %}
{%- set hours = ((time % 86400) // 3600) %}
{%- set hours = '{}h '.format(hours) if hours > 0 else '' %}
{%- set days = (time // 86400) %}
{%- set days = '{}d '.format(days) if days > 0 else '' %}
{{ 'Less than 1 min' if time < 60 else days + hours + minutes }}
You can then define however you want to call the days hours minutes. Right now it just does 2d 1h 55m.
Thank you! This would come in handy in the future! Indeed, mine isn’t super accurate, but it’s good enough for my specific usecase (the state changes at least once a day).
I want to remove the circular background behind the fluorescent tubelight icon. The chip where it toggles on and off should have a background as it does. I am happy with the text positioning also underneath. However, the icon should stand in a transparent background or if you have a better aesthetic suggestion. Also, if i can color the skin the same as the box shadow around the box when the light is turned on.
Unable to take out the background of the icon so far.