after you do this, you probably won’t need an icon template because it will handle the icon for you.
@Mutt Icon_templates are only available on specific integrations and that list is extremely limited. Personally, I don’t offer this as a solution anymore because of those reasons.
I was also looking into changing the icon for a few of my door/window sensors. I really thought I understood how this works by reading this topic through, plus the “Template Binary Sensor” page and partly the big “Templating” page.
I started with just overwriting one sensors icon based in it’s state, but I keep getting a new entity with the name of my template binary sensor. And this new entity works and changes its icon based on the actual sensors state… But I can’t get it to work, that the actual sensor gets its icon changed in the frontend:
binary_sensor:
- platform: template
sensors:
living_room_door_on_off_icon:
entity_id:
- binary_sensor.living_room_door_on_off
# Note that 'value_template' is required. I have to add it, but I only want to change the icon...
value_template: "{{ is_state('binary_sensor.living_room_door_on_off','on') }}"
icon_template: >-
{% if is_state("binary_sensor.living_room_door_on_off", "on") %}
mdi:door-open
{% else %}
mdi:door-closed
{% endif %}
I’ve also tried to name the template binary sensor exactly like the actual sensor, but that gives me the same result, just that it’s named living_room_door_on_off_2…
Did I still understood that wrong? Will this never change the actual sensors icon in the frontend by itself, but just gives me another entity that I could use if I would do custom dashboards or something?
Or doesn’t it work, because my sensor is actually not added through the “binary_sensor” integration, but ZHA!?
You already have a binary sensor with on/off states. Delete your binary_sensor template you have there, and instead use the customize config to change the device class to door… like this in your configuration.yaml:
customize:
binary_sensor.living_room_door_on_off:
device_class: door
Much simpler… now restart HA and should be done. The door class will make use of those neat opened and closed door mdi’s (note not all lovelace cards display icon changes… verify the icons are working right using glances or dev/states). Here’s more binary_sensor classes that you may want to be familiar with:
On a side note to help clear some confusion… yes it is likely the ZHA integration went ahead and added in all the necessary entities for you when you set it up. Hence why you magically had the binary_sensor in your dashboard. It does that by default (see the zha integration switch for “adding newly discovered entities”… it’s on by default). So with the above customize: config, you are just telling HA that it should refer to that sensor as a door rather than a generic binary_sensor with an ugly/boring square.
Thank you so much! That’s the solution for my problem I didn’t understand yet, that the device class is “just” used for representation in the frontend. I thought it has some more, deeper usage and I didn’t want to play around with the device class of an entity, not wanting to risk to break something
But still, just so I know / understand the templating thing I did there:
Is the outcome of what I did there (the 2nd binary sensor) the expected outcome? Or is that just here in my setup where the entity I tried to change is not actually a raw binary sensor entity?
Interesting… To be fair, according to what the config looks like, it totally makes sense, as it configures a binary sensor with the platform “template”… Still interesting concept, that you can’t affect the sensor itself but need to use this template sensor instead if you want your icona… So really only helpful if you have custom UI/dashboards, I guess. Tbf, probably 90% of all HA users have tbem, but I am not even two weeks into HA, so I still stick with the default UI and dashboard
Thanks! I got it to where it isn’t causing a configuration error. My original purpose was to get my door icons to show open icon and closed icon. That didn’t work they are still the same so I will continue to research.
Because I unintentionally mixed two things: the highlighting of an icon (something that wasn’t consistently working in all places before) vs changing the icon itself to indicate the state. How about you explain @waank1’s issue then instead of only so smartly pointing out my error.
customize:
binary_sensor.open_close_sensor_25_be_7e:
device_class: door
Newest development: I have these lines in my Config.yaml No errors, I have tried it with several entities but the icon doesn’t change. Somehow the device class has no effect whether I do in in yaml or if I do it in the entity in the UI.
can you confirm to have that in configuration.yaml like that?
also, please answer the other questions for us to be able to help you at all. We need to understand which integration creates this binary sensor. Is it zwave? is it a template binary etc etc.
and also a sceenshotof the sensor in dev tools states