Stop a Running Rule?

I think I know the answer to this but I’ll ask anyway.

Is there any way to stop a rule dead when it’s currently in a delay period? In other words, a rule is running and is currently in a wait state due to a delay action but during that wait period something else happens and as result I want to stop that running rule so it does not complete its wait and keep running.

In webCoRE this was the ‘Cancel all pending tasks’ command and it would override any delay/wait that was in progress.

My guess is I need to refactor my logic but I’m already in to three SharpTools Rules to cover the two pistons I had for this use case in webCoRE (I’ve been in circular logic/looping/rate limit hell trying to figure this one out).

I also have rules that could benefit from this. I’ve been thinking re-writing a lot anyway, just because I’ve learned a lot and know new things.

When I saw your post I instantly thought, I could do mine with a variable. After the delay, check the variable, if it hasn’t reset, keep running the rule. Might be a challenge as to how exactly enable or disable the trigger. But I think I can make it work :grin:

1 Like

Still struggling here. Every time I think I have it cracked the rule comes out of its ‘delay’ state again and keeps going :man_facepalming:

Well, I have one example running at the moment.
I have set my back door to turn the light on, when the garden lights are on. They stay on 5 minutes and go off. But sometiles I’d come back from the garage, enter and 2 seconds later the light turns off by the first run of the rule. Re-running the rule, starting with “stop the previous one”, would fully fix it. But I can’t.
So I added an If argument, the back door needs to have stayed closed for 4 minutes. If not, the light stays on for another 5 minutes.

A variable can help in using more and different triggers. But it takes some thinking. You’re welcome to share your use case, so we can help think about how :grin:

In my case I could use a boolean variable to create a loop. The 5 minute rule turns on the light the first time and sets the variable to on and a second later back off. Turning it on runs another rule, which turns the light off after 5 minutes when the door has been closed for 5 minutes, else flips the variable again, to run the rule again. So you kinda isolate the part you want to stop running and give it an external trigger to continue or not.

Only issue with exactly this would probably be the door wouldn’t be 5 minutes closed exactly 5 minutes after it was opened, so I’d give it another 30 seconds or so. Or tie it to the closing of the door. Which would require some more “coding”. You can achieve similar response with a virtual switch.

I also have a kind of alarm system and sometimes it gets triggered for wrong reasons. Simply stopping the rule, even with a button, would help. It’s tied to my garage doors and sometimes they don’t respond first time. Multiple presses on the button in my car, makes my system get a bit confused, setting the alarm when it’s not supposed to. Being able to stop all rules to continue would help.

1 Like

It’s fairly simple. At a point in time or when a virtual switch is flipped On I want to start a loop of turning on two LED strips with a random color, cycling every 30 seconds (‘Mood Lighting’) until a certain time or the virtual switch is flipped Off.

First rule I have handles the setting of a virtual switch for ‘Mood Lighting’ to On or Off according to set times.

Note that the Mood Lighting switch can also be invoked at any time manually from the SmartThings app, etc.

Second rule sets a variable for Mood Lighting to True or False according to the virtual switch state. This variable gets used in the third rule.

Third rule attempts to handle the actual color looping of the strips. The issue here is that if the rule is in the wait period (and it mostly will be) and the Mood Lighting virtual switch is flipped Off the rule does not cancel the delay and turn off the LEDs - it just keeps on going after the delay period ends.

I only see the variable going off with the switch, so it’s not really doing anything.

In your third rule, after the delay, you could make another if argument, if the switch or variable is on, continue, if it’s off, do nothing.

When the second rule sets the variable to False I want the the third rule to trigger and run the part of the flow that turns off the devices. I’m not certain yet if that happens (I think it does) but what I do know does happen is the flow that is in a delay state continues to run regardless.

You can put the last part of your third rule in the “else” part of the part that contains the delay.

Your second rule is not of much use, since it’s just copying the switch. Doesn’t hold much value.

I don’t fully understand the rules either.
When the variable turns on, it picks a colour and sets it to the devices, then waits 30 seconds and turns the switch on again. I don’t see it turning off anywhere. If I’m reading it correctly, it isn’t looping like you want?

I think what you want would be the following:
Trigger switch on or off.

If switch is on, set all your lights. Delay 30 seconds, if switch is on, turn off and on. (Retriggering to rule and looping it, if you turned it off, the trigger stops here)
For the first else, you can set the lights turning off.

For the first if switch, you can also use the event variable, which could help with faster execution.

Thanks, yes.

It sets-up the variables which are used as triggers in the third rule.

At the end of that delay the action to set the variable to True again actually re-triggers the rule again (even though the variable is already True) thus I get the loop I want. That works. What I can’t seem to do is break that loop when a delay is active.

I’ll play more tonight.

I do appreciate your thoughts and suggestions, thanks.

You could add a nested IF Condition after the delay to determine if you should set the variable to true again (else do nothing for that part of the flow).

1 Like

Thank you! That did it.

So simple and obvious but I couldn’t see it.

1 Like

How come in this instance the rule loops, even though the variable doesn’t change, it only gets set to the same value?
And in the loop every 2 minute topic, it won’t loop? I’d assume both would act the same.

‘State Stays’ for variables uses the timestamp of the change in the value for evaluating the state stays duration.

The language for the trigger in this thread would probably better be described as ‘value is’ rather than ‘changes to’ as it’s based on the triggering event coming in and doesn’t compare it with any previous state. Only the raw event itself is evaluated against the comparison.