Is it possible to run scripts according to a template?

I have this code in an automation, and need to know if this is possible at all, running one or more scripts this way??

    - service: homeassistant.turn_on  
      data_template: 
        entity_id: >
          {% if is_state('device_tracker.pal_presence', 'Away') and 
          is_state('device_tracker.eva_presence', 'Away') %}
            script.espresso_turn_off
          {% endif %}

You don’t have an else statement. That’s going to generate errors.

Also you would be better off with a service template rather than a data template (scripts are services):


    - service_template:
        {% if is_state('device_tracker.pal_presence', 'Away') and is_state('device_tracker.eva_presence', 'Away') %}
          script.espresso_turn_off
        {% else %}
          ## another service here
        {% endif %}

Thank you for your clear eyes and suggestion, @tom_l :slight_smile:

@tom_l: Will I be able to list several scripts in a row like this?

    - service_template:
        {% if is_state('device_tracker.pal_presence', 'Away') and is_state('device_tracker.eva_presence', 'Away') %}
          - script.espresso_turn_off
          - script.another_script
          - script.a_third_script
          - service.even_a_service_to_run
        {% else %}
          ## another service here
        {% endif %}

No. Only one.

If you need to do that, create one big script.

Thank you!