For a mushroom card I want create a if template so icon color will change. This must change for a temperature sensor. But not how example is shown. But if sensor is in between -10 and -5, -5 and 0, etc
The last one must be 40 or more.
{% if is_state('sensor.temperature', '-10') %}
dark blue
{% elif is_state('sensor.temperature', '-5') %}
blue
{% elif is_state('sensor.temperature', '0') %}
light blue
{% elif is_state('sensor.temperature', '5') %}
light green
{% elif is_state('sensor.temperature', '10') %}
green
{% elif is_state('sensor.temperature', '15') %}
dark green
{% elif is_state('sensor.temperature', '20') %}
orange
{% elif is_state('sensor.temperature', '25') %}
light red
{% elif is_state('sensor.temperature', '30') %}
red
{% elif is_state('sensor.temperature', '35') %}
dark red
{% elif is_state('sensor.temperature', '40') %}
purple
{% endif %}
Ohh yes. This is an other way to do. Was forgotten this one. haha Thanks!!!
Look like this is a sensor part. Are you use the sensor into a template in UI so no lots of code goes into the UI Lovelace code?
exactly…
I use custom_ui to set colors on icons. this way I only have to create that template once, and next, use the sensor name in the frontend config.
in js this would be:
homeassistant:
# create some node_anchors
node.anchors:
temp_color: &temp_color
hide_attributes: templates
templates:
icon_color: >
if (state === 'unknown') return 'grey';
if (state < -20) return 'black';
if (state < -15) return 'navy';
if (state < -10) return 'darkblue';
if (state < -5) return 'mediumblue';
if (state < 0) return 'blue';
if (state < 5) return 'dodgerblue';
if (state < 10) return 'lightblue';
if (state < 15) return 'turquoise';
if (state < 20) return 'lightgreen';
if (state < 25) return 'darkgreen';
if (state < 30) return 'orange';
if (state < 35) return 'crimson';
return 'firebrick';
customize_glob:
# and use that node_anchor ;-)
sensor.*temperature: *temp_color
Seems nice… Will check it. Have also some custom ui stuff. Funny that ‘navy’ and ‘crimson’ gives me black icon. Or something with latest HA issue maybe. Have to check