Is it possible to change header card icon based on entity state?

So far I’ve managed to change the icon color with cardmod, but I would want to change the icon to mdi:transmission-tower-off when the grid is offline.

type: heading
icon: mdi:transmission-tower
heading: RED
heading_style: title
card_mod:
  style: |
    .content ha-icon {
      color: 
        {% set s = states('binary_sensor.energy_acsources_grid_active') %}
        {% if (s == 'off') %} red
        {% endif %}
    }

So far I’ve tried iterations of the following without success.

icon: >
  {% if states['binary_sensor.energy_acsources_grid_active'].state === 'on' %}
    mdi:transmission-tower
  {% else %}
    mdi:transmission-tower-off
  {% endif %}

Is there a way?

Try this:

    type: heading
    icon: mdi:fan
    heading: xxx
    badges:
      - type: entity
        entity: sun.sun
      - type: entity
        entity: zone.home
    card_mod:
      style: |
        .badges hui-heading-badge:nth-child(1) hui-entity-heading-badge {
          --card-mod-icon: mdi:human;
        }
        .badges hui-heading-badge:nth-child(2) hui-entity-heading-badge {
          --card-mod-icon: mdi:account;
        }
        .title ha-icon {
          --card-mod-icon: mdi:car;
        }

image
Just add jinja templates to do it conditionally.

This does not work since the Heading card does not support templates.