Change color icon in sensor.yaml

Hello,

I would like to make a change, it is to be able to put the icon of the door in green when it is closed and put in red when the door is open. I can’t add in my sensor configure in > sensor.yaml <

Can you help me?

  • platform: template
    sensors:
    porte_salle_a_manger:
    friendly_name: Porte Salle à Manger
    value_template: >
    {% if is_state(‘sensor.aeotec_zwave_porte_salle_a_manger_access_control’, ‘23’) %}
    Off
    {% elif is_state(‘sensor.aeotec_zwave_porte_salle_a_manger_access_control’, ‘22’) %}
    On
    {% else %}
    Off
    {% endif %}
    icon_template: >
    {% if is_state(‘sensor.aeotec_zwave_porte_salon_access_control’, ‘23’) %}
    mdi:door
    {% elif is_state(‘sensor.aeotec_zwave_porte_salon_access_control’, ‘22’) %}
    mdi:door-open
    {% else %}
    mdi:door
    {% endif %}

The color can only be changed in the UI section. It requires a custom lovelace card: lovelace card mod.

@SebRom77 You can also do the same thing (in a slightly different way) by making your own images…

      ssfilt_hi_lvl:
        entity_picture_template: >-
          {% if is_state('binary_sensor.slow_sand_filter_hi_lvl', 'on') %}
            /local/images/lowLevel.png
          {% else %}
            /local/images/HIHILevel.png
          {% endif %} 
        friendly_name: Slow Sand Filter HI LVL
        value_template: "{{ is_state('binary_sensor.slow_sand_filter_hi_lvl', 'on') }}"

Great thanks, I hadn’t thought of it.

also look at custom-ui - https://github.com/andrey-git/home-assistant-custom-ui

then you can do things like this in customize.yaml:

binary_sensor.door_window_sensor_158d0001c0ff73:
  device_class: door
  templates:
    icon_color: if (state === 'on') return 'red'; else if (state === 'off') return
      'green'; else return 'blue';