Understand Repeat Loop

Trying to understand command Repeat (loop).

I want to do a simple loop and enumerate a variable

loop
variable +1
end loop

And
Is there "case" or do I have to use IF?
Case
variable =
variable =
variable =
End Case
If
variable = do this
End if
Many thanks

Have you read through the Repeat section of the RM documentation?

I have tried to find what these parameters are for. I just want to do a loop X times
I can't find it in the documentation. But would be happy to receive a link.

I don't really understand "repeat interval" and "repeat n times"
Maybe I'm a bit stupid?:slight_smile:

Time between repeats. I.e., Days/hours/minutes/seconds between each repeat. I have a laundry autmation that repeats a reminder that the laundry is done every 15 minutes until I open the door of the washer or dryer.

How many times you want the repeat to run. I have the laundry reminder set to 10 reminders...after that we're clearly either not home or don't care to deal w/laundry so I turn off the reminder at that point.

1 Like


We can say I want this loop to run 5 times and the variable to increment by 1 each turn

This example will run 5 times (every 5 seconds) and add 1 to the variable counter.

2 Likes

Thanks, will try some more. A loop is good to have. :slight_smile:

So, what if he just wants it to run X times or endlessly regardless of any time increment and stop it by placement of Stop Repeating Actions.

Let's say he has a set of actions in the rule that are spaced out over hours with Delays or Waits. The time increment is kinda confusing in that situation. One has to then sync up the Repeat time with the cumulative Delay(s) duration no?

I'm finding myself trying to relate this to the Do While construct but I'm not getting there.

Case in point....say you have a dual relay and want to cycle on then off between two colors of Xmas lights, first running one for 10 min, then off, and the second color for 10 min, then off, and back again to the first set...and do this nightly between two specific hours.

I thought the Repeat While would wrap this neatly but getting into it I had second thoughts.

EDIT: BEWARE I just kinda "cross-posted" on this subject as I just saw the exact use case elsewhere. See link below.

For repeat you don't need to define the number of loops but you do need to define the time interval.

Here's an option that doesn't use the Repeat action but will repeat

Required Expression:
Time between 6:00 PM and 9:00 PM

Trigger:
Time is 6:00 PM OR
Relay 2 is off

Actions to Run:
On: Relay 1
Wait for event: elapsed time --> 0:10:00
Off: Relay 1
On: Relay 2
Wait for event: elapsed time --> 0:10:00
Off: Relay 2
1 Like

I have the Required Expression in play for the Holiday span but didn't think to use it for the nightly time window. Like that.

So the repeating is by Relay 2 being turned off and the rule just being re-Triggered. I see.

Thanks.

Here's an option using the While loop and no RE:

Trigger:
Time is 6:00 PM

Actions to Run:
On: Relay 1
Wait for event: elapsed time --> 0:10:00
While (Time between 6:00 PM and 9:00 PM) Repeat every 0:10:00
    Toggle: Relay 1, Relay 2
END-REP
Off: Relay 1, Relay 2
1 Like

Yeah, another permutation.
We're derailing the thread a bit here but...

I was just in working your first example and I sometimes find myself confused selecting Switch Triggers especially with the options in the menu: SWITCH, PHYSICAL SWITCH, DIGITAL SWITCH.

I haven't yet gone to the documents to reacquaint myself of the differences in selecting one vs the other (the relays I am using show up in ALL cases). But one thing that is obvious in ALL cases is that the screen menu options once a layer lower infer triggering when the switch "Turns On" (or off, or changes).

The way you wrote the RE condition above you were just CHECKING THE STATE of that switch not hanging around waiting for the state to change. So, which to choose?

Physical Switch refers to someone manually turning on or off a switch device. Not all devices report physical events. Can your relay be operated manually? Digital is non-manual events. Switch can be either physical or digital.

The RE above is checking that the current time is between 6:00 and 9:00. If it is then the triggering event, either the time becoming 6:00 or Relay 2 turning off, is causing the actions to run. It's an important distinction that triggers are events and not states (or conditions). For the example provided, I would choose Switch for the Relay 2 trigger.

1 Like

Ah, thanks for the clarification. I neglect thinking "event vs state" often having not grown up in event based systems. So the in this case the very nature of turning off the relay in the code re-triggers the whole rule from the start regardless of what comes afterwards in the rule.

1 Like

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.