Template Sensor icon is not displayed / Binary Template Sensor icon is not updating

Hello,

I don’t understand why my template sensor icon is not being display if it’s outside of a group. This my sensor:

rain:
  value_template: '{% if states.sensor.weather_precip_probability.state | int > 50 %}Regen{% else %}Sonne{% endif %}'
  icon_template: '{% if states.sensor.weather_precip_probability.state |  int > 50 %}mdi:weather-rainy{% else %}mdi:weather-sunny{% endif %}'
  entity_id:
    - sensor.weather_precip_probability
  unit_of_measurement: Wetter

If I add the sensor to my default view the icon is not display. If I click on it the card shows the icon. If I add the sensor to a group the icon is displayed.

Bug or expected behaviour? Did I miss the option to display the icon instead of the status?

In addition to that I have a similar problem with Binary Template Sensors:

It’s not highlighted in yellow outside of a group:

image

If I click on it, the card is highlightedin yellow:

and like in my issue with the Template Sensor it’s displayed correctly in a group.

Thanks, Thomas

I am wondering the same thing. Was hoping to create a template sensor to display an icon with the icon template of the scene I’m currently using.

Looks like it’s not possible. From the template sensor component page it says the following:

The Binary template sensor is the one in similar cases if you prefer to see an icon instead of text.

@Jer78 - But it’s working if you use the sensor in a group instead of a badge on the top of the page, so I think it’s working basically, but not as a badge.

Yes, it’s working. But it would be nice to switch to an icon over the text for certain things. I will add as a feature request.

Agreed, I’d like to see another variable in the template sensor config that allows you to select icon or text as the default to go in the bubble.

By the way - I solved that with Andreys custom-ui: https://github.com/andrey-git/home-assistant-custom-ui

Hi,

I’m in the same situation where my dynamic icon don’t display in a badge, i have tried different combinations using custom-ui, badgelists, individual badges… Could you help me out by pasting your config for me?

Thanks!

I’m using custom-ui like that:

binary_sensor.bedroom_climate_windowshutter:
  icon: mdi:glassdoor
  friendly_name: Schlafzimmerfenster
  group:
    group.bedroom:
      friendly_name: Fenster
      templates:
        theme: if (entities['binary_sensor.bedroom_climate_windowshutter'].state === 'on') return 'active';
        friendly_name: if (entities['binary_sensor.bedroom_climate_windowshutter'].state === 'on') return 'Seit ' + (entities['sensor.bedroom_climate_windowshutter_openingtime'].state) + ' Minuten geöffnet'; else return 'Fenster';
  state_card_mode: badges

With templates: you can also set a icon instead of a friendly_name like in my example.