Note sure if I’ve got the right terms here , but i using the Mushroom-chip-card to display if a person is home . All working fine
I have been able to include a FIXED Content badge on the chips :
using the following code:
type: custom:mushroom-chips-card
alignment: center
chips:
- type: entity
entity: person.lee
icon_color: green
name: LB
content_info: name
icon: mdi:face-man
card_mod:
style: |
ha-card:after {
content:
{%- if is_state('person.lee','home') -%}
"A"
{%- else -%}
"B"
{%- endif %};
position: absolute;
display: flex;
justify-content: center;
align-items: center;
background: rgb(var(--rgb-orange));
color: var(--card-background-color);
font-weight: bolder;
border-radius: 50%;
top: -5px;
right: -5px;
width: 18px;
height: 18px;
font-size: 11px;
}
What i would like to do is insert the time into the badge , ie “2m” or “2h” instead of the fixed text
Developed the following code to do the time and works ok in the template editor
{% set time_diff = (now()- states.person.lee.last_changed).total_seconds() | round(0) %}
{% if time_diff > 86400 %}
{{(time_diff / 86400) | int}}d
{% elif time_diff > 3600 %}
{{(time_diff / 3600) | int}}h
{% elif time_diff > 60 %}
{% else -%}
{{(time_diff / 60) | int}}m
{% endif %}
But just can not get it to work with the chip/badge .
I’m sure it’s just a special character required to insert the code
type: custom:mushroom-chips-card
alignment: center
chips:
- type: entity
entity: person.lee
icon_color: green
name: LB
content_info: name
icon: mdi:face-man
card_mod:
style: |
ha-card:after {
content:
{%- set time_diff = (now()- states.person.lee.last_changed).total_seconds() | round(0) -%}
{%- if time_diff > 86400 -%}
{{(time_diff / 86400) | int}}d
{%- elif time_diff > 3600 -%}
{{(time_diff / 3600) | int}}h
{%- elif time_diff > 60 -%}
{%- else -%}
{{(time_diff / 60) | int}}m
{%- endif %};
position: absolute;
display: flex;
justify-content: center;
align-items: center;
background: rgb(var(--rgb-orange));
color: var(--card-background-color);
font-weight: bolder;
border-radius: 50%;
top: -5px;
right: -5px;
width: 18px;
height: 18px;
font-size: 11px;
}
Thanks in advance
Lee B