[solved] Syntax for script with service_template. Can't find the right way to define entity

Service templates require a result at all times, so you have to use a condition to stop the script instead of using a service template.

script:
  media_mode:
  alias: Set media mode script 
  sequence:
  - condition: template
    value_template: >
      {% set media_devices =
        {
        'PowerOff': 'poweroff',
        'Televisie': 'television',
        'Mediaplayer': 'mediaplayer',
        'Apple-TV': 'appletv',
        'Radio':, 'radio',
        'Muziek': 'music',
        'DVD': 'dvd',
        'Teletekst': 'teletext',
        'Smart-TV': 'smarttv'
        }
      %}
      {{ old_state in media_devices.keys() }}
  - service: input_boolean.turn_off
    data_template:
      entity_id: >
        {% set media_devices =
        {
          'PowerOff': 'poweroff',
          'Televisie': 'television',
          'Mediaplayer': 'mediaplayer',
          'Apple-TV': 'appletv',
          'Radio':, 'radio',
          'Muziek': 'music',
          'DVD': 'dvd',
          'Teletekst': 'teletext',
          'Smart-TV': 'smarttv'
        }
        %}
      input_boolean.{{ media_devices[old_state] }}

So, it appears as if you are trying to use toggles to switch your harmony activities. There’s a much better way to do this without scripts, switch templates. Check out the switch template section in this post:

Basically the switches will only be on when the activity is on. You don’t have to worry about toggling other input_booleans off when you turn on another activity.

EDIT: I also want to clarify. The reason your template isn’t working is because you are attempting to use a list of tuples to get your information. You need to use a dictionary. Notice the syntax change for media_devices. That is the proper way to make a dictionary in jinja. The way you were writing it was a list of tuples ().