Template: how to set a custom icon and/or color

Hi all

After crawling the forum and inet for hours I came to the conclusion that I am lost.
We have a typical German kitchen door: open, closed and tilted. Three states, so I didn’t choose a binary sensor for the template:

  # New sensor for kitchen door statuses Open | Closed | Tilted using two Aquara contact sensors
  - sensor:
    - name: "Status kitchendoor"
      unique_id: status_kitchendoor
      state: |
        {% set b1 = states('binary_sensor.contact_sensor') %}
        {% set b2 = states('binary_sensor.gartentur_8') %}
        {% if b1 == 'off' and b2 == 'off' %} Geschlossen
        {% elif b1 == 'on' and b2 == 'off' %} Gekippt
        {% elif b2 == 'on' %} Offen
        {% elif b1 == 'unavailable' or b2 == 'unavailable' %} nicht verfügbar
        {% else %}
        {% endif %}
      icon: |
        {% set b1 = states('binary_sensor.contact_sensor') %}
        {% set b2 = states('binary_sensor.gartentur_8') %}
        {% if b1 == 'off' and b2 == 'off' %} mdi:door
        {% elif b1 == 'on' and b2 == 'off' %} mdi:window-open-variant
        {% elif b2 == 'on' %} mdi:door-open
        {% elif b1 == 'unavailable' or b2 == 'unavailable' %} mdi:exclamation
        {% else %} mdi:help-circle
        {% endif %}

In contrast to the other doors and windows, which are (still) added in the normal way (and therefore only know two states: open/closed) and therefore also switch nicely between the colors using state_color: true, this is not possible in the template.

Then changed mdi:door-open as SVG, i.e. recolored and stored under www/my_svg/door-open-recolor.svg.

But is it even possible to specify a path for an icon in a template, i.e. /local/my_svg/door-open-recolor.svg?

I had inserted it instead of mdi:door-open once as a test, there was no error, but also no colored icon when the state changed.

Perplexed & capable of learning
Greetings
RAV

Update - I have adjusted my template as follows:

  - binary_sensor:
    - name: state_kitchendoor2
      unique_id: state_kitchendoor2
      state: >
        {% if is_state('binary_sensor.contact_sensor', 'off') and is_state('binary_sensor.gartentur_8', 'off') %} off
        {% elif is_state('binary_sensor.contact_sensor', 'on') or is_state('binary_sensor.gartentur_8', 'on') %} on
        {% else %} Unavailable
        {% endif %}
      icon: >
        {% if is_state('binary_sensor.contact_sensor', 'off') and is_state('binary_sensor.gartentur_8', 'off') %} mdi:door
        {% elif is_state('binary_sensor.contact_sensor', 'on') and is_state('binary_sensor.gartentur_8', 'off') %} mdi:window-open-variant
        {% elif is_state('binary_sensor.contact_sensor', 'on') %} mdi:door-open
        {% else %} mdi:alert
        {% endif %}
      device_class: door

State is now only switched between on or off, the icon continues to check three cases. In the frontend, the color is now correctly set between normal and accent color in the three cases Open, Closed and Tilted. BUT the labeling is of course only between Open and Closed due to device_class door. Is it really possible to have only “icon colors” in the frontend via binary sensor or “nicely named states” via sensor, but not both?

Edit:

In the end, a workaround is the compromise I have to live with… I use two entities in a bubble card:
kitchendoor

One is for the states text (normal sensor) and the other one for the icon (binary sensor).

- sensor:
    - name: "Status Küchentür"
      unique_id: status_kuechentuer
      state: |
        {% set b1 = states('binary_sensor.contact_sensor') %}
        {% set b2 = states('binary_sensor.gartentur_8') %}
        {% if b1 == 'off' and b2 == 'off' %} Geschlossen
        {% elif b1 == 'on' and b2 == 'off' %} Gekippt
        {% elif b2 == 'on' %} Offen
        {% elif b1 == 'unavailable' or b2 == 'unavailable' %} nicht verfügbar
        {% else %}
        {% endif %}
  - binary_sensor:
    - name: state_kitchendoor2
      unique_id: state_kitchendoor2
      state: >
        {% if is_state('binary_sensor.contact_sensor', 'off') and is_state('binary_sensor.gartentur_8', 'off') %} off
        {% elif is_state('binary_sensor.contact_sensor', 'on') or is_state('binary_sensor.gartentur_8', 'on') %} on
        {% else %} Unavailable
        {% endif %}
      icon: >
        {% if is_state('binary_sensor.contact_sensor', 'off') and is_state('binary_sensor.gartentur_8', 'off') %} mdi:door
        {% elif is_state('binary_sensor.contact_sensor', 'on') and is_state('binary_sensor.gartentur_8', 'off') %} mdi:window-open-variant
        {% elif is_state('binary_sensor.contact_sensor', 'off') and is_state('binary_sensor.gartentur_8', 'on') %} mdi:door-open
        {% elif is_state('binary_sensor.contact_sensor', 'on') %} mdi:door-open
        {% else %} mdi:alert
        {% endif %}
      device_class: door

I’m not really happy with it because I can’t just use normal cards, but maybe it will help someone.