I currently have 12+ window sensors. Each one has its own binary_sensor with device class set to window. Because I find it fairly difficult to differentiate between the default mdi window icons in their open/closed state, I have created an additional template binary sensor for each one that sets the variant window icon instead - I find these are easier to differentiate even though they don’t look like my windows in real life (well neither do the other ones, anyway!)
This means I have 24+ sensors in total - 2 for each contact.
I came across the ability to customize the icons in the homeassistant section of configuration.yaml and I can get the following code to change one of the sensors.
This will change the original sensor’s icon but it will not respond to open/close state changes - it always stays the same. I have tried adapting the icon to icon_template to include the logic that my additional template sensors have for managing the icon on state change - however this does not appear to work.
The documentation on customization only mentions icon as a customizable element so I’m assuming it cannot be done, unless anyone else knows differently?
I already have additional template sensors as a workaround. I am looking for a solution where I can just have one binary_sensor to represent my contact sensor - with icons of my choice. If it’s not possible I’ll submit a feature request (if one hasn’t been submitted already).
Thanks @apmillen yes, like you say I’ve already got that solution in place but it means I’ve got an additional binary_sensor for each contact. I was hoping it could be fixed at the customize level, but it looks like it just hasn’t been implemented yet.
A long time ago, what you want to do was achievable using a custom component called Custom UI. However, by the time version 0.110 was released, it rendered Custom UI unusable and its author was no longer willing to adapt it. @Mariusthvdb took over and helped to convert it to be compatible with 0.110+. Not all of the functionality of the original Custom UI was retained (for various reasons) but it does let you control an entity’s icon and icon color.
though easily changed using the custom-ui, I do spot an issue in the OP’s config. If you use the device_class, you shouldn’t set an icon additionally. The device_class takes care of the icon, though I haven’t tested the class window myself, I would suppose it to change according to state.
tada! Perfect, thanks @123 that’s just what I was looking for. I was using HACS but never found it in the repos until you sent me that link and then I was able to add it as a custom repo. Blimey did it take some restarting and cache emptying to fire it up, but works a treat now.
still, again, the device_class also sets an icon per state. Only use them both if you want to override that
also note that you will get some serious comments from the core HA dev’s, they don’t like the custom-ui.
Originally this was written for the per-Lovelace states interface. So be glad we can keep working what’s working for now, no promises made…
Apologies for bumping this old thread, but I thought this workaround could be useful for future readers.
In my case, I have a binary_sensor that’s device_class: presence, but it’s for a car, so the default mdi:home/mdi:home-outline icons don’t quite fit. I was trying to do this without needing custom-ui (since this is the only thing I want to customize, and don’t want to worry about the add-in compatibility).
I was able to do it by defining a new template binary_sensor which mimics the real sensor’s value, but customizes the behaviour: