State dependent icon and icon color using card-mod

Version: core-2026.1.3
Installation type: Home Assistant OS
card-mod 4.1.0

I have not been able to get state dependent icon and icon color to “adjust” using card-mod.

My intent is to show a red door-open or a green door-closed icon based on door status:

type: tile
entity: binary_sensor.u_bolt_pro_z_wave_smart_lock_current_status_of_the_door
icon: >
  {{ 'mdi:door-open' if
  is_state('binary_sensor.u_bolt_pro_z_wave_smart_lock_current_status_of_the_door',
  'on') else 'mdi:door-closed' }}
vertical: false
features_position: bottom
card_mod:
  style: >
    ha-card { --paper-item-icon-color: {{ 'red' if
    is_state('binary_sensor.u_bolt_pro_z_wave_smart_lock_current_status_of_the_door','on')
    else 'green' }}; }

No error messages in the system log or when I open the card with the visual or code editor.

I have at least 2 problems to resolve: icon selection and icon color. Neither of my approaches in the YAML above work.

Any suggestions would be appreciated. Thank you.
(duck.ai got me this far, but I need a bit more help :wink: )

You cannot use jinja templates here, the Tile card does not support them.

If the “binary_sensor” entity has a “device_class = door” - then it will have a proper icon automatically.

No need to use card-mod - if you the entity has a “device_class = door” (see above) then these colors can be defined in a custom theme:

  state-binary_sensor-door-on-color: red
  state-binary_sensor-door-off-color: cyan

But of course you can use card-mod:

    card_mod:
      style: |
        ha-card {
          --state-binary_sensor-door-on-color: red;
          --state-binary_sensor-door-off-color: cyan;
        }

If the entity has no “device_class = door” - a common way can be used:

    card_mod:
      style: |
        ha-card {
          {% if is_state(config.entity, 'on') -%}
          --card-mod-icon-color: ...;
          --card-mod-icon: ...;
          {%- else -%}
          --card-mod-icon-color: ...;
          --card-mod-icon: ...;
          {%- endif %}
        }

Has no sense since the Tile card does not support features for “binary_sensor” entities.

Outdated some time ago (a year? two years?).

1 Like

Thank you so much.

Yes: device_class = door
image

I’ve uninstalled card-mod and created this theme:

# Themes
frontend:
  themes:
    doorcolor:
       state-binary_sensor-door-on-color: red
       state-binary_sensor-door-off-color: green

Oddly, I deleted those lines many times, but every time I re-edited the YAML those lines reappeared. No worries, I’ve deleted that ill-fated attempt altogether.

Closed:
image

Open:
image

as desired… thanks again!

1 Like