Looking to see if there is a better way to do the following. I have a template sensor that keeps count of the number of lights on in the house. Based on that number, I am updating the icon on my dashboard. The below works in an entity card, but was wondering if there was a better way.
{% if is_state(“sensor.total_lights_count_template”, “0”) %}
mdi:numeric-0-box
{% elif is_state(“sensor.total_lights_count_template”, “1”) %}
mdi:numeric-1-box
{% elif is_state(“sensor.total_lights_count_template”, “2”) %}
mdi:numeric-2-box
{% elif is_state(“sensor.total_lights_count_template”, “3”) %}
mdi:numeric-3-box
{% elif is_state(“sensor.total_lights_count_template”, “4”) %}
mdi:numeric-4-box
{% elif is_state(“sensor.total_lights_count_template”, “5”) %}
mdi:numeric-5-box
{% elif is_state(“sensor.total_lights_count_template”, “6”) %}
mdi:numeric-6-box
{% elif is_state(“sensor.total_lights_count_template”, “7”) %}
mdi:numeric-7-box
{% elif is_state(“sensor.total_lights_count_template”, “8”) %}
mdi:numeric-8-box
{% elif is_state(“sensor.total_lights_count_template”, “9”) %}
mdi:numeric-9-box
{% elif is_state(“sensor.total_lights_count_template”, “10”) %}
mdi:numeric-10-box
{% endif %}
pedolsky
(Pedolsky)
November 27, 2023, 11:10pm
2
Welcome to the community forums!
icon: mdi:numeric-{{ states('sensor.your_sensor') if states('sensor.your_snsor')|int(0) < 9 else '9-plus' }}
1 Like
@pedolsky Perfect. Thank you. Worked exactly as needed.