Set up a template select

Hello,
I’m trying to setup a template select without succes so far. The idea is to be able to customize icon depending on the select state. I have several template switch that work as expected (albeit syntaxt is slightly different), but I can’t even get this template select created (looking at Entities).
select.383 is an MQTT that is working fine.
Code is based on: Template/select, but obvioulsy I’m doing something wrong.
Running 2022.4.1
Thanks for any help on this matter

In configuration.yaml I’ve got

template: !include templates.yaml

And in templates.yaml, I’ve got

- select:
  - name: "Sèche_serviette_gui"
    unique_id: 383_1
    state: "{{ states('select.383') }}"
    options: "{{ state_attr('select.383', 'options') }}"
    select_option:
      service: select.select_option
      target:
        entity_id : select.383
        data:
          option
    icon: >
      {% if state == 'Off' %}
      mdi:radiator-off
      {% elif state == "On" %}
      mdi:radiator
      {% elif state == "Eco" %}
      mdi:radiator-off
      {% elif state == "HGt" %}
      mdi:radiator-off
      {% elif state == "HG" %}
      mdi:radiator-off
      {% elif state == "1H" %}
      mdi:radiator-off
      {% elif state == "2H" %}
      mdi:radiator-off
      {% endif %}

Your select_option isn’t properly indented and is missing the value to set the option to.
In your icon template the variable state needs to be defined. As it stands, it returns nothing when I tried it in a notify service.

Try the following…

- select:
  - name: "Sèche_serviette_gui"
    unique_id: 383_1
    state: "{{ states('select.383') }}"
    options: "{{ state_attr('select.383', 'options') }}"
    select_option:
      - service: select.select_option
        target:
          entity_id : select.383
        data:
          option: "{{ option }}"
    icon: >
      {% set state = states('select.383') %}
      {% set map = {
      'Off': 'mdi:radiator-off',
      'On': 'mdi:radiator',
      'Eco': 'mdi:radiator-off',
      'HGt': 'mdi:radiator-off',
      'HG': 'mdi:radiator-off',
      '1H': 'mdi:radiator-off',
      '2H': 'mdi:radiator-off' } %}
      {{ map.get(state) }}
1 Like