Input select equal home theater source

Hello everyone. Could you help me with this automation. I want that when changing an input select the home theater changes to the same place. I’m doing something wrong because I can’t get the home theater to match the input select
I think maybe the automation is wrong. Thank you

  - alias: bdv_n9200w_change_source
    description: "Cambia media con Broadlink cuando se cambia input_select.home en  home assistant"
    trigger:
      - platform: state
        entity_id: input_select.home
    condition:
      - "{{ now() - state_attr('automation.bdv_n9200w_input_select', 'last_triggered')  >= timedelta(seconds=4) }}"
    variables:
      repeats: >
        {% set sources = ["Bluetooth","Audio","DB DVD","USB","FM Present","HDMI 1","HDMI 2","TV","SCR M"] %}
        {% set old_pos = sources.index(trigger.from_state.state) | int(0) %}
        {% set new_pos = sources.index(trigger.to_state.state) | int(0) %}
        {% if new_pos >= old_pos %}
          {{ new_pos - old_pos }}
        {% else %}
          {{ (sources|length - old_pos) + new_pos }}
        {% endif %}
    action:
      repeat:
        count: "{{repeats}}"
        sequence:
          - service: script.bdv_n9200w_source

Script

  bdv_n9200w_source:
    sequence:
    - service: remote.send_command
      target:
        entity_id: remote.broadlink_rm3_comedor
      data:
        command: 'b64:JgDuAFESKRIVExQTKBMUEygTKBMUExUSFRIVEygSFRMoEygAApxREygSFRMTFCgTFBMnFCgTExQUExQTFBQnExQUJxQnAAKdUBQnExQUExQnFBMUJxQnFBQTFBMUExQUJxQTFCcUJwACpk8UJxQUExQTKBMUEygTKBMUExQUExQTFCcUFBMoEygAAqVQEygTFBMUFCcUExQnFCcUExQUExQTFBMoExQUJxQnAAKlUBQnFBMUExQnFBQTKBMoExQTFBMUFBMUJxQTFCcUJwACpk8UKBMUExQTKBMUFCcUJxMUFBMUFBMUEygTFBMoEygADQUAAAAAAAAAAAAA'
    - delay: '00:00:01'