I'm pretty sure hubitat rule machine will run a rule concurrently/in parallel by default but thought I'd ask to be sure.
If a rule is triggered by a temperature change and contains one or more delays, what happens if the temperature changes again while those delays are still active? Do the rules run in parallel by default, allowing the first instance to complete its full sequence even as a second instance begins?
In most of my rukes, I use 'cancelable' delays and a 'cancel delayed actions' command at the start of my rules to ensure only the most recent trigger finishes. The first instance being cancelled wherever it was up to.
However, for this project, I want to ensure the first instance completes regardless of subsequent triggers. Do I need to manually block the rule from re-triggering, or will it naturally run in parallel without the first instance being interrupted?"
Only way to make sure that a rule will not run again is to set the private boolean to false on the first line of the rule and then set it to true on the last line of the rule. Then you make the private boolean as a required expression. This will ensure that once a rule starts, they is no way that another instance of the same rule can start until the first one has completed.
As for the delayed action, you must really use the delayed action action, not just use the checkbox available on many actions within the action, these will complete the rule and run in the background when the delay is up unless it was cancelled.
Check the delay section in the docs of rule 5.1...
Note that if you use a « wait » instead of a « delay », the rule will automatically cancel the delay and all subsequent actions when it is re-triggered while in a wait state.
Also, running a rule in parallel is not recommended as it might have unintended consequences.
I've used booleans to block a rule running again, but I didn't put a required expression in. Instead I used an if statement that surrounded the rule. I'm thinking now that the better practice (and one less line of code) may have been the required expression. I may not change my current rules but will use that in future.
Edit: Seems required expressions only see the global variables, not local. I'm sure that is done intentionally due to how required expressions work.
Hmm I've only used wait commands when waiting for an event to be true. Maybe I need to rethink my uses of delay and wait.. I've only been using hubitat for many years
The “private Boolean” is a special beast. Private to the rule, but can be controlled much like a hub variable. You can control another rule’s private variable.
Oh so a Private Boolean is different than a private variable that I set to 1 or 0. Yes I've been using a variable like a Boolean, but instead it's a 1 or 0.
Maybe it's time for me to reading these two topics a little better. I admit I've just used hubitat rule machine, with not a lot of reading the documents that they have spent much time creating
Each rule can have only ONE “Private Boolean”… its own. You can create your own Boolean variable(s) that will also be private to the rule but they won’t have the special ability to be controlled by other rules.
Its use in Reqiured Expressions is a “practice” aided by the fact that it is pre-created for the rule.
Another tidbit of useful information that I didn’t know about for quite a while.
When viewing the rule for editing, etc., you might notice the value(s) of local variables looking “purplish”.
If you click on the value. And it’s Boolean, it will change from true to false or vica versa,
Other variables will open up for editing.
Nice for debugging or flipping that Private Boolean that got set wrong.