Colors icon with condition

Hi everybody !

I 'm looking for a moment on the forum but I don’t found answer…

I would like to change the color of my icons.

For example : 

   IF Temperature_bedroom > 23°C
     mdi:thermometer -> Red
   ELSE
     mdi:thermometer -> Green

Somebody knows how to do ?

Thank you !!!

You could copy it locally (to your www dir) and colour them in renaming them thermometerRed/Green

And probably others, but I’ll leave you to use the search function :wink:

I tried something :

  - platform: template
    sensors:
      temperature_salon:
        friendly_name: "Température"
        unit_of_measurement: "°C"
        value_template: >-
          {%- if states.sensor.netatmo_salon_temperature.state %}
            {{ states.sensor.netatmo_salon_temperature.state }}
          {% else %}
            {{ states.sensor.netatmo_salon_temperature.state }}
          {%- endif %}
        icon_template: >-
          {%- if is_state("sensor.netatmo_salon_temperature", "unknown") %}
            mdi:thermometer
          {% elif states('sensor.temperature_salon') | float >= 19 %}
            entity_picture: /home/homeassistant/.homeassistant/www/thermometre_vert.svg
          {% elif states('sensor.temperature_salon') | float >= 21,7 %}
            entity_picture: /home/homeassistant/.homeassistant/www/thermometre_orange.svg
          {% elif states('sensor.temperature_salon') | float >= 24 %}
            entity_picture: /home/homeassistant/.homeassistant/www/thermometre_rouge.svg
          {% else %}
            entity_picture: /home/homeassistant/.homeassistant/www/thermometre_bleu.svg
          {% endif %}

My sensor’s values are corrects, but icons don’t appears…
Do you have an idea ?

Thank you !

Use

/local/thermometre_vert.svg

instead of

/home/homeassistant/.homeassistant/www/thermometre_vert.svg

I always have an empty space, and not my icons… :persevere:

  - platform: template
    sensors:
      humidite_salon:
        friendly_name: "Humidité"
        unit_of_measurement: "%"
        value_template: >-
          {%- if states.sensor.netatmo_salon_humidity.state %}
            {{ states.sensor.netatmo_salon_humidity.state | round }}
          {% else %}
            {{ states.sensor.netatmo_salon_humidity.state }}
          {%- endif %}
        icon_template: >-
          {%- if is_state("sensor.netatmo_salon_humidity", "unknown") %}
            mdi:humidity
          {% elif states('sensor.humidite_salon') | int >= 30 %}
            entity_picture: /local/humidite_orange.svg
          {% elif states('sensor.humidite_salon') | int >= 40 %}
            entity_picture: /local/humidite_vert.svg
          {% elif states('sensor.humidite_salon') | int >= 60 %}
            entity_picture: /local/humidite_orange.svg
          {% elif states('sensor.humidite_salon') | int >= 70 %}
            entity_picture: /local/humidite_rouge.svg
          {% else %}
            entity_picture: /local/humidite_rouge.svg
          {% endif %}

Do I need to install this ?

I don’t think you can do that .svg’s are not icons, however it looks like you can colour the mdi icons with the custom ui :slight_smile:

Hi !
Thank for your answers !
I finally not found a solution to colorized my icons… maybe later !!

Today is the day :slight_smile: