Change icon color on open/close

I have this code, but the icons are always white, regardless of opening or closing, what’s the problem?

type: custom:vertical-stack-in-card
cards:
  - type: custom:vertical-stack-in-card
    cards:
      - type: entities
        entities:
          - entity: cover.roleta_w_gabinecie
            type: custom:multiple-entity-row
            name: "[Gospodarczy]"
            show_state: null
            icon: mdi:home-silo
            secondary_info: last-updated
            entities:
              - type: custom:button-card
                icon: mdi:window-shutter-open
                show_state: false
                styles:
                  icon:
                    - color: |
                        [[[ 
                          if (states['cover.roleta_w_gabinecie'].state === 'open') return 'rgb(0,255,0)';
                          if (states['cover.roleta_w_gabinecie'].state === 'closed') return 'rgb(255,0,0)';
                          return 'rgb(255,165,0)';
                        ]]]
                tap_action:
                  action: call-service
                  service: cover.open_cover
                  service_data:
                    entity_id: cover.roleta_w_gabinecie
              - type: custom:button-card
                icon: mdi:window-shutter-alert
                show_state: false
                styles:
                  icon:
                    - color: |
                        [[[ 
                          if (states['cover.roleta_w_gabinecie'].state === 'open') return 'rgb(0,255,0)';
                          if (states['cover.roleta_w_gabinecie'].state === 'closed') return 'rgb(255,0,0)';
                          return 'rgb(255,165,0)';
                        ]]]
                tap_action:
                  action: call-service
                  service: cover.set_cover_position
                  service_data:
                    entity_id: cover.roleta_w_gabinecie
                    position: 41
              - type: custom:button-card
                icon: mdi:window-shutter
                show_state: false
                styles:
                  icon:
                    - color: |
                        [[[ 
                          if (states['cover.roleta_w_gabinecie'].state === 'open') return 'rgb(0,255,0)';
                          if (states['cover.roleta_w_gabinecie'].state === 'closed') return 'rgb(255,0,0)';
                          return 'rgb(255,165,0)';
                        ]]]
                tap_action:
                  action: call-service
                  service: cover.close_cover
                  service_data:
                    entity_id: cover.roleta_w_gabinecie

Wrote a long answer - and only then noticed that you are using custom:button-card inside multiple-entity-row which is not possible.

2 Likes