Simple switch with changing icon

Hi together,

is it possible to create a simple switch in HA with changing icons based on the state?

Finally I would like to display the switch in a simple button card which changes the icon when pressing the button. I thought about using a template switch like this:

- platform: template
    kitchen_music_on:
      # value_template: "{{ states('switch.mute_kitchen') }}"
      turn_on:
        service: switch.turn_on
        target:
          entity_id: switch.kitchen_music_on
      turn_off:
        service: switch.turn_off
        target:
          entity_id: switch.kitchen_music_on
      icon_template: >-
        {% if is_state('switch.kitchen_music_on', 'on') %}
        mdi:volume-high
        {% else %}
        mdi:volume-off
        {% endif %}

This doesn’t work … or only works once I pressed the button in lovelace. Using template switch looks a bit like shooting sparrows with cannons and it does not feel right as written above. Anyone has a simple solution?

PS: I wanted to avoid custom cards.

red

It is, but this entire switch is circular. It references itself, so the entire thing iwll not work. You’d need to pair this with an input_boolean and use that as the turn_on and turn_off entity as well as the value_template and icon_template.

Hi @petro,

Yes, I also saw this circular, but did not have any other idea :thinking:.
I feared it ! I thought I could avoid one more entity.

Finally, I used the additional input_boolean as you recommended and now it works. :slight_smile:. Thanks for the quick feedback!

Thanks, red