Mushroom Chips Card -Change Color of Icon depinding on state -not working-

Hi all,

I am very frustrated because I do not see the mistake in my configuration.

The color of the icon should change depending on the switching state (on/off). The state of “input_boolean.autokellerbeleuchtung_weekend” is correct. I can see it in the developer environment. Can anyoune help here?

Spartacus

type: custom:mushroom-chips-card
chips:
  - type: entity
    entity: input_boolean.autokellerbeleuchtung_weekend
    icon: mdi:lightbulb-auto
    tap_action:
      action: toggle
    name: Auto Wochenende
    use_entity_picture: true
    double_tap_action:
      action: none
    hold_action:
      action: none
    icon_color: |-
      {% if is_state('input_boolean.autokellerbeleuchtung_weekend', 'on') %}
        green
      {% else %}
        red
      {% endif %}

Use the chip template card for templating

type: custom:mushroom-chips-card
chips:
  - type: template
    ...

Hi,

hm! This matter is quite new to me, and i need some more help. If i change “entity” to “template” nothing works abymore. So I guess that there is much more to do, than only changing he type !

type: custom:mushroom-template-card
primary: wochentags
secondary: ''
icon: mdi:home
entity: input_boolean.auto_kellerlicht_werktags
icon_color: |-
  {% if is_state ('input_boolean.autokellerbeleuchtung_weekend', 'on') %}
   green
  {% else %}
   red
  {% endif %}
layout: horizontal
tap_action:
  action: toggle
hold_action:
  action: none
double_tap_action:
  action: none
  • the icon always stays red!

There’s a space between.

1 Like

…yeh! Thanks!

I believe you can reduce the template to this:

icon_color: "{{ 'green' if states(entity) == 'on' else 'red' }}"
1 Like

Hello Taras,

very cool! Thank you very much for this! it works!

Hello @123,

please, can you see, what is wrong with this one - it does not change the color at all?

icon_color: "{{ 'green' if states('alarm_control_panel.section_2') == 'disarmed' else 'red' }}"

What does {{ states('alarm_control_panel.section_2') }} show in Developer toolsTemplate?

it says: armed_away

OK, assuming that it only has 2 states, you could try this (I have reversed the logic):

icon_color: "{{ 'red' if states('alarm_control_panel.section_2') == 'armed_away' else 'green' }}"

…but I am not sure that there isn’t an armed_home (for nights, maybe), so perhaps check what that sensor shows when you alarm is disarmed (maybe it’s disarmed_home)?

yes, I also tried ‘disarmed’, but the result is the same. I am not sure, whether it simply is not supported…

I also tried this one, but the same result…

    icon_color: |-
      {% set state=states('alarm_control_panel.section_2') %}
      {% if state=='armed_away' %}
      red
      {% elif state=='disarmed' %}
      green
      {% endif %}

I am also trying another entity, but the result is the same :frowning:

  - type: entity
    entity: group.vodovod
    content_info: name
    icon_color: |-
      {% set state=states('group.vodovod') %}
      {% if state=='off' %}
       red
      {% elif state=='on' %}
       green
      {% endif %}
      action: toggle

So you tried it with my code and it still didn’t work?

yes, I tried, but with no success :frowning:

yes, of course. Try it with type: custom:mushroom-template-card instead.

Hi,

Its nor working for me? Can you help me?


- type: custom:mushroom-template-card
    primary: Lampen
    secondary: ''
    icon: mdi:lightbulb
    icon_color: '{{ ''green'' if states(light.woonkamer_voorkeuken) == ''on'' else ''red'' }}'
    layout: vertical
    tap_action:
      action: navigate

However the icon now has no color. and wont change if i enable this light.

You need single quotes around your light entity:

if states(‘light.woonkamer_voorkeuken’)

edit:
I’ve cleaned up all your quotes for you - note where I have put doubles and singles:

    icon_color: "{{ 'green' if states('light.woonkamer_voorkeuken') == 'on' else 'red' }}"

Perfect.

Its working now. Thanks for your feedback!

1 Like

One more question. Is it possible to enter multiple states for one color?

The quick answer is ‘yes’ but I am not at my desktop right now. Can it wait?