Script If Else don't work

Hi

I like to use a script which join/unjoin sonos speakers to a group. For this I use if-else. Unfortunatly it don’t work. Can someone help me with my script?

'1577611033501':
  alias: Sonos-Test
  sequence:
  - service: sonos.join
    data_template: >
    {% if is_state('media_player.livingroom', 'playing')%}
      entity_id:
           - media_player.livingroom
           - media_player.bath
      master: media_player.livingroom
    {% elif is_state('media_player.kitchen', 'playing')%}
      entity_id:
           - media_player.kitchen
           - media_player.bath
      master: media_player.kitchen
    {% elif is_state('media_player.bedroom', 'playing')%}
      entity_id:
           - media_player.bedroom
           - media_player.bath
      master: media_player.bedroom
        {% else %}
      entity_id:
           - media_player.bath
      master: media_player.bath
        {% endif %}

When I test the Script in the Template Section from Home Assistant, then I get the following output:

1577611033501':
  alias: Sonos-Test
  sequence:
  - service: sonos.join
    data_template: >
    
      entity_id:
           - media_player.bath
      master: media_player.bath

But the script don’t work and when I check the configuration, I get the following error:

Error loading /home/homeassistant/.homeassistant/configuration.yaml: while scanning for the next token
found character ‘%’ that cannot start any token
in “/home/homeassistant/.homeassistant/scripts.yaml”, line 118, column 6

Does anybody have a idea what’s wrong in my script?

Thanks & Regards
Thailwip