Running multiple scripts in parallel from automation no longer works?

I have an alarm setup that, upon being triggered, starts blinking some lights, producing noise and sending a notification. After updating this became sequential rather than parallel. The code looks as follows:

- id: perform_alarm
  alias: Performs the alarm action
  description: ''
  initial_state: true
  trigger:
    - platform: state
      entity_id: alarm_control_panel.home_alarm
      to: 'triggered'
  action:
    - service: script.alarm_make_noise
    - service: script.flash_alarm_lights
    - service: notify.alarm_alert
      data: 
        message: "🚨 *Alarm triggered!* 🚨"

What used to happen in the past is that the noise making started, and while noise was being produced, the lights started flashing, etc. The various scripts were executed in parallel. This several months ago, when I implemented the thing.

Now, after several HA updates after which I didn’t retest the alarm system (so I don’t know which one exactly broke it), it turns out to first produce the noise and wait for that to completely finish. Then it goes and blinks the lights, waits for that to finish. Then it goes and notifies. Obviously this is not what it should do, but I’m at a loss as to what change has caused this behaviour. I’ve tried marking scripts as “mode: parallel” on the off chance that that’s somehow related (from HA 0.113 release), but that doesn’t achieve anything.

How do I get the automation to merely start each script, but not wait for it to finish before proceeding, the way it used to be before?

Read this and then adjust the way you call your scripts (use the script.turn_on service.)

Aha, ok. That fixes it. Thanks.

1 Like

Hi, does the script calling another scripts via script.turn_on service need to wait for all the scripts called before terminating itself, or it may simply exit not caring about what the called scripts do and how they finished? (fire and forget mode)

No. You would have to call the scripts directly for that to happen. Read the link I posted above.

Well, let me re-phrase my question. I understand the difference in the calling modes, just wonder if there is any risk for memory leaks or rule to close what was opened linke with “begin-async” / “end-async” or “using” clause known from C# or similar.
Best
Emil

Not in single or restart modes. There are options for limiting the maximum queued or parallel runs. All covered in the page linked above.

There’s the script.turn_off service.

I have the same issue:

I use Alarmo for my alarm system. I have 2 scripts that are executed if the alarm is triggered

  1. Play a siren WAV file on 4 Sonos repeating in a loop until the alarm is disarmed
  2. Flash all lights (about 30 individual lights) in the apartment in red until the alarm is disarmed.

It generally works and the lights flash and the sound plays in parallel but what I notice is that the sound “stutters” or is somehow choppy. Also the lights don’t flash right away but take quite some time to start flashing.

Also when I disarm it takes maybe 15 seconds until the sound stops and lights go out again.

It all seems very laggy as if HA is completely overwhelmed. I run HA on a Home Assistant Yellow with a Raspi 4 board.

Could it be that it is a performance issue?

@hesspoint Did you solve this? I have the same issues…

I have given up doing this via Sonos. Never got it to work properly. Instead I am now using Alexa Media Player to play via my Alexas instead. But I have not gotten around to test it thoroughly for the alarm sounds. Overall playing any sounds or notifications on Alexa works much better than via Sonos