Running Tasks in Parallel so actions performed at the same time help

Trying to understand how the parallel action works. Do the items within the parallel action run in parallel or does the parallel action itself run in parallel?

What I’m trying to accomplish.

  1. Triggered by Entity State
  2. Notify Phones via push notifications (all in parallel)
  3. Toggle lights as well as do a time check then run script (would like these two actions in parallel), but I then another script only if the first script was executed. So that would be run sequentially in the time check parallel action to the light toggle.

This is easy to do in Node Red, but I’m struggling to put this into HA automations. Currently my automation runs sequentially, not a deal breaker, but not as nice as if I had the light toggle and speaker notification run in parallel, but the speaker notification requires a condition record.

Have a look at this automation where I have 4 different sequences running in parallel.

Parallel automation example.
###############################################################################
## Light - Adaptive Lighting Sleep Mode
###############################################################################
- id: light_adaptive_lighting_sleep_mode
  alias: "[Light] Adaptive Lighting Sleep Mode"
  description: "Turn on sleep mode lighting."
  trigger:
    - platform: state
      entity_id: input_select.occupancy_mode
      to: Night

    - platform: state
      entity_id: input_select.occupancy_mode
      from: Night
  condition:
    - condition: state
      entity_id: switch.adaptive_lighting
      state: "on"

    - condition: state
      entity_id:
        - input_boolean.occupancy_override
        - input_boolean.alarm_triggered
      state: "off"
  action:
    - if:
        - condition: state
          entity_id: input_select.occupancy_mode
          state: Night
      then:
        - parallel:
            - sequence:
                - service: switch.turn_on
                  target:
                    entity_id: switch.adaptive_lighting_sleep_mode_main_lights

            - sequence:
                - wait_template: "{{ is_state('light.bathroom_vanity_rgb_light','off') }}"

                - service: switch.turn_on
                  target:
                    entity_id: switch.adaptive_lighting_sleep_mode_bathroom_lights

            - sequence:
                - wait_template: "{{ is_state('light.dining_room_rgb_light','off') }}"

                - service: switch.turn_on
                  target:
                    entity_id: switch.adaptive_lighting_sleep_mode_rgb_lights

            - sequence:
                - wait_template: >
                    {{ is_state('light.bedroom_fan_light','off')
                        and is_state('light.bedroom_potlights','off') }}
                - service: switch.turn_on
                  target:
                    entity_id: switch.adaptive_lighting_sleep_mode_bedroom_lights

      else:
        - service: switch.turn_off
          target:
            entity_id:
              - switch.adaptive_lighting_sleep_mode_bedroom_lights
              - switch.adaptive_lighting_sleep_mode_main_lights
              - switch.adaptive_lighting_sleep_mode_rgb_lights
              - switch.adaptive_lighting_sleep_mode_bathroom_lights
1 Like

@jazzyisj

so like this:
NOTE: the two parallel actions run sequentially, then within the first parallel action the kitchen lights run sequentially but in parallel with the study?

alias: Testtest
description: ""
trigger:
  - platform: state
    entity_id:
      - switch.aiden_bathroom
    to: "on"
condition: []
action:
  - parallel:
      - sequence:
          - service: light.turn_on
            data: {}
            target:
              entity_id: light.kitchen_downlights
          - service: light.turn_on
            data: {}
            target:
              entity_id: light.kitchen_chandelier
      - service: light.turn_on
        data: {}
        target:
          entity_id: light.study
  - parallel:
      - service: notify.mobile_app_pixel_6a
        data:
          title: TEST!
          message: TEST Pressed!
          data:
            priority: high
            channel: doorbell
mode: single
1 Like

This seems to work. It would be good if in the visual editor if they added a sequence action. Similar to parallel.

1 Like

Hopefully coming soon → Parallel actions to run "blocks" of actions - #8 by tomas1 :crossed_fingers: