Repeating Actions Examples

Does anyone know of some good examples on creating while loops? I've done a few, but they seem to be unpredictable. Sometimes they just loop endlessly, even though I can see the statement has been satisfied. I can't really find any cut and dry examples.

Could you give a quick example of what you want to do? Maybe even post a screenshot (not a copy paste) of the rule(s) in question.

This seems unusual to me that you would be using this very often. I don't think I have ever had to use one. Maybe there is an alternative way of accomplishing what you are trying to do?

Here's a thread I refer people to often. The goal in this case is notifications, but the information on how repeats work (and can be stopped) is the same: How to get Repeated Notifications using Rule Machine

I confess that I don't like repeating rule actions and avoid them whenever possible. Sounds like I'm not alone. :slight_smile:

1 Like

I basically try to use it when I want a lot of confidence that the rule has done what I wanted it to do. With this example, sometimes the last step (lock virtual garage door lock) never gets completed, I assume because the rule is stuck repeating in the loop somewhere.

I have also noticed that with this rule operating, the garage door plug will be randomly cycled on then off a couple times a day, which is very concerning because it's hooked up to a relay that has opened my garage door in the middle of the night unexpectedly.

edit: I watched the logs, and whenever this is activated, it sometimes just gets stuck constantly repeating END-REP and Off: Garage Door Plug (the one within the loop).

Do you want to stop when the switch turns off? If so, try a simple conditional (you can see an example in the post I linked to above) rather than a "regular" one. I don't think the "full" conditional outside the repeat will function as any sort of check once you get inside the repeat (so there's nothing to stop it) given that it's completely outside and you have nothing else to trigger your actions list to run.

How quickly does the plug report its status to the hub after its state changes? You may want to add a delay before the If statement to be longer than the average status change time so the If statement isn't True each first go around. Same applies to how often you do the Repeat. You might want to move that to something like 10 seconds.
"Be careful not to make this interval too short, as you can consume your hub CPU resources by repeating too quickly."

Regarding your garage opening at night, what outside this rule is setting the Virtual Garage Door Lock to unlocked? You need to look at that closer because as you know, even when the door is closed, cycling the plug will just open it even if the rule thinks it is closing it.

I use a contact sensor in conjunction with a plug to control my garage door. So an Open rule will only trigger when the contact is closed and vice versa. I have never once had the door do something other than what it should have done. Also, if the contact is open for more than the time I set it for, the garage door will automatically close. If you do not have a contact sensor on your door, I would highly suggest you add one. Hope this helps.

This does not answer your repeat question but I just wanted to give you an example of using the garage door sensor along with the plug. I just moved mine over from ST yesterday so here is my Open rule. "Garage Door Opener" is just a SmartThings plug. The sensor is a SmartThing Multi sensor which has a Garage Door option that opens and closes based on position instead of having to use an actual contact. You just let the magnet hold it to the door and you are done!

One last comment on the opening during the night part of your statement, If you are really concerned about that, you can start off your Conditions with a time check to be between 10:00 pm to 6:00 am or whatever you want and if that is true, then "Exit Rule", That may or may not work for you but would guarantee it doesn't open when you are sleeping.

I delay for 25 seconds and then check the status of the sensor which lets me know if the door reversed direction and isn't really open like this rule should have done. This gives it enough time for the door to fully open and stay there. The same logic is true for when I close the door. I can reliably know if the door is open or closed without actually looking at it this way.

1 Like

This is awesome, thank you...I do have one of the Gold Plated ZWave garage door sensors which seems to work quite well. I have been meaning to make my rules a little more encompassing like this, so here is a good place to start!

I'm still concerned about the plug itself, though. No matter what I do in Hubitat, if the Leviton Plug randomly turns itself off and on my garage door will open. I suppose I could write a rule where if it's after sunset and the door has been opened for more than 5 minutes it will automatically close.

Thanks for this. I thought you could use END-REP to exit the loop once the IF statement is false? If that is not the case, then is there any other way to use complex conditions to control repeating actions?

END-REP is used to enclose the block of repeating actions, telling Rule Machine where they end. It does not stop an in-progress repeat. Your example would be doable with a simple conditional, but there is an example with multiple conditions in the post I linked to above ("Stop Repeating Actions" inside a conditional inside the repeat is what you're looking for).

Okay last hi-jack but since you were interested, I thought I would share my Auto Close rule. You need to add an Override Virtual switch and you can add it to your dashboard. If you are going to be working in the garage and want to leave the door open, you activate the override switch so this rule will not close the door. HE is Event driven so this rule is triggered when the sensor changes to Open. This way you do not need to worry about trying to do comparisons on a global variable set in the Open rule and this also works if you had opened the door from inside the garage using the standard button on the wall. The door will auto close in 1 hour in this example but you just set that to your own needs. If you close the door sooner than the hour, this rule stops and sends the message that the auto close was not needed.

Thanks for this. I have switched to simple condition rules and things seem to be working much better now. My question to you is why would a more complicated If (Conditions) Then not work?

Thank you chipz. I am going to try some of these! I have paused my incorrect rule and noticed that my plug is no longer randomly opening. The way I had it, the rule was just repeatedly sending the 'off' command every two seconds for days at a time. This must have been causing some sort of erratice behaviour. I am hopeful that I can now trust this rule.

It would--you just have to do it like in the example, inside the repeat. :slight_smile: But if you're asking why it won't work outside, the reason is this: a simple conditional is a conditional on a specific action. In some sense, it is roughly equivalent to an IF THEN ... END IF block with only one action inside (the other difference is that the IF part can only contain a single condition). But when you apply a simple conditional to a repeat action, it's also a sort of check for that repeat to stop--something that's just not possible with the same syntax and a "full" conditional due to the fact that it isn't "attached" to any particular action but rather delineates a block of actions.