Is there such a thing as a For/Next Loop in the Rules Engine?
I'm looking to flash some external lights on/off in a loop for a set period of time. The Zigbee lights don't support flashing on/off so I need to do this manually, and I was thinking I'd do it in a For/Next Loop. Essentially something similar to this...
For A=1 To 1000
Lights.Switch = Toggle
Wait = 0.5s
A=A+1
Next
Try looking at the repeat action. I use it to test my light by toggling them each day. You can choose a number of repeats, which would be the equivalent to your A variable. You can also include a DELAY action. I'll get a screenshot in the morning if you need it.
Thank you - that really helps, stupidly I hadn't seen the REPEAT function!! One question - there is a toggle switch when creating a REPEAT function entitled "Stoppable" which I've enabled, I'm just unsure how I then intervene and actually stop the REPEAT function.
I can see that there is a separate function that allows me to Stop Repeating Actions, but it seems generic and doesn't ask me WHICH repeating action to stop? I figured it may well be generic and stop ALL repeating actions but that doesn't seem to be the case?
Your follow up questions are not something I have had to consider. I'll leave it open to others to chime in... or for you to play around with the rule yourself, before I call on some of the more experienced RM users here. I would expect the Stop Repeating Actions would stop anything within the Repeat -> END-REP construct (the whole rule in my case), and to be similar to the cancellable option for delayed actions.
If you want to run this at a nominated time of day, and that's the only trigger, then you could start by not worrying about the stoppable option. If you want to interrupt / stop the repeating rule, say with a button / switch / rule / etc, then I would suggest turning that option on and (without any knowledge of this) setting up a second rule triggered by that then stops the repeating actions in rule 1.
Thanks for this - I tried use the Stop Repeating Function but it didn't work (it doesn't actually ask me for a REPEAT function to stop, so I assumed it was a generic stop all repeating actions currently ongoing)??
Anyway, I ended up going down the route of using The Flasher from BPTWorld - excellent app, and does exactly what I needed (and more).
A purpose built app is typically a good approach, particularly when you have a developer like Bryan developing it, i.e. someone who is quite active and responsive to sorting out any issues or requests for changes. Good to hear you hear you have a solution.
The stop repeating function is, as youāve already sort of figured out, a generic stop for any currently repeating actions in a rule. The stop on its own will not necessarily immediately advance the rule to continue below the repeat loop as it will only prevent the process from repeating again when it reaches the end of the loop. So if you have a delay in the repeat loop, even when you stop the repeat, it will continue waiting for the delay to run out before proceeding through the code.
To force the code to immediately exit the repeat loop youād have to add a cancel delay action as well.