[2.4.1.152] Repeat Actions n Times issue[C8P]

Trying to set up a Repeat Actions loop and want it to run n number of times. The problem is that I am forced to also enter a time for the Done with Action button to appear. So, instead of looping 5 times without delay, the loop takes 5 unnecessary seconds.

Same with Repeat while Condition. I would think that the Repeat Interval option should be disconnected from the Repeat n Times option.

Is this a feature or a bug?

As I recall, that's how it works.

I've never wanted the loop to run "immediately" again, so I always have made sure the time exceeds the time it takes for the lines inside the loop to complete (to ensure it doesn't try to kick off again while lines are still running). Tbh, I'm not sure if it would or not--but I know that kicking rules off multiple times in a row can cause issues.

All repeats are time based. Thatโ€™s how it works. You can select one second. Imagine that without that you would lock up your hub, potentially in an infinite loop.

2 Likes

But if I choose Repeat 5 times, there would be no infinite loop. I would suggest the settings work as:

  1. time based loop requires a number of times
  2. number based loop shouldn't require a time. Time is "optional'. If time is entered, it would become #1.

I see a greater risk for an infinite loop with Repeat with Condition, if someone messes up and the condition doesn't change to break the loop. In that case, I would think the number of times would be required as a backstop. Still, I don't see why the time would be a required setting.

Um, think about it. What you are saying doesn't make sense. Repeat 5 times infinitely quickly? Really?

No, the repeat has to have a timing for the loop. This is not the same as a "For" loop in C or Python.

2 Likes

Well, not infinitely quickly but once the loop completes, start again without needing to wait. Aren't the steps executed in order, gets to the end of the Repeat, and then starts again? Or are all repeats executed simultaneously?

That explains it, then. I considered the Repeat more like a While or For in a scripting language like php or perl.

Thanks, but no thanks. It will remain the way it is.

You never said anything about your use case for this. In the past, every such stated use case turned out to be better served another way. This has been going on for years, and no one has showed a valid use case for what you are describing.

Oh, and by the way, if you put 10000 in for n repeats, you would lock up your hub for a long time. RM isn't going to police that. n can also be a variable, where the potential for damage goes way up.

6 Likes

Fair enough. It was just my suggestion. I should have said request, but either way, understood.

10,000 for repeats is way beyond me. I can't even begin to imagine how that would be used in home automation. My use case is very simple. I get a bunch of calendar events and some automation stuff happens. At the same time, a combined list gets sent to and stored in a device attribute which triggers a rule to do some reformatting and cleanup for sending a notification to the phone and/or email. HTML prettification was part of the goal, but that's not going to happen due to HE understandably stripping out tags for security purposes. So the more limited goal is the previous cleanup.

The rule doesn't know how many events are in the variable, and I discovered that each variable replacement step would only work on the first instance in the variable. So, each step was repeated 6 times for 5-6 possible events, just in case. 8 cleanup steps, repeated 6 times. It worked, but changes were difficult to maintain. Coming from a scripting background, it seemed a loop would simplify things.

I know other options are to write a driver, an app, or use webcore. Unfortunately, I am far from reaching that stage. I'm only at the "tinker with something that already exists and hope it doesn't break" stage. :rofl:

For my use case, 6 second delay is not critical, so it's not a hill I would die on. :grinning: If there is a simpler way to do the cleanup, I'm all ears.

Problem solved.

1 Like

An interesting thing I discovered today.

A "Repeat 1 time" never completes (it executes the items inside the "Rep-EndRep" loop, but never continues after that.

I only found this as I was (happily) testing the "Command Retry" in lieu of my coded Repeat loops--before I totally upended my code, I was just going to change the loop to "one time only". My workaround was to stuff a "Stop Repeating" command at the end. Just wanted to mention it as a very minor issue.

Works for me as expected:

or, fully defined:

So, it appears the loop ends--but the code afterwards doesn't execute.

image

But, it just dawned on me this is a "legacy" rule--so likely not worth fixing either. Sorry.

3 Likes

Yeah, I can reproduce this. Sorry, I wasn't paying enough attention before. There clearly is a bug. On it...

4 Likes

You asked about alternate ways to do this.

If you don't want the 6 seconds, don't use Repeat at all. Just copy/paste the actions 5 times. Those actions will run back to back with no delay at all. None of the overhead of Repeat.

Fix will be in next release. Check this out:

Screenshot 2025-04-03 at 7.59.03 PM

3 Likes

You should be able to set your repeat to 0.1 seconds.

2 Likes

Part of my learning curve with Rule Machine was defeating my computer science courses understanding of how programming works. Rule Machine looked enough like a programming language at first. But I kept getting frustrated when looking for "how do they do this? Oh they don't. Try another way" Or "why don't they let me do this" Then finally, RTFM...

5 Likes

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