Hi all,
I’m trying to figure out the right syntax for a template sensor for which the icon changes depending on the value of another sensor.
For my central heating custom button card, I defined a template sensor for the CH Pump which changes icon based on the power consumption of the pump. If power consumption of the pump is below 10 Watt, the pump is assumed to be off, so the icon should change to the off state.
That’ll never go unavailable because you’re using a default of zero. It will always show off in that case.
{% set power = states('sensor.ch_pump_power')|float(none) %}
{% if power is not none %}
mdi:toggle-switch{{ '-off' if power <= 10 else '' }}-outline
{% else %}
mdi:exclamation-thick
{% endif %}
Right, which will put it in the off icon when it should be hitting the ! Icon. Because it fails to convert and places the result as zero, which will hit the less than or equal to 10.