Icon Template won't change the Icon

I needed eyes on this.
Been P—ing me off for a day now.
The sensor flips correctly, but the icon won’t change.
I waited until today when the dryer would cycle to check it again, and everything worked fine except the icon does not change to off when the sensor turns off.

It may or may not be obvious but this is in the template / binary_sensor ‘domain’


    #####################################################
    # Dryer State                                       #
    #####################################################
    - name: "Dryer Running"
      unique_id: 4105191d-d7b4-4e60-1142-715847353f33
      state: >-
        {# Flip sensor for better visual state. #}
        {% set dr_st = is_state('binary_sensor.dryer', 'off') %}
        {% if dr_st %}
          true
        {% else %}
          false
        {%- endif %}
      delay_off:
        minutes: 1
      availability: >-
        {% from 'availability_template.jinja' import avail %}
        {{- avail(['binary_sensor.dryer']) | bool -}}
      attributes:
        friendly_name: "Dryer Running"
      icon: >-
        {# Flip sensor for better visual state. #}
        {% set dr_st = is_state('binary_sensor.dryer', 'off') %}
        {% if dr_st %}
          mdi:tumble-dryer
        {% elif not dr_st %}
          mdi:tumble-dryer-off
        {% else %}
          mdi:tumble-dryer-alert
        {% endif %}

I do similar with the washer, different, but the same is and it all works fine…


    #####################################################
    # Washer State                                      #
    #####################################################
    - name: "Washer Running"
      unique_id: a735192a-271a-4c27-83ea-c25d342652b2
      state: >-
        {# Set the variable. #}
        {% set wm_amps = states('sensor.wash_machine_energy_current') | float(0.07) %}
        {# Create a dead zone to prevent oscillations. #}
        {%- if wm_amps > 0.16 %}
          true
        {%- elif wm_amps < 0.077 %}
          false
        {%- else %}
          {{ states('binary_sensor.washer_running') }}
        {%- endif %}
      delay_off:
        minutes: 5
      auto_off:
        hours: 1.5
      availability: >-
        {% from 'availability_template.jinja' import avail %}
        {{- avail(['sensor.wash_machine_energy_current']) | bool -}}
      attributes:
        friendly_name: "Washer Running"
      icon: |
        {# Set the variable. #}
        {% set wm_amps = states('sensor.wash_machine_energy_current') | float(0.07) %}
        {# Set the icon #}
        {%- if wm_amps > 0.16 %}
          mdi:washing-machine
        {%- elif wm_amps < 0.077 %}
          mdi:washing-machine-off
        {%- else %}
          mdi:washing-machine-alert
        {%- endif %}

image
But even when off the Dryer has the same icon.
image
And with the washer running normal
image

That is happening in sections view?

Maybe in appearance, show entity picture is disabled?

type: tile
entity: sensor.pixel_aas_battery_state
show_entity_picture: true
vertical: false
hide_state: false
state_content:
  - last_changed
  - state

Don’t use sections at all.
The washer one changes correctly in the same panel. It’s in the template binary_sensor somewhere.
There is no code anywhere else. Just a stock entities panel.

this would never move to alert, because the not will always catch it?

why not change to

        {% set dr_st = states('binary_sensor.dryer') %}
        {% if dr_st == 'on' %} mdi:tumble-dryer
        {% elif dr_st  == 'off' %} mdi:tumble-dryer-off
        {% else %} mdi:tumble-dryer-alert
        {% endif %}

I’ll try it…

The binary_sensor.dryer is actually reverse state of this sensor, so I had to switch on and off, but it didn’t change anything.

      icon: >-
        {# Flip sensor for better visual state. #}
        {% set dr_st = states('binary_sensor.dryer') %}
        {% if dr_st == 'off' %} mdi:tumble-dryer
        {% elif dr_st  == 'on' %} mdi:tumble-dryer-off
        {% else %} mdi:tumble-dryer-alert
        {% endif %}

And I did do an HA update on the sensor and reloaded templates. I mean you can see the other sensor is right because the thing states off, which is correct. Just the icon /icon template that isn’t changing. The icon template reports right in developer-templates. Fing weird…

Is doing a set in an icon template a problem? I think I tried long-handind it as well though, don’t remember.

No not at all.
Your issue would be something else