Create rule w/two repeats, and then restarts?

Wondering if I can create a rule that does the following.

  1. Trigger = plug turns on
  2. Starts first repeat while that ends when a condition is met
  3. Starts the second repeat while that ends when condition is met
  4. Keeps doing the first repeat/second repeat loop until a condition is met (e.g., switch turns off)

Main question I have is getting from step 3 (when the second repeat ends) back to the restart the first repeat and then go to the second repeat again, etc., and going through the two repeats until the switch turns off in step 4. Not sure how/if I can do that.

I suspect I may need to just create two separate rules w/one repeat in each, and have the first call the second and the second call back to the first to keep the two repeat while loops repeating until I want them to end.

I would do this:

While Switch is on
      While first condition is on
            First Actions
      END-REPEAT
      While Second Condition is on
            Second Actions
      END-REPEAT
END-REPEAT

If you want either of the repeats to end when the switch is turned off, then add that as a condition to those two as well as the initial one. Makes sense?

2 Likes

I think so - just don't see how the rule will "restart" at the first repeat after the second repeat ends. Is it going to restart at the first repeat if the switch is still on? The behavior at the end of the second repeat is what I'm not sure of.

Oh - just noticed that above is a nested repeat, which you aren't supported IIRC. So wouldn't work due to that.

1 Like

Oh? I didnā€™t know they werenā€™t supportedā€¦? You could instead, within an if condition, call the rule.

Can't you call Run Rule Actions from within a repeat ?

Here is another way to create a loop. Right now you will have to add an EXIT at the end due to a bug. The next update will fix this.

testhubloop is a hub variable.

Thanks, I'll take a look at that. I generally prefer to use the Repeat function since I already have some understanding of its working, but options are good! :slight_smile:

7 posts were split to a new topic: State Machine discussion

The solution that @Sebastien posted would work, but for the problem of nested repeats. You can't nest repeats within a rule, but you can accomplish this with multiple rules, each with its own repeat. Logically nested repeats, if you will. For @Sebastien's example it would be possibly three rules.

2 Likes

Don't want to re-start the state machine discussion in this topic, but wanted to note that I am kind of intrigued by this approach for my automation, and may look into it. Thanks for the suggestion.

As Bruce notes, head over to below if you want to talk more about state machines in detail... :slight_smile:

2 Likes