Change Icon when state changes on Binary Sensor

you create a template sensor based on ‘binary_sensor.living_room_tv_status’ but I can’t see that under the ping sensors?

Hi

I tried but it just invalidates my configuration file. Hence why my file is like it is.

Not sure what I am doing wrong.

From my above file. Any chance you can type a template up, to show me for future sensors etc ?

Thanks

Martyn

well, you are building a template sensor on another sensor the doesn’t exist.

Still not got my head around this yet.

Has anyone actually got a working binary sensor that the icon changes on the status of power on and off ?

Thanks

Me here too, fallen in this rabbit hole decided to invest some time to figure out what is available.

The only home assistant only way of doing this seems to be the platform template_sensor however this has the drawback of you just adding another sensor just to have a dynamic icon, this sounds odd to me.

By using community stuff I found a few other options:

Looks like @Mariusthvdb has made a fork of unmaintained custom-ui stuff, this is quite old, I was looking at the code and seems like the js was minified and now it is formatted again. This relies on setting customization attributes that are later parsed on the UI itself by a js module.

Yet another option is the templatable lovelace card this is a row only component for the entities card, which promises to allow to change the icon.

And last, but not least is the config-template-card which seems to be one of the best options, I ended up using this now.

Are there other options?
Do somebody know why icon_template: isn’t supported on all sensors? Or at least a icon_on:, icon_off: for all binary sensors? Seems quite common specially with the mdi icon library having several version of icons with the “off” state.

In the latest version (115.x) the template binary_sensor is reported as deprecated so anyway the old template method is dead.

deprecated? the template binary_sensor? this one: https://www.home-assistant.io/integrations/binary_sensor.template/

why would you say that?

Because the only binary_sensor I have is the one with template and I get the following error:

Logger: homeassistant.components.template.binary_sensor
Source: helpers/config_validation.py:752
Integration: template (documentation, issues)
First occurred: 12:59:52 (1 occurrences)
Last logged: 12:59:52

The 'entity_id' option is deprecated, please remove it from your configuration
Home Assistant עלה!

My code is:

- platform: template
    sensors:
      sun_up:
        entity_id:
          - binary_sensor.aviry_home_rain_alarm
        value_template: >-
          {{ is_state("binary_sensor.aviry_home_rain_alarm", "on") }}
        icon_template: >-
          {% if is_state('binary_sensor.aviry_home_rain_alarm', 'on') %}
            mdi:weather-pouring
          {% else %}
            mdi:weather-sunny
          {% endif %}

That is a change mentioned in the breaking changes for 115: entity_id is no longer required for template sensors to find the states it needs to listen to.

It has never been required for your binary_sensor because it is right there in the template anyway.

So, take out the entity_id line and you will be fine

You’re sure this is the correct template to see if the sun is up :wink:

OK. Thanks. I will check.