Change input_select o source

Hello. If a device has an attribute that is for example hdmi 1, how do I change an input_select to take that value?

  - alias: change source
    trigger:
      - platform: state ?
        entity_id: input_source
    condition: template
            sequence:
              - service: remote.send_command
                data:
                  entity_id: remote.broadlink_remote
                  command: !secret ir_purifier_speed_down
       value_template: "{{ state_attr('x', 'html 1') }}"
    action:    
      - service: 
        data: x

If I change the value in the select … How do I in one case execute the command 1 or 10 times depends on what I select. For example if I am in hdml 1 and I change to hdmi 2 I have to execute the command 1 time but if I am in hdml 2 and I choose hdmi 1 I have to execute the command several times to get to that source on the tv or home theater

  - alias: change source
    conditions:
      - condition: template
        value_template: >
          {{is_state_attr('input_select.source', 'hdmi 1')}}
        sequence:
          - service: remote.send_command
            data:
              entity_id: remote.broadlink_remote
              command: xxxxxx