Understanding Actions in Automation

Hi!

I have a question about automations… If I have a loop action in the middle of other actions, the automation will run all the actions even if there is a “block” loop action in the middle or it will wait till the loop action is finished, then continue with the next action?

trigger
action 1
action 2
action 3 loop (until)
action 4
action 5

I try to understand these automations better, how they run, what is needed to break an automation or a loop action and so on…

Edit: besides the fact that I want to understand more about automations, I have a real case as well, which will help me in what I want to achieve… and what I wand is this:

Let’s say that I have a PIR sensor and a Screen on/off Switch. The PIR sensor will have the “detected” state as much as someone is moving in the front of the PIR (if I move one hour, the sensor will have the state “detected” for one hour), and the automation should be something like this

trigger - PIR state "detected"
action 1 - something
action 2 - something

action 3 - loop util Screen Switch is On
   - turn on screen
   - after and only after util repeat has finished, run the next action
action 4 - loop while PIR state is "detected"
   - keep screen on

action 5 - notification

The thing is that I don’t want action 5 to run untill 3 and 4 are finished.
I have an idea how to achieve this but I am curious about other ideas and of course, the first reason to open this post, to know more about automations.

Thank you!

Use the choose action. Not sure why you would want to “loop” an action.

Choose it will only run once the action, loop will loop it till you want…
But I found out by testing now, if you put a loop action in the middle, the rest of the actions won’t run till loop finishes…

Edit: And I think I done the automation, I used a loop until and a loop while after this, all good. Somebody would do this different?

Edit2 : This is how my automation is now

alias: PIR2Action - Computer
description: ""
trigger:
  - platform: state
    entity_id:
      - binary_sensor.computer_presence_pir_sensor
    to: "on"
condition: []
action:
  - repeat:
      sequence:
        - service: rest_command.computer_tablet_forced_motion
          data: {}
        - delay:
            hours: 0
            minutes: 0
            seconds: 2
            milliseconds: 0
      until:
        - condition: template
          value_template: >-
            {{ repeat.index >= 5 or is_state("switch.computer_tablet_screen",
            "on")  }}
  - repeat:
      sequence:
        - delay:
            hours: 0
            minutes: 0
            seconds: 10
            milliseconds: 0
        - service: rest_command.computer_tablet_forced_motion
          data: {}
      while:
        - condition: state
          entity_id: binary_sensor.computer_presence_pir_sensor
          state: "on"
        - condition: template
          value_template: >-
            {{ repeat.index <= 5 or
            is_state("binary_sensor.computer_presence_pir_sensor", "on")  }}
mode: restart


When PIR will detect motion, the screen will be on… then, the screen will still be on untill the PIR will stop being detected.

Edit3: I think I have answer myself to my question, but now I have another one :smiley: There is any solution to run an automation fully, without stop/wait for the loop actions? But without using scripts :smiley: No need something, I am just curious

How does this “Loop Action” look like ?, a “if/then” “if/then”“if/then” >infinitely . or a " template" executed somehow ( which in turn doing your “Loop”), unaware of the status of your Automation ?

Yes, I am aware how a loop action it is working, I just needed to find out if the other actions after the loop action, are running imediately after, no matter if the loop finishes or it will wait for the loop to finish. I found the answer meanwhile. Thanks! :partying_face: