How to run services in parallel?

Greetings, I have an Automation calling a Script like this:

lights_off:
  alias: all off
  sequence:
  - type: turn_off
    device_id: 6ad5a3980a7763c6d294a2cde386f3a4
    entity_id: light.lidl_e14_w_light
    domain: light
  - type: turn_off
    device_id: dc8655f3e109a784dd6d9b89c789e7db
    entity_id: light.0x001788010940bf8d
    domain: light
  - service: script.turn_off_A
  - service: script.turn_off_B
  - service: script.switch_off_C
  mode: single

Both lights and A are more or less directly turned off. B should lowly fade out, so this should take like 15 minutes and C should wait 3 minutes and then turn off.

It works, but switching off B takes like 15 minutes (intentionally) and it seems that turning off C waits until then to start waiting another 3 minutes and then turns off the last device.

Is there an elegant way to start all actions of the Script in parallel and some end directly, some after 3 minutes and some after 15?

Thanks,
Fridolin

Use the script.turn_on service. Doing it this way does not wait for the script to complete before moving on to the next action. See: https://www.home-assistant.io/integrations/script/#waiting-for-script-to-complete

2 Likes

@tom_l

Thank you very much.

I first tried script.turn_off, but I’ve quickly seen that this makes no sense. Now I’ve changed it to:

lights_off:
  alias: all off
  sequence:
    - type: turn_off
      device_id: 6ad5a3980a7763c6d294a2cde386f3a4
      entity_id: light.lidl_e14_weiss_light
      domain: light
    - type: turn_off
      device_id: dc8655f3e109a784dd6d9b89c789e7db
      entity_id: light.0x001788010940bf8d
      domain: light
    #    - service: script.turn_off_A
    - service: script.turn_on
      entity_id: script.turn_off_B
    - service: script.turn_on
      entity_id: script.switch_off_C
  mode: single

It seems to work.

Thanks,
Fridolin

It’s the custom of this community forum to assign the Solution tag to either the first post or the best post that identifies the root cause and supplies a solution. In this case, it would be tom_I’s post because it identifies the cause of the problem and offers a way to correct it.