Private boolean question

So...if I'm understanding the private boolean deal, each rule can reflect true or false based on whether it's active or not. Then, that can be used in other rules as a potential condition/trigger (if this other rule is NOT running, do this, else exit rule). Where I'm getting confused is if you have to make that a part of each rule. I've read that the boolean is activated but I've also seen where you have to make it a first and last command (or something like that...once triggered, set boolean to true and do stuff...).

I guess my question is, if I want other rules to not conflict, should I be making every rule set itself to true at the beginning and false at the end...or is there another way? Hopefully that all makes sense.

Private Boolean is a feature of RuleMachine that dates way back. Once upon a time, it was the ONLY variable.

I'd suggest you leave it alone because it's default is true and that's already what every running rule uses.

Each Rule has it's own unique Private Boolean. It gets initialized to True and therefore a newly created rule will run. Any rule can alter the Private Boolean of any other Rule and this used to be the only way to 'cross connect' rules. Now of course, we have Hub Variables as well.

If you have no active need for Private Boolean, you can ignore they exist. Do nothing and everything will work correctly.

In use, mostly you would set it to false, do something, then set it back to true. For example, Rule A would set Rule B's Private Boolean to false, preventing Rule B from running. When Rule A (or Rule C, D or E) run, if the conditions are right, it sets Rule B's Private Boolean back to true and Rule B will run the next time it's supposed to.

That's not exactly correct I fear. It's kinda the cart before the horse... Active/Inactive is not controlling Private Boolean... Private Boolean controls active or not.

You don't have to touch Private Boolean until you have a need to use it for a specific circumstance... I don't have any rule using a Private Boolean anymore. In other words, none of my existing rules need to grow complicated enough that Private Boolean needs to be used. A long time ago I used it, but eventually found I was using them more as a 'cool factor' than any giant need. :slight_smile:

This is not correct. PB has nothing to do with whether or not a rule is active. It has whatever use you put it to, and doesn't have to be used at all. One potential use is to prevent rules from running more than once instance at the same time. This could happen in rules that have delays, that get triggered again while the delay is pending.

If you don't know what to do with PB, ignore it.

rather than just ignore something, I'd like to learn it. That's why I'm asking.

I have one rule (rule A) that I want to run as long as rule B isn't running. If B is active, don't run A, If B is inactive, run A. It works based on rule A checking the PB of rule B when A is triggered. I may not understand it, but I got that one to work.

I have several rules that somewhat conflict (for lack of a better word) with each other. Small rules that I would like to default to bigger rules if they're active. I was just wondering if there is a better/easier way to make the bigger rules show as active.

Thanks! It's taking me a little bit, but I think I'm starting to get a basic understanding of it. I just had it flipped in my mind. I'll start looking at it from the PB controlling active or not stance. That will help greatly I think.

It may be a situation where I don't need it, but don't see another way right now. I have several small rules that can run when triggered unless a larger rule is running. I want the small rules to check the status of the larger rules and run if they aren't active. Can you suggest a better way without PB? I'm new but I'm trying to learn as much as I can. I love the possibilities of this.

Be careful about what you mean by "isn't running". Rules only run for hundreds of milliseconds. A rule with delays may exit waiting for the delay to finish. These can be 'caught' by setting a variable as the first action and setting it back as the last action, where "running" means the rule is somewhere in between the first action and the last action.

PB is just a Boolean variable associated with each rule. Hub Variables are system wide variables, that can be set or tested in any rule.

1 Like

Private Booleans (PB for short) are powerful tools. But like Channel Lock pliers make poor hammers, PB isn't for everything. RMv5 is much more powerful than RMv2 was when I started with Hubitat. It's another way of saying there's more tools in the box. RMv2 came with hammers, RMv5 comes with quite a few more including those channel lock pliers I mentioned. :smiley:

As @bravenel implies, look at your rules with delays or waits. Those are the ones where multiple instances could occur and although multiple instances aren't the explicit problem, what those rules are doing MIGHT be a problem. The same rule running 2-10 times simultaneously could cause unexpected results. Laundry monitoring comes to mind.. you get power reporting events, and if the reporting device floods the hub because the granularity is too low, then the Rule watching for power above or below X to send a Notification will get triggered a zillion times too often. Usually those rules have a delay to filter out transient power fluctuations mid cycle. We say, "OK, announce Washing is done when the power is below X for 2 minutes." If you got 30 power reports in those 2 minutes, you might have 30 instances of the rule "running" (each is waiting 2 mins, so not actually running in the sense of consuming cpu) and will all actually run when the 2 mins expires. Who needs 30 Notifications ? :slight_smile:

Rules running multiple times is one use for PB and nowhere close to the only, but the example is easy to describe.

I made a post, and now I am wondering if I know how PB works. Just to be clear, if a rule's PB is false, the rule is not paused or somehow prevented from running.

You can write logic into your rule to check the status of the private boolean and then do desired actions accordingly. But in and of itself whether or not a rule's PB is true or false has no automatic effect on the rule, unless you defined the logic within the rule.

Is the above correct?

could look to use a global boolean. when rule A starts, set the GB to true. when rule A ends, set the GB to false.

in rule B, have a statement, if GB = true then exit

this way as long as rule A is active, rule B won't run

that's correct. by itself the PB has no effect. if you change it in the rule, or have an action to do something different based on the state of the PB, that is only impacting that one rule

sorry to post so many times...to give some perspective on PB:

i had a rule that was triggering relays to activate a remote to control my blinds. i had a private boolean go to TRUE when i started. this prevented multiple instances of that one rule from running simultaneously, thus prevent misfires of the remote. when i started the rule, i checked the state of the PB. if it was false, i then set it to true (indicating i'm starting my main rule). when i got to the end of my rule, i set it back to false [i no longer have this check in my rule since i've since replaced the relay/remote with a bond bridge]

Thanks, I figured as much, since I use private boolean in some rules and they work as desired.

would need more insight into the smaller rules to see how they can be consolidated/combined

This is good info! Thank you all for contributing.

Maybe the specific rule examples could help to make sure I understand it.

Our bathroom has a shower in the main portion and a separate (small) toilet room. Both the shower and toilet have a fan above them.

Rule A says when the toilet light turns off, IF the toilet fan is running, wait 7 minutes and turn off the toilet fan.

Rule B says that when the bathroom timer turns on (virtual switch), turn. on toilet fan and shower fan, wait 20 minutes and turn off both fans.

The problem I have is that if rule B is running and someone turns off the toilet light, it activates the 7 minute timer in rule A, killing the toilet fan before rule B finishes.

I have set the PB for rule B to true while running and false after the wait event finishes. And I wrote in a condition for rule A that if PB of rule B is true, exit rule. It seems to work as desired.

Is this a “proper” use or would the hub variable or global be a better use?

you could even use your VS (virtual switch) as that marker. in rule A, when the toilet light turns off, check the state of the VS. if it's on, exit the rule. if it's off, then wait 7 minutes and turn off the fan. in rule B, wait 20 minutes, turn off both fans, set VS to off

1 Like

I thought about that, but that requires me to write another line in to turn off the virtual switch. That may be easier though as opposed to writing more stuff about PB into other rules. :grin:

Right now I have all the virtual switches to enable auto off after 5 seconds so they’re just used as a trigger.

Just a quicky
I want to test the state of a Private Boolean of another rule.
I thought this would be easy but I can find how to define the condition.
It seems I can only test the state of the Private Boolean in its rule.

Does this make sense?

You can only set the state of Private Boolean from another Rule; you cannot read it. If you want that functionality, you'll have to use a hub variables instead, which you can read and set from any Rule (and an increasing number of apps).

2 Likes

You mean something like this? First rule is to determine the washer is running or not. I did it separate from the main rule for simplicity, and to be able to reuse the logic in multiple rules. Second rule takes the PB of the first, and does whatever actions.

This is Rule 4.0 (Legacy) so I am not sure if this does work in any newer versions. The newer hub variables might be the way to go with newer versions. But I didn't want to rewrite a working rule so I haven't tried either Rule 5, or variables.

Thank you