Template not working on script

Hello,

I have a script that sends a text message to an echo dot. The text comes from an input field and the echo dot is chosen using an input boolean.

I have used the template edition in developer tools and all seems to work propertly. However, the script isn’t doing anything, even it doesn’t give any error.

Here it is the part of the script where the template is used:

- service: notify.alexa_media
    data:
      message: "{{states('input_text.tts')}}"
      data:
        type: tts
      target: >
        {%- if is_state('input_boolean.alexa_pb', 'on') and is_state('input_boolean.alexa_p1','on') %}
          - media_player.alexa_pb
          - media_player.alexa_p1 
        {%- elif is_state('input_boolean.alexa_pb','on') and is_state('input_boolean.alexa_p1', 'off') %}
          - media_player.alexa_pb
        {%- elif is_state('input_boolean.alexa_pb', 'off') and is_state('input_boolean.alexa_p1','on') %} 
          - media_player.alexa_p1 
        {% endif %}

I imagine that the problem is in the target field, because if I remove the template and put any of the alexa devices, it works correctly. However, I can’t figure it out where is the mistake as I don’t get any error message.

Thanks in advance!