How does Repeat Actions work

@bravenel, what if you have actions after the "End Repetition"? Do they only execute after the "while loop" is done? Here's an example:


So, in this example, would the attic light turn on
A) after the motion was inactive (up to 30 seconds after the motion goes inactive to be 100% accurate)
B) immediately after the first toggle of the closet light and then the repeat would continue to toggle the closet light until the motion was inactive?

If it is A, this is one of the functions I've been looking for in RM. WebCoRE called them "conditional waits". This isn't the exact same thing but it's a way to get most of the way there and get almost the same outcome. This could be really useful in Triggers or Triggered Rules where you don't have the benefit of the "Cancel on Truth Change" for the repeat.

Yes, anything after a Repeat Actions block happens after the repetition is over.

However, your example is very screwy, as the repeat starts again after 30 seconds, while the embedded delay is also for 30 seconds, so there is going to be overlap of what's happening. Why not just repeat every 60 seconds, instead of adding the extra delay?


Yes, you're right that would be the correct way. The reason I had the delay in there was because at first there were no actions in the repeat loop. I added the closet light toggle for demo purposes. Can i just have:

Another way to that would be the "until loop", correct?

This is what it should be?

What I don't understand is that the repeat action still requires that I put a time into it in order to save the rule.

It's the way Repeat Actions works. It repeats something every so often. It doesn't make sense to repeat anything in continuous loop. It seems as though you are caught up in the definition of how things get defined versus coming at it from the end result you want. Describe the end result you want, and I can show you how to accomplish it.

Trying to replace trigger events and conditions of a rule with conditional actions in an action is a mistake. That's not what they are intended to do.

@bravenel What I'm trying to get to is a "Wait Until". This allows you specify the order in which the triggering events happen to perform a specific function. Will this not get there?

Also, i added another example to my previous post based on your other response. Would that be the correct way to do that with the while loop?

One of the functions that I had that did that was when an outdoor motion sensor went active at night an outside light turned on. Then it waited for a door to open to turn on the inside light and then waited for the door to close to turn off the outside light. Now, I'm sure all of that can be accomplished using the rule Private Boolean but it's been too daunting for me to try and accomplish. Coming from WebCoRE, it would be a simple matter of selecting "Wait until...." but rule machine didn't have that. Now with the Until Loop, I thought that I could get it all done in one rule and not have to worry about the private boolean getting all screwed up.

That's an event. So you want to build a trigger or rule around that event. Rule Machine is event driven. You can't replace using events with conditional actions.

But isn't a "wait until" the exact same as an "Until Loop" just with no actions inside of the loop?

No. Events happen when they happen, and apps subscribe to events. The whole idea of Hubitat Elevation is to NOT be running code waiting for something to happen. That's why events drive what happens, so the CPU isn't spinning in a loop waiting. You're attempting to turn this into some other type of system, where everything is synchronous. But the essence of this system is that things are asynchronous. That's the beauty of it, and the challenge to understanding how it works. When something happens in the real world to one of your devices, it generates an event. Rule Machine, and every other app we offer, responds to those events to do something.

1 Like

Okay...I understand that. But you're saying that I can have an until loop that has actions but not have an until loop that doesn't have actions? Do you understand why I'm confused? That doesn't make a lot of sense to a layman like me. You've added the while and until loops to the RM documentation but now you're saying that I can't use them unless there is an action within the loop? Unless the loop is doing something? I must be missing something because that doesn't make any sense to me. If you don't want the hub waiting around to do something then why do you have the while and until loops in the functions of RM?

And thank you for taking the time to try and explain this to a dummy like me. I am understanding so much more...i really appreciate it.

1 Like

I didn't say that. You can do anything you want with them. But because of the essence of an asynchronous system, spinning the CPU waiting for something is a quick path to a dead hub. That's why Repeat Actions have a timer associated, to turn them into event driven things. In this case, the event is the timer. Remove the timer, and you just killed your hub.

While loops and repeat-until loops and repeat-n-times loops are tools for building sophisticated automations. The bring additional flexibility and power to RM. But, they aren't replacements for basic event-driven automations.

There are lots of possible examples of what these are used for. Make a chime sound every 10 seconds while a door is open. Send an alert every 5 minutes while some condition is true. Ring the bell 4 times for front door opening, ring it 3 times for back door opening, etc etc.

What not to try to do: Use a Repeat Actions in RM to wait for something to happen. Use a Repeat Actions or an IF-THEN action to replace a trigger event or condition of a rule. etc. These are actions to be run IN RESPONSE TO EVENTS that are the controlling mechanism of automations.


Okay...that makes sense. But isn't that the same thing as repeating a set of functions until a condition changes? I don't see how one is more of a resource hog than the other. For example, you have loop A chiming a bell every one minute until a door closes and loop B doing nothing but a 30 second delay until the door closes. Why is A okay to do but B not?

Because it is repeated on a timer, like every 15 seconds.

Both are repeated on a timer.

The way I see it one is potentially infinity happening when it just doesn't need to be until something else happens, the other is only happing for a period of time if or while something else happens but only every X seconds. Back to front

That's fine, but not reflective of understanding how the platform works. Why would you do it that way? Why not just trigger off the door closing?

Because I don't want it to happen EVERY time the door closes. Back to my previous example, I don't want the outside light to turn off if the door closes when I'm leaving...only when I'm arriving. So, the trigger for the sequence starts with the trigger of motion being active outside vs the trigger of the door opening.

Complex automations are only possible if you can control the sequence of events and allow for the next trigger to take place. Like I said, probably possible using rule 2.5 with PB but even thinking about it gives me a headache.

Why are two separate rules not the answer? Sorry, maybe I’m joining this thread too late to understand why that would not work?

In the simplified example, it would be. But what I'm talking about in the broader context is a sequence of event driven actions. The sequence starts, does A, B, and C then stops until X happens, then does D, C and E then stops until Y happens and then does F, G.... Doing all of that with separate rules enabled and disabled with PB is going to get VERY messy if the sequence is interrupted. If it's all in one rule, you have the escape based on Truth Change to the triggered rule at the top.
To me THAT is complex automation.

1 Like

Ok. I see. Well, we are just at the beginning stages of this capability. Given time I have no doubt @bravenel will be able to optimize how that function works.

You are wanting a WAIT for event action. I understand that. My advice is don't try to make Repeat serve that purpose.

1 Like