pepeEL
(pepeEL)
December 27, 2019, 8:49am
1
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.
tom_l
December 27, 2019, 9:40am
2
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.
Lovelace Templates
I’ve gone and made a crazy card that allows you to pretty much template anything in Lovelace for your card configurations using any information available on the frontend; states, attributes, user, etc.
Want state/attribute-based icons? DONE!
Want dynamic stacks; vertical vs horizontal based on user? DONE!
Want OR conditionals? DONE!
The list is pretty much endless and I’m sure you all will come up with some crazy stuff. Be sure to share.
Go nuts! Enjoy!
Alternatively, if you used the template cover integration you can define an icon template in your config.
pepeEL
(pepeEL)
December 27, 2019, 9:55am
3
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?
tom_l
December 27, 2019, 10:03am
4
Yes and I told you how above.
pepeEL
(pepeEL)
December 27, 2019, 10:18am
5
Ok but how in this config-template change Icon other for open and other for closed…?
tom_l
December 27, 2019, 10:33am
6
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.
pepeEL
(pepeEL)
December 28, 2019, 10:08am
7
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.
tom_l
December 28, 2019, 10:15am
8
What is the error message?
pepeEL
(pepeEL)
December 28, 2019, 10:20am
9
No error. Not show any icons.
tom_l
December 28, 2019, 10:26am
10
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' }
pepeEL
(pepeEL)
December 28, 2019, 10:35am
11
Now on card not show any entity. Blank white card
tom_l
December 28, 2019, 10:45am
12
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
pepeEL
(pepeEL)
December 28, 2019, 10:50am
13
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
pepeEL
(pepeEL)
December 28, 2019, 1:40pm
14
But is any chance to add this card to card default in lovelace name ENTITY ?
tom_l
December 28, 2019, 1:48pm
15
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' }
taillant
(Jean-Marc Taillant)
February 16, 2022, 11:36pm
17
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'