Run a conditional action if it has been a certain time since the last time it was run?

Hey all,

I have a rule I am working on that does a bunch of stuff, and I have it triggered to run at random times (based on when other variables are triggered). I have one set of tasks that I don't want to run every time the task is triggered...just once every 30 minutes or more.

The only thing I can come up with is I have created a time variable and called it something like "Time since updated", and set it for right now. Then I created an conditional action that is set to run between the times of that variable plus 30 minutes and that variable plus 120 minutes (or however far in the future you want to put it). Is this the best option? The problem with this, that I can see, is if I have a power outage for more than 2 hours (or however long into the future you set)...or if your trigger doesn't fire in 2 hours (or however long into the future you set), then you will miss your window to update and it will never run again.

Is there a way to set the time variable and then just set a conditional action to look for the current time and see if there is more than 30 minutes difference?

ETA: Ok, looks like I can start the task off by setting the current time to a "current time variable", and then set another variable ("Time for Next Update) for current time + 30 minutes, then run a conditional action to check if current time > Next Update.

That would be the way to do it for sure, but beware of having a single rule do a bunch of stuff, you might want to have multiple rules instead as it is easier to debug and manage. One thing you can also do is have separate rules for smaller tasks and have a master rule that fires them based on time or whatever trigger you want.

Generally I would accomplish this by having a Required Expression that requires the Private Boolean be false. Then as the first actions in the rule:

  • Private Boolean true
  • Private Boolean false (delayed X minutes)

...then whatever the rule is actually supposed to do.

Thanks for the responses. I don't know enough about Private Boolean to understand your suggestion, but I'll do some reading.

There is a section about variable and private booleans about 3/4 down, can't give a direct link to that part because the software they use for the docs does not have direct links to parts of an article :frowning:

Thanks for the article. I have a rule that fires randomly but need part of the rule to run only if it has been n number of minutes. Trying to understand when/why I would use the PM vs using a variable. Maybe playing around with it will help.

Example Rule:
Collect attributes from Device, then
Has it been 60 minutes since you collected the special attributes? If yes, collect the special attributes.
Continue on with the rest of the rule

Then you'd just use the Private Boolean in the condition gating that part rather than the Required Expression for the entire rule.

Thanks. I guess that's what I don't understand. I'd need some condition to trigger changing the PM. The PM doesn't skip any steps, it seems. In fact, doesn't it add a step. I still have to create the condition. Then the condition can just run the sub rule as opposed to the condition changing the PM and then the PM allowing the sub rule to run. Again, I admit I am over my head here.

What about a wait for 30 minutes cancellable at end of rule and if rule runs again just cancel it.

The wait will be cancelled automatically if the rule runs again before the wait expires.

Thanks for the suggestion, but this rule will be almost guaranteed to run more often than 30 minutes. The only time it would not is if there was a power outage. So, if I am reading your suggestion correctly, the wait would always be cancelled out and would never run.

1 Like