Change lock unlocked icon?

Is there a way to change the icon that is used for a z-wave lock showing unlocked?

I’m happy with mdi:lock for locked, but I want mdi:lock-open-variant for unlocked because the “normal” mdi:lock-open is too close to locked at a glance.

I attempted to change it in the customize-YAML using code that works with templates, but then I get no icon…
image

homeassistant:
  customize:
    lock.deadbolt_back_door:
      icon: {{ 'mdi:lock' if is_state('lock.deadbolt_back_door','locked') else 'mdi:lock-open-variant' }}
  1. You cannot use jinjia templates for customizing an icon in the “customize” section.
  2. Do you wish to redefine an icon for a particular card - or for everywhere (including more-info window)? If for a particular card - you may either use a template-supporting-card (like config-template-card) or card-mod (setting a “–card-mod-icon” variable). If for everywhere - probably a template switch will be the easiest way.

I was hoping everywhere for consistency, but I am displaying them in entity cards along with other home status highlights.

I know I can change it to a single icon in the entity card customization, but that doesn’t seem to be dynamic either.

Then choose any of the mentioned above ways to select an icon dynamically.

I don’t understand enough of what those are talking about, what to change on the card to make them appear like I want though. Is there documentation on that somewhere?

Simplest way - using card-mod:
here is how to set a STATIC icon: go to card-mod github, scroll to “changing icons”.
But you need it dynamic: on - icon 1, off - icon 2.
Then use a jinja template like:

...
card_mod:
  style: |
    :host {
      {% if is_state(‘lock.xxxxx’,’on’) %}
      --card-mod-icon: mdi:xxxxxx;
      {% else %}
      --card-mod-icon: mdi:xxxxxx;
      {% endif %}
    }
2 Likes

This is great. I did some fine tuning for my use case and utilised card-mod’s, config Jinja object to avoid hard cording the entity name:

card_mod:
  style: |
    :host {
      {% if is_state(config.entity, 'open') %}
      --card-mod-icon: mdi:gate-arrow-right;
      {% elif is_state(config.entity, 'locking') %}
      --card-mod-icon: mdi:gate-arrow-left;
      {% else %}
      --card-mod-icon: mdi:gate;
      {% endif %}
    }
  }