Need help with condition in script

Hi all,

I hope this is possible but i am stuck with errors…
What i want to accomplish is to run script.1 if condition Y and script.2 if condition X

  - service: script.turn_on
  - condition: template
    value_template: >
      {% if is_state('media_player.all', 'off') %}
      script.coffeedone_tts
      {% else %}
      script.coffeedone_notts
      {% endif %}

I have also tried editing like in this post without any luck

  - service: script.turn_on
    data_template:
      entity_id: >
        {% if is_state('media_player.all', 'off') %}
          script.coffeedone_tts
        {% else %}
          script.coffeedone_notts
        {% endif %}

Or if you have no variables to pass:

- service_template: >
    {% if is_state('media_player.all', 'off') %}
      script.coffeedone_tts
    {% else %}
      script.coffeedone_notts
    {% endif %}

Don’t you need a service for the service_template?

i.e. “script.turn_on”

Thank you @tom_l & @pnbruckner that solved my meltdown :slight_smile:

would you mind posting the completed working code? or did you use Tom’s exactly as is? I am thinking of changing some of my code to use a similar method. Cheers

The script name is a service. Try this:

grep registered home-assistant.log

Or just go to the Services page and you can see all your scripts are shown as services.

1 Like

Well there you go. I learned something today. Thanks.

1 Like