Wait and delay confusion

OK so I feel a little silly right now as I am sure its obvious.... however I don't think I have grasped the idea of wait and delay in rule machine. Ignore the namings as this is just a trial.

I send a http get request from an esp8266 to maker api that flicks a virtual switch off and on (this is the trigger). The idea is that the kitchen light gets turned on, then there is a wait for 2 minutes beore continuing. If there is another event (http) the trigger retriggers the actions again so the kitchen light off action is never run until the trigger doesn't re-occur within 2 minutes of each other...

I thought this would work but it appears the actions stop at the wait for events elapsed time, and the light off action never occurs even after a trigger isn't received again (the trigger event stays on).

If I change the wait to a delay then the trigger starts the actions again every minute still, however it appears the delay doesn't get cancelled so the light gets turned off after 2 minutes even if the trigger occurs again..

Confused

"Wait for Event" is fairly new, so it might be harder to find examples using it. You can read more about it here: Rule 3.0: Wait for Event (this was for the previous release of Rule, but the same more or less applies except that in Rule 4.0, all rules are more or less what triggers used to be and "truth change" isn't a thing anymore). I'd say the highlight would be: "A pending Wait for Event is automatically cancelled upon [...] [the rule] being triggered or being stopped."

What you'll see most people do in a situation like your rule is use "Delay." You are correct that the delay won't get cancelled if that's all you do. The docs and the thread discussing Rule 4.0 have more information, but the highlights are this: the "Cancel?" flag needs to be set on the delay (or on the action with a delay), and you need to have a "Cancel Delayed Actions" action somewhere, which will cancel anything previously scheduled that has this flag set. In your case, I'd probably do that at the beginning of your actions (or after "On"; shouldn't matter too much), you'd use "Delay" instead of "Wait for...".

That being said, I don't see why your rule doesn't work as-is: since you only have one event in your "Wait for events," it should effectively do the same as my "Delay" suggestion. A re-trigger will cancel this wait and restart the actions, but that sounds like exactly what you'd want. If you click the "gear" icon in the top right of your rule while this wait is counting down, do you see any "Scheduled jobs" listed in the table towards the bottom?

1 Like

Ahh OK. I tried the delay and had the cancel at the start but.......... I didn't click the cancel option in the delay action. It now works. Thanks you.