Trouble changing icon color based off entity state

Hey everyone. I’m trying to set up a custom mushroom chip card which contains my front door lock (among other chips). I want the lock icon to be one color when unlocked and another when locked but I cannot seem to get this to function. I have even copied other user’s yaml configurations and still been unsuccessful. Here’s what I have that is non-functional. This current configuration results in the lock icon remaining white under all circumstances but has no errors reported. I’m sure I’m overlooking something very silly but I’m brand new to coding so feel free to point me to any and all resources to get me on the right track here.

  - type: entity
    entity: lock.front_door
    use_entity_picture: false
    icon_color: <-
        {% if is_state( 'lock.front_door', 'unlocked' ) %}
        red
        {% else %}
        green
        {% endif %}

Not using mushrooms, but this is an obvious error, try this:

icon_color: >-
  ...

Ildar is correct, the only difference is you can’t use templates in an entity chip has to be a template chip like so.

type: custom:mushroom-chips-card
chips:
  - type: template
    entity: switch.loungetv
    icon: mdi:television
    icon_color: >-
      {% if is_state( 'switch.loungetv', 'off' ) %} red {% else %} green {%
      endif %}
    content: '{{states(''switch.loungetv'')}}'

Thanks both lldar and Frosty, I’ve made those two adjustments but am still yielding an unchanging white icon.

  - type: template
    entity: lock.front_door
    icon: mdi:lock
    icon_color: >-
      <- {% if is_state( 'lock.front_door', 'unlocked' ) %} red {% else %} green
      {% endif %}
    content: '{{states("lock.front_door")}}'

remove the < -

Wow. Facepalm moment for real. Thanks!!!

1 Like