mwthrane
(mwthrane)
November 25, 2022, 12:47pm
1
Hello
I’m trying to create a mushroom state card that changes color based on the state. There are no errors but the icon does not change color. Any ideas?
type: custom:mushroom-entity-card
entity: sensor.nordpool_kwh_dk1_dkk_3_01_025
name: Elpris
fill_container: false
icon: mdi:lightning-bolt
icon_color: >
if (state > 4) return 'rgb(0,0,0)'; if (state > 3) return
'rgb(0,0,204)'; if (state > 1) return 'rgb(255,255,0)'; if (state < 1)
return 'rgb(0,204,102)';
State:
2.532
The icon stays white.
Any ideas?
cadwizzard
(Cadwizzard)
November 25, 2022, 1:10pm
2
I had this same problem with climate card. My thermostats dont have a heating state so the badge wouldnt work. I thought to change the icon based on state. The developer basically said it wasnt possible.
But what is possible is to used card-mod to either flash the icon or change the card background colour based on state.
I’d be super interested if you figure a way to change the icon based on state… or the developer of mushroom adds this into his cards (icon or/and badges)
mwthrane
(mwthrane)
November 25, 2022, 2:07pm
3
Thank you
If you have the code to change the background color, could you post it?
cadwizzard
(Cadwizzard)
November 25, 2022, 3:10pm
4
I had to pay someone to write it for me, so not releasing it yet (but looks like you have the skills to figure it out)
Start with:
` card_mod:
style: >
ha-card {
background-color:`
mwthrane
(mwthrane)
November 25, 2022, 3:38pm
5
I read your post 7 times and still thought I read it wrong.
pedolsky
(Pedolsky)
November 25, 2022, 11:37pm
6
mwthrane:
mushroom-entity-card
You have to use the template card together with Jinja .
type: custom:mushroom-template-card
primary: some text
secondary: some text
icon: mdi:fire
entity: sensor.xxxx
icon_color: |
{% if states(entity) |int(4) > 4 %} {{ '#%02x%02x%02x' % (255,0,0) }}
{% elif states(entity) |int(3) > 3 %} {{ '#%02x%02x%02x' % (0,0,204) }}
{% elif states(entity) |int(1) > 1 %} {{ '#%02x%02x%02x' % (255,255,0) }}
{% elif states(entity) |int(0) < 1 %} {{ '#%02x%02x%02x' % (0,204,102) }}
{% else %} grey
{% endif %}
That part '#%02x%02x%02x' %
converts the rgb color into hex.
2 Likes
mwthrane
(mwthrane)
November 26, 2022, 8:54am
8
I played around with it a bit.
type: template
entity: sensor.nordpool_kwh_dk1_dkk_3_01_025
icon: mdi:lightning-bolt
icon_color: |-
{% if states(entity) |int(4) > 4 %} {{ '#%02x%02x%02x' % (0,0,0) }}
{% elif states(entity) |int(3) > 3 %} {{ '#%02x%02x%02x' % (255,0,0) }}
{% elif states(entity) |int(2) > 2 %} {{ '#%02x%02x%02x' % (255,127,0) }}
{% elif states(entity) |int(1) > 1 %} {{ '#%02x%02x%02x' % (255,255,0) }}
{% elif states(entity) |int(0) < 1 %} {{ '#%02x%02x%02x' % (0,255,0) }}
{% else %} grey
{% endif %}
content: ''
This line is triggered
{% elif states(entity) |int(1) > 1 %} {{ '#%02x%02x%02x' % (255,255,0) }}
WIth state:
2.602
Should be this one (i think)
{% elif states(entity) |int(2) > 2 %} {{ '#%02x%02x%02x' % (255,127,0) }}
Any ideas?
pedolsky
(Pedolsky)
November 26, 2022, 3:06pm
9
I don’t know the Nordpool integration. Change the |int to |float to take the digits into account.
1 Like