Change icon for cover open and closed

Hi
I have a roller shutter on mysensors gateway and it is add to my Home Assistant. I add it to Entity card. But i want change icon this cover. I want to have icon for open: mdi:window-shutter-open
and for closed icon: mdi:window-shutter

I do this in code card but it is not working and icon now no apper…
It is for cover.roller_shutter_for_ha_0_1

entities:
  - entity: scene.swiatlo_scene
  - entity: cover.roller_shutter_for_ha_0_1
    icon: >-
      if (state === 'open') return 'mdi:window-shutter-open'; else return
      'mdi:window-shutter';
  - entity: cover.roleta_test
show_header_toggle: false
title: Sceny
type: entities

i want to look icon as for roleta.test:

Anybody can help me…
When create cover templating it is no good because i dont have a slider positioning…
But better will be only change icon for this cover and it will be a good solution.

Did you just make this up and hope it would work or did you copy it from somewhere?

    icon: >-
      if (state === 'open') return 'mdi:window-shutter-open'; else return
      'mdi:window-shutter';

The core lovelace entities card is not template-able.

You have to use a custom card to do this.

Alternatively, if you used the template cover integration you can define an icon template in your config.

I copied it from some topic found in internet.
But is any chance to change this Icon look “window” to my Icon found look as roller shutter?

Yes and I told you how above.

Ok but how in this config-template change Icon other for open and other for closed…?

By reading the instructions, looking at the examples and having a go.

If it does not work post what you have tried here and we will attempt to help.

I installed this… but i dont know how use it in Lovelace. I add manua card and add this but it has bug:

type: 'custom:config-template-card'
entities:
  - cover.roller_shutter_for_ha_0_1
card:
  type: entities
  entities:
    - entity: cover.roller_shutter_for_ha_0_1
      icon: >-
        if (state === 'open') return 'mdi:window-shutter-open'; else return
        'mdi:window-shutter';

but not working.

What is the error message?

No error. Not show any icons.

Your template syntax is nothing like what is shown in the card instructions. Try:

type: 'custom:config-template-card'
entities:
  - cover.roller_shutter_for_ha_0_1
card:
  type: entities
  entities:
    - entity: cover.roller_shutter_for_ha_0_1
      icon: >-
         ${ states('cover.roller_shutter_for_ha_0_1') === 'open' ? 'mdi:window-shutter-open' : 'mdi:window-shutter' }

Now on card not show any entity. Blank white card

How about:

type: 'custom:config-template-card'
entities:
  - cover.roller_shutter_for_ha_0_1
card:
  type: entities
  entities:
    - entity: cover.roller_shutter_for_ha_0_1
      icon: >-
         ${ states['cover.roller_shutter_for_ha_0_1'].state  === 'open' ? 'mdi:window-shutter-open' : 'mdi:window-shutter' }
2 Likes

Yes bug was with “[”
Now works icon is show ok but when cover is open and closed always show icon mdi:window-shutter

Not show icon mdi:window-shutter-open when cover is state “open”

EDIT
Works ok THANKS. Some bugs by typing. Again copy and past and works perfect.

1 Like

But is any chance to add this card to card default in lovelace name ENTITY ?

Probably not. But nothing stopping you from asking:

https://community.home-assistant.io/c/feature-requests

Hi,

Is it also possible with attributes, like postition = 100 then mdi:window-shutter-open? I try this, but this is wrong format.

      - type: 'custom:config-template-card'
        entities:
        -  cover.rolluikwoonkamer
        card:
          type: entities
          entities:
          - entity: cover.rolluikwoonkamer
            icon: >-
                ${ states['cover.rolluikwoonkamer.attributes.current_position'].state  === '100' ? 'mdi:window-shutter-open' : 'mdi:window-shutter' }

Try this to get the current_position attribute

- type: 'custom:config-template-card'
        entities:
        -  cover.rolluikwoonkamer
        card:
          type: entities
          entities:
          - entity: cover.rolluikwoonkamer 
            icon: >-
                ${ states ['cover. rolluikwoonkamer'].attributes.current_position === 100 ? 'mdi:window-shutter-open' : 'mdi:window-shutter'