Lovelace card icons (on/off) not changing

So I am using yaml based UI and have the following in my <config>/ui-lovelace.yaml

resources:
  - url: /local/simple-thermostat.js?v=1
    type: module
title: KEATS
views:
    cards:
      - type: vertical-stack
        title: HW & CH
        cards:
          - type: entities
            entities:
              - entity: switch.danfoss_rxz3_rf_relay_switching_unit_switch
                name: Hot water
                icon: mdi:water
                state-color: true
              - entity: switch.danfoss_rxz3_rf_relay_switching_unit_switch_2
                name: Central heating
                icon: mdi:radiator
                state-color: true

which correctly gives me:
Capture

But when I slide the on/off button, the icons do not change.
I expect , for water , to use the mdi:water icon and change the icon for on/off states using
mdi:water-on and mdi:water-off ??

What have I done wrong please - obviously probably not understanding icon and entity relationships??

If Homeassistant knows what device_class your sensor belongs to it will figure out what icons to use for the on/off state i.e. motion sensors. Just giving an icon doesn’t help homeassistant here, you have to be more specific and create a new template sensor that specifies an icon_template for the on and off state. (No guarantee the syntax is correct)

sensor:
  - platform: template
    sensors:
      water:
        entity_id: switch.danfoss_rxz3_rf_relay_switching_unit_switch
        friendly_name: Hot Water
        icon_template: >
          {% if is_state('switch.danfoss_rxz3_rf_relay_switching_unit_switch',  'on') %}
            mdi:water-on
            {% else %}
              mdi:water-off
            {% endif %}

Then use your new sensor.water in your card

Ah, I see. I understand your code - thanks - but alas it may not be that simple…can I just check with you please…

I have a Z-Wave Danfoss RX2 controller which HA has discovered as a device, and has auto-created entities for it, including switch.danfoss_rxz3_rf_relay_switching_unit_switch as a binary_sensor class.
So do I need to “overwrite” some of the So do I need to “overwrite” attributes of this switch, perhaps like this?..:

Just wanted to check before I go off and try myself.

EDIT:

Scratch the above. I understand now. Didn’t realise the template was creating a new entity called water.

Also

I had to tweak the code - granted you provided unverified code:

ui-lovelace.yaml

      - type: vertical-stack
        title: HW & CH
        cards:
          - type: entities
            entities:
                # templating for switch.danfoss_rxz3_rf_relay_switching_unit_switch
              - entity: switch.water
                name: Hot water
                state_color: true
              - entity: switch.danfoss_rxz3_rf_relay_switching_unit_switch_2
                name: Central heating
                state_color: true

configuration.yaml

  switch:
    - platform: template
      switches:
        water:
          friendly_name: Hot water
          value_template: "{{ is_state('switch.danfoss_rxz3_rf_relay_switching_unit_switch', 'on') }}"
          turn_on:
            service: switch.turn_on
            data:
              entity_id: switch.danfoss_rxz3_rf_relay_switching_unit_switch
          turn_off:
            service: switch.turn_off
            data:
              entity_id: switch.danfoss_rxz3_rf_relay_switching_unit_switch
          icon_template: >
            {% if is_state('switch.danfoss_rxz3_rf_relay_switching_unit_switch',  'on') %}
              mdi:water
            {% else %}
              mdi:water-off
            {% endif %}

Had to move from sensor to switch to get the desired UI.

But , why does the color of the water drop turn yellow when on? Can this be changed, to say red/orange? Other than this, working perfectly - so big thank you.

Glad you got it to work even with my minimal help. As for the color, maybe this helps: Change Icon Color Binary_Sensor

It does help cheers.

BTW, your minimal help may have been so, but essential nevertheless :wink: