Can someone help me out with this code please?
I wan’t to change the valve icon depending on the item state.
The if works for the other icon called heater but it does not work when I try to change the icon of the valve.
it looks like this:
and
but the question mark should be replaced by the valve icons.
type: custom:button-card
entity: switch.ak_ventil_fb
icon: mdi:hanger
aspect_ratio: 1/1
name: Ankleide
state:
- value: off
color: var(--paper-item-icon-color)
- value: on
color: var(--primary-color)
styles:
name:
- padding-bottom: 18px
card:
- background-color: /*#002000*/
grid:
- position: relative
custom_fields:
heater:
- color: |
[[[
if (states['switch.ak_ventil_fb'].state == 'on')
return "red";
return "grey";
]]]
- position: absolute
- left: 60%
- top: 10%
- height: 40px
- width: 40px
valve:
- color: grey
- position: absolute
- left: 64%
- top: 45%
- height: 30px
- width: 30px
- icon: |
[[[
if (states['switch.ak_ventil_fb'].state == 'on')
return "mdi:valve-open";
return "mdi:valve-closed";
]]]
- color: |
[[[
if (states['switch.ak_ventil_fb'].state == 'on')
return "red";
return "grey";
]]]
custom_fields:
heater: |
[[[
return `<ha-icon
icon="mdi:heating-coil"
style="width: 40px; height: 40px; /*color: grey;*/">
</ha-icon>`
]]]
valve: |
[[[
return `<ha-icon
icon="mdi:help"
</ha-icon>`
]]]
Thanks!