Sensor Template For Door Icon (Open / Closed) to be yellow when open?

Evening All,

I’ve got my lovely Xiaomi door sensor integrated into my HASSIO frontend with the following:

- platform: template
  sensors:
    front_door:
      friendly_name: "Front Door"
      value_template: >-
        {% if is_state('binary_sensor.door_window_sensor_158d0001f49c83', 'on') %}
          Open
        {% else %}
          Closed
        {% endif %}
      icon_template: >
        {% if is_state('binary_sensor.door_window_sensor_158d0001f49c83', 'on') %}
          mdi:door-open
        {% else %}
          mdi:door-closed
        {% endif %}

Is there any way to make the mdi:door-closed yellow ala the light switches? Would just be a quicker way to see if a door is open. If you could point me in the right direction it would be appreciated, thanks.

1 Like

See here - Custom UI - icon color change

Right so in theory I could do something like (stealing from your link here):

sensor.front_door:
  templates:
    rgb_color: "if (state === 'open') return [200, 100, 30]; else return [10, 20, 30];"

Will give it a try.

Edit: Didn’t seem to work, lets have another read.

Did you get around to getting this resolved? Looking to do a very similar thing.

Yeah custom UI wasn’t even needed. I ended up using “device_class: door” in my customize.yaml and it did the trick.

1 Like