I’d like to add an icon to a sensor. The sensor is configured in a templates.yaml file. I’ve tried using ‘icon_template:’ without achieving the desired result. No icon appears on the entity. My templates.yaml file follows. The sensor I wish to add the icon to in near the end of the file. The name of the sensor is “Rain in next 48 hours”.
###################################################
# "Outdoor Temperature Feels Like" Configuration #
###################################################
- sensor:
- name: "Feels Like"
device_class: temperature
unit_of_measurement: "°C"
state: >
{% if not is_state('sensor.stratford_humidex', 'unknown') %}
{{ states('sensor.stratford_humidex') }}
{% elif not is_state('sensor.stratford_wind_chill', 'unknown') %}
{{ states('sensor.stratford_wind_chill') }}
{% else %}
{{ states('sensor.stratford_temperature') | round(0) }}
{% endif %}
#####################################
# "Rain in 48 Hours" Configuration #
#####################################
- name: "Rain in next 48 hours"
state: >
value_template: >-
{% set p0 = state_attr('weather.stratford', 'forecast')[0].condition == "rainy" %}
{% set p1 = state_attr('weather.stratford', 'forecast')[1].condition == "rainy" %}
{{ 'Yes' if p0 or p1 else 'No' }}
icon_template: {{'mdi:weather-rainy'}}
Ah, I see. That’s quite an old post, and the preferred template sensor format has changed since then. You were trying to shoehorn old format configuration into a new format sensor.
That sort of mix-up one of the “tells” for ChatGPT, as its training corpus is quite old and it has no actual intelligence on the two different approaches. My apologies for suggesting your own intelligence might be artificial .