Customize state icons without having to create additional template sensors

It seems like a lot of people are creating additional template binary sensors just to be able to change the default icons. For example when I add a new window contact, the entity that gets created has the mdi:window-open and mdi:window-closed. I personally find it quite hard to differentiate between these two icons so I would like to use mdi:window-open-variant and mdi:window-closed-variant instead. This is just an example case, there are lots of others in the forums.

The current offered solution is to create template sensors and define different icons inside an icon_template based on different states. Whilst this achieves the desired result, it consequently means that I now have 2 binary sensors for the same device. When you’ve got umpteen contacts all over your house, maintaining this code can get tedious, not to mention the performance impact its probably having on HA with twice as many sensors.

It seems the logical place to do this would be in the customize section of homeassistant in configuration.yaml. This is where you would override the entity name, device class etc., for example.

      friendly_name: "Bathroom Window"
      device_class: window
      icon: mdi:window-open-variant

However whilst you can specify an icon here, it does not respond to state changes, e.g. on or off.

My suggestion therefore is to extend the functionality of the icon in here so that it responds to state changes. Something that would allow me to say use this icon when on and this icon when off.

This will save everyone from creating additional template sensors when all they are wanting to do is change an icon.

What if you go to:

Configuration --> customization to change the icon:

Don’t forget to set the color option in lovelace:
e.g. entities card configuration:

Thanks but it just looks like the UI is just an alternative to the yaml I have provided - and essentially does the same thing. With this UI editor you can only modify the icon as you can in yaml - it looks like the functionality for customizing icons based on state has not yet been implemented.

Not sure what you mean…

e.g. a lock has lock can have an open and lock closed icon for open and close…?

Yes any binary sensor has just two options. The current problem is that you have to accept the default icons that the developers have programmed and there is no way to use your own icons unless you create an additional template sensor or use custom component.

Yes that is correct.

In that case, do not forget to vote your own feature request.

:laughing: :rofl: Thanks @sender, yes I will!!

While you’re at it, the ability to define icon colour in a template would be good - red for window open icon, green for closed, etc.

you know you can do all of that and more using custom-ui? We’ve been talking for years about adding the templating options to core HA customization and the re-addition of icon_color, but the main dev’s simply don’t want it.

Custom-ui is from HA using the states front-end, but we’ve been able to keep it working up to now.

Using the icon_color, or the adapted icons, even glob that for the domain if you so desire is a breeze.