Two relays and a template fan

Hello everyone!

I’ve approached the topic several times, but I still can’t figure it out. I have two relays connected to the HA to control the fan:

  • switch.4ch_switch_szafka_tv_l1
  • switch.4ch_switch_szafka_tv_l2

The control works as it should, but I would like to create a fan using template fan. Below is what I have achieved so far, but it is not what I would like.

fan:
   - platform: template
     fans:
       tv_fan:
         friendly_name: TV Fan
         entity_id: fan.tv
         preset_mode_template: >
           {% if is_state('switch.4ch_switch_szafka_tv_l1', 'off') and is_state('switch.4ch_switch_szafka_tv_l2', 'off') %}
             off
           {% elif is_state('switch.4ch_switch_szafka_tv_l1', 'on') and is_state('switch.4ch_switch_szafka_tv_l2', 'off') %}
             low
           {% elif is_state('switch.4ch_switch_szafka_tv_l1', 'off') and is_state('switch.4ch_switch_szafka_tv_l2', 'on') %}
             high
           {%else %}
             off
           {% endif %}
         turn_on:
           - service: switch.turn_on
             entity_id: switch.4ch_switch_szafka_tv_l1
         turn_off:
           - service: switch.turn_off
             entity_id: switch.4ch_switch_szafka_tv_l1
           - service: switch.turn_off
             entity_id: switch.4ch_switch_szafka_tv_l2

The fan created in this way shows only two states in HA: off and on (which is low gear). I am kindly asking for help.

If anyone needs it, below is the configuration that worked for me

fan:
  - platform: template
    fans:
      closet_fan:
        friendly_name: "Closet Fan"
        value_template: >
          {%- if states.switch['4ch_switch_szafka_tv_l1'].state == 'on' or states.switch['4ch_switch_szafka_tv_l2'].state == 'on' -%} on 
          {%- else -%} off
          {%- endif %}
        percentage_template: >
          {%- if states.switch['4ch_switch_szafka_tv_l1'].state == 'on' -%} 50 
          {%- elif states.switch['4ch_switch_szafka_tv_l2'].state == 'on' -%} 100
          {%- else -%} 0
          {%- endif %}
        turn_on:
          service: homeassistant.turn_on
          entity_id: switch.4ch_switch_szafka_tv_l1
        turn_off:
          service: homeassistant.turn_off
          entity_id: switch.4ch_switch_szafka_tv_l1, switch.4ch_switch_szafka_tv_l2
        set_percentage:
          - service_template: >-
                {%- if (percentage > 0) and (percentage <=50) -%} homeassistant.turn_on 
                {%- else -%} homeassistant.turn_off
                {%- endif %}
            entity_id: switch.4ch_switch_szafka_tv_l1
          - service_template: >
                {%- if (percentage > 50) and (percentage <=100) -%} homeassistant.turn_on 
                {%- else -%} homeassistant.turn_off
                {%- endif %}
            entity_id: switch.4ch_switch_szafka_tv_l2
        speed_count: 2