WTH: Why no sequence action like parallel action in automation/scripts

Running stuff in parallel is great, but what if I want some tasks within a parallel action to be run sequentially. It would be great to add a sequential action to the UI (this can be done in yaml).

Example of parallel and sequential actions. What if I want to check the time for a specific action flow as a condition action that only relates to that parallel thread?

Make a script. Run that script in parallel with your other actions. Make the script sequential

Problem is, then Iā€™d creating duplicate scripts for actions. For example, I have a script for notifications. This turns on speaker zones, sets input and volume. But I donā€™t want to specify what notification sound or tts within that script. Iā€™d rather call the script from an automation, then send the tts after the script has completed. Perhaps this could be done with a template and somehow passing a variable from the automation to the script, but that seems overly complicatedā€¦

sequence can already be done in parallel actions, just has to be done in YAML.

Scripts accept variables that you can pass from the automation. No duplication necessary.

Easily done in your script service call from the automation using fields in your script.

A sample script using fieldsā€¦

some_script:
  alias: "Some Script"
  fields:
    some_variable:
      description: ""
      example: ""
   sequence:
     - if: "{{ some_variable == 'some value' }}"
       then:
         - do something

Calling the script.

- service: script.some_script
  data:
    some_variable:  "some value"
1 Like

You can put a sequence in a parallel action

Itā€™s explained clearly in the docs:

It is also possible to run a group of actions sequantially inside the parallel actions. The example below demonstrates that:

script:
  example_script:
    sequence:
      - parallel:
          - sequence:
              - wait_for_trigger:
                  - platform: state
                    entity_id: binary_sensor.motion
                    to: "on"
              - service: notify.person1
                data:
                  message: "This message awaited the motion trigger"
          - service: notify.person2
            data:
              message: "I am sent immediately and do not await the above action!"

Oh wait, you already knew, but you want it in the GUIā€¦

1 Like

Yes, added to the GUI. Shouldnā€™t be controversial right? Not everyone is a coderā€¦ would make this a bit more powerful/flexible.

True ā€¦ and probably why a programming concept like parallelism isnā€™t exposed in visual mode (an interface suitable for novices).

In addition to the Automation Editorā€™s limitations in visual mode there are several quirks when handling YAML. For example, it has a habit of quoting boolean and list values (thereby converting them to strings). It removes any YAML comments you may have entered and reformats Jinja2 templates to comply with its guidelines.

I mean I guess Iā€™m genuinely kind of curious to see how many votes this gets. Because youā€™re right, not everyone is a coder. But also would a non-coder ever pick parallel? :thinking:

Chicken or the egg I guess. I personally find Jinja2 templates confusing and unnecessarily complicated. YAML is ā€˜OKā€™. Itā€™s always nice to be able to write code and make something, but also nice to put something together via the gui in a visual view.

I personally like using node red and use function nodes to write more complex conditions, but tracing failures is a pain if you donā€™t enable logging on each line. Also, when it triggers something, it just gets triggered by the service and not an automation so sometimes it can be difficult to troubleshoot.

If you have put the effort into learning Node Red you can learn jinja with about the same effort.

Itā€™s nice that you have the choice though.

I use the GUI all the time except when I canā€™t, and I understand there are cases where the GUI just isnā€™t smart enough (yet) but not being able to pick sequence is just plain silly!

1 Like

The ā€œlikeā€ on my last post (@hldh214) brought my attention back to sequence in automations/scripts so now that weā€™re on 2024.4.x I had another look at options in the visual editor and I discovered a way to do it (which probably existed before) using repeat: with count: 1:

repeat:
  count: 1
  sequence:
    - service: ""
      data: {}
    - service: ""
      data: {}

1 Like