Template select option with multiple actions

Hello,

I am just starting with HA and I am trying to integrate my custom radiator controller (Pilot Wire) that is based on a Shelly Plus 2PM + Two Diodes connected to each output.
Depending on the combination On/Off of each channels it defines the actual radiator modes.

I have managed to display the current modes (pilote_salon_front_mode), but now I would like to have a more user friendly way of setting the the modes from the UI.

Question / Help:

Using the mode selector (pilote_salon_front_setmode), if I select any of the given modes how could I set / send the corresponding combination of On or Off the the channels.

How would the below pseudo code look like or is this kind of thing even possible?

template:
  - sensor:
      - name: "Pilote - Salon - Front - Mode"
        unique_id: pilote_salon_front_mode
        state: >
          {% if is_state('switch.shelly_pm_pilote_salon_switch_0', 'on') and is_state('switch.shelly_pm_pilote_salon_switch_1', 'off') %}
            off
          {% elif is_state('switch.shelly_pm_pilote_salon_switch_0', 'off') and is_state('switch.shelly_pm_pilote_salon_switch_1', 'off') %}
            on
          {% elif is_state('switch.shelly_pm_pilote_salon_switch_0', 'on') and is_state('switch.shelly_pm_pilote_salon_switch_1', 'on') %}
            eco
          {% elif is_state('switch.shelly_pm_pilote_salon_switch_0', 'off') and is_state('switch.shelly_pm_pilote_salon_switch_1', 'on') %}
            anti-freeze
          {%- else -%}
            unknown
          {%- endif %}
  - select:
      - name: "Pilote - Salon - Front - SetMode"
        unique_id: pilote_salon_front_setmode
        state: "{{ states('sensor.pilote_salon_front_mode') }}"
        options: "{{ ['off', 'on', 'eco', 'anti-freeze'] }}"
        select_option:
            <<HELP -- PESEUDO CODE>>
            if pilote_salon_front_setmode == 'on':
              - service: switch.turn_off
                target:
                  entity_id: switch.shelly_pm_pilote_salon_switch_0
              - service: switch.turn_off
                target:
                  entity_id: switch.shelly_pm_pilote_salon_switch_0
            if pilote_salon_front_setmode == 'echo':
              - service: switch.turn_on
                target:
                  entity_id: switch.shelly_pm_pilote_salon_switch_0
              - service: switch.turn_on
                target:
                  entity_id: switch.shelly_pm_pilote_salon_switch_1

            <<HELP -- PESEUDO CODE>>

Thanks in advance for any help or suggestions,

template:
  - sensor:
      - name: "Pilote - Salon - Front - Mode"
        unique_id: pilote_salon_front_mode
        state: >
          {% set combo = (states('switch.shelly_pm_pilote_salon_switch_0'),
          states('switch.shelly_pm_pilote_salon_switch_1'))|string %}
          {% set mapper = {
          "('off', 'on')": 'anti-freeze',
          "('off', 'off')": 'on',
          "('on', 'off')": 'off',
          "('on', 'on')": 'eco' } %}
          {{mapper.get(combo)}}
  - select:
      - name: "Pilote - Salon - Front - SetMode"
        unique_id: pilote_salon_front_setmode
        state: "{{ states('sensor.pilote_salon_front_mode') }}"
        options: "{{ ['off', 'on', 'eco', 'anti-freeze'] }}"
        select_option: 
          - choose:
              - conditions:
                  - "{{ option == 'on' }}"
                sequence: 
              - service: switch.turn_off
                target:
                  entity_id: 
                    - switch.shelly_pm_pilote_salon_switch_0
                    - switch.shelly_pm_pilote_salon_switch_1
              - conditions:
                  - "{{ option == 'eco' }}"
                sequence:
                  - service: switch.turn_on
                    target:
                      entity_id: 
                        - switch.shelly_pm_pilote_salon_switch_0
                        - switch.shelly_pm_pilote_salon_switch_1
              - conditions:
                  - "{{ option == 'off' }}"
                sequence:
                  - service: switch.turn_on
                    target:
                      entity_id: switch.shelly_pm_pilote_salon_switch_0
                  - service: switch.turn_off
                    target:
                      entity_id: switch.shelly_pm_pilote_salon_switch_1
              - conditions:
                  - "{{ option == 'anti-freeze' }}"
                sequence:
                  - service: switch.turn_off
                    target:
                      entity_id: switch.shelly_pm_pilote_salon_switch_0
                  - service: switch.turn_on
                    target:
                      entity_id: switch.shelly_pm_pilote_salon_switch_1

Thanks for the help, this is exactly what I was looking for!

I know have a related question, in this example I just had to define these two templates pilote_salon_front_mode and pilote_salon_front_setmode but I have around 6 individual shelly devices for each room.

Any one know if this could be blueprinted or templetized so that I don’t have to repeat all this same code for each device?
It’s still not clear to me what would be the best way to simplify this logic and automate the creation of these two entities for each device.