Run multiples scripts with Automation

Hello all,

Hey guys, wondering if someone can clear something up for me. here is my configuration :

action:

  • service: script.turn_on
    entity_id:
    • script.script1
    • script.script2

The scripts will run randomly mp3 files with media_player, the duration is variable.
so when i run the automation script at 19:30, i want it to start script1, wait until it finished, then start the second script and so one.

Any idea ?

Call the scripts directly rather than using the script.turn service. See: https://www.home-assistant.io/integrations/script/#waiting-for-script-to-complete

    action:
      - script.script1
      - script.script2

When i call them directly i had this error :

Message malformed: expected dictionary @ data[‘action’][0]

Because I’m an idiot. Try this:

    action:
      - service: script.script1
      - service: script.script2

Thank you for your quick response.

each time i ran the automation, only one of the 2 scripts ran. when i ran it again, only the second one who ran.

Any idea ?

Did you wait for script 1 to finish?

What happens is, script 1 runs then when it is finished script 2 runs. Which is what I thought you asked for:

Or have I missundersttod?

Yes that’s my goal.
Start script1, wait until it’s finished, than start Script2.

But when i used :

action:
  - service: script.script1
  - service: script.script2

and execute the automation. only one of them start. (exemple : script1) that it.
and when i ran the automation (manually) the second time. only the other script (exemple : script2) who start.

To give you an overview, here is my logs.

As you can see, Test (script) and English_Story (script) ran at the same time by Auto_test (Automation)

but i only hear MP3 from English_Story (script).

And when i execute the automation again. i heard only songs from Test (script).

Because you did not wait for the first script to finish. The second time script 1 was already running, in the default single mode most likely.

Because you did not wait for the first script to finish

I did wait,

The first script should run only 2 o 3 seconds than the second should start.

Without seeing your scripts I cant say what is happening for you but for everyone else this is how it works: https://www.home-assistant.io/integrations/script/#waiting-for-script-to-complete

Here is my scripts :

Script 1

media_content_id: '/media/local/test/{{range(1,4)|random}}.mp3'
media_content_type: audio/mp3

Script 2

media_content_id: '/media/local/English Story/{{range(1,41)|random}}.mp3'
media_content_type: audio/mp3

What do you think ?

Neither of those are scripts.

Sorry my bad, i pasted only a part of script.

Here is the scripts :slight_smile:

Script 1

alias: English story
sequence:

  • service: media_player.play_media
    data:
    media_content_id: ‘/media/local/English Story/{{range(1,41)|random}}.mp3’
    media_content_type: audio/mp3
    entity_id: media_player.mini_nour
    mode: single

Script 2

alias: test
sequence:

  • service: media_player.play_media
    data:
    media_content_id: ‘/media/local/test/{{range(1,4)|random}}.mp3’
    media_content_type: audio/mp3
    entity_id: media_player.mini_nour
    mode: single

Related to this older thread…

Looking to confirm behavior or scripts in single mode for an automation.

Basically the opposite of the above, I have 3 scripts that I call directly from 3 sequential actions within an automaton. Does each script need to fully and successfully execute before the automation proceeds to the next action?

For example:
Script 1 - pass
Script 2 - error
Script 3 - will not run

Would running them in parallel prevent any issues? What happens if one of the 3 does fail, will the automation stop in this case as well? I want them all to run regardless of whether or not there is an error within one.

Thanks!