Change color of entity icon in heading card based on numeric value

I’m redoing my dashboards with the new sections layout, and I’m trying to condense things into a heading card for quick reference. I want to do an if/then statement in yaml to change the color of the temperature icon, but the yaml doesn’t seem to work in the card.

I’ve tested it in the template editor, and the expression works and is able to print out Blue or Green. I know the expression is good, but I don’t know why it’s not working in the heading card.

What am I missing to make it work in the heading card?

type: entity
show_state: true
show_icon: true
entity: sensor.apollo_mtr_1_f58774_dps310_temperature
color: >-
  {% if (states('sensor.apollo_mtr_1_f58774_dps310_temperature') | float <= 75)
  %}
    blue
  {% else %}
    green
  {% endif %}
name: Temperature


  1. You are talking about Heading card - but what you posted seems to be a part of it. Suggest to post a full code of a card to avoid confusion. And of course - no need to post unrelated staff like 10 other entities which you do not want to style.
  2. Heading card does not support jinja templates for options. In fact, only a Markdown card supports templates and some custom cards.
  3. To set a color of an icon of some badge in Heading card dynamically (dependently on some entity, for example) - use card-mod. Go to the main card-mod thread → go to 1st post → find a link at the bottom titled “fantastic post” → find “Heading card” chapter. Suggest to discuss all card-mod related staff in that thread.