I am reading the status of my door contacts via Mqtt.
They are definid in the yaml file and they are 0 or 1 (magnet closed or magnet open
I would like the icon in the heading card to change based on this value.
I tried several things i found on the forum (with if statements), but nothing seems to work.
Can this be done without changing the yaml file for all the sensors?
Changing an icon conditionally may be done by card-mod.
Go to main card-mod thread → 1st post → link at the bottom titled “fantastic” → heading card → changing icon
Thanks for your pointer, however i cannot get it working. Could you show me what i’m doing wrong?
my code is
type: heading
heading: Living
heading_style: subtitle
icon: mdi:sofa-outline
badges:
- type: entity
entity: sensor.28_8b0284030000_temperatuur
- type: entity
show_state: true
show_icon: true
entity: sensor.status_livingschuif
card_mod:
style: |
.badges hui-heading-badge:nth-child(2) hui-entity-heading-badge {
{% if states('sensor.status_livingschuif') != '0' %}
--card-mod-icon: phu:sliding-window-door-open
{% else %}
--card-mod-icon: phu:sliding-window-door-close
}
You are trying to use card-mod on an “entity level” - but you must use it on a “card level”, check an example provided on that link.
i saw the difference, thanks.
However, the if statement does not work? if i remove the if and just use
card_mod:
style: |
.badges hui-heading-badge:nth-child(2) hui-entity-heading-badge {
--card-mod-icon: phu:sliding-window-door-close
}
that works, but the code below does not?
type: heading
heading: Living
heading_style: subtitle
icon: mdi:sofa-outline
badges:
- type: entity
entity: sensor.28_8b0284030000_temperatuur
- type: entity
show_state: true
show_icon: true
entity: sensor.status_livingschuif
card_mod:
style: |
.badges hui-heading-badge:nth-child(2) hui-entity-heading-badge {
{% if states('sensor.status_livingschuif') == '0' %}
--card-mod-icon: phu:sliding-window-door-close
{% else %}
--card-mod-icon: phu:sliding-window-door-open
}
{% endif %} ?