If, then, else - based on state

I’ve been trying to create a script (which will be triggered by Alexa), that will either pause one device or the other, depending on which is currently playing. I cannot figure out how it should be written, though.

I think it should be something along these lines, but I think I need help with the formatting, or instructions: (I’ve tried a few ways, and this particular one gives me “template rendered invalid service” error)

alias: '123'
sequence:
  service_template: >
    {% if is_state('media_player.fire_stick_lounge', 'playing') %}
      script.pause_resume_fire_stick
    {% elif is_state('media_player.roku_lounge', 'playing') %}
      script.pause_roku
    {% endif %}
mode: single
alias: New Script
sequence:
  - choose:
      - conditions:
          - condition: state
            entity_id: media_player.fire_stick_lounge
            state: playing
        sequence:
          - service: script.turn_on
            target:
              entity_id: script.pause_resume_fire_stick
      - conditions:
          - condition: state
            entity_id: media_player.roku_lounge
            state: playing
        sequence:
          - service: script.turn_on
            target:
              entity_id: script.pause_roku
    default: []
mode: single

You can make use Choose Action script syntax.

1 Like

Thank you so much; that works brilliantly! I hadn’t come across “choose” before.