Private Boolean

So I think I've got a pretty good handle on Rule Machine and how to utilize it for MOST of my automatons.....but I've been following a few threads that discuss "private boolean" and I'm curious to find out more. I've read the RM Doc on the website but it didn't really help me understand what PB is and how to use it. Can someone please explain to me like I'm 12 years old what PB does and how to use it in practical rule applications for Hubitat. Thanks!!

2 Likes

Private boolean is a simple variable that captures what the state of a rule is; Either the rule is true or false.

It allows you to change the boolean of any rule regardless of the conditions set in the rule. So, let's say that you have a rule that has the conditions of Must be between 06:00 and 11:00 AND contact sensor 1 must be open. In the real world, it's 13:30 and contact sensor 1 is closed. So, this rule would evaluate to false. However, using PB, you can flip that rule to true for the purpose of running it from the rule you are calling from.

I hope that makes sense.

1 Like

That's not how I'd describe Private Boolean....

I would have probably said something like...

Private Boolean (PB) is part of the set of features to allow Rules to be combined/cascaded/work together.

PB is a switch that exists in each and every Rule that can be manipulated by any Rule. However, PB must be enabled for that manipulation to do anything. :slight_smile:

Under Restrictions, down at the bottom, is one of these:

43%20AM

It is disabled (PB is ignored by this rule) by default. PB is also initialized to be True. (Which is what the [true] in the screen cap means) Therefore, enabling PB only, does nothing. It's true, and true means the Rule gets evaluated because of it's events.

When PB is enabled, and something sets it false, that Rule is shut off... as if it got deleted. Set that PB to true again and the Rule will function as intended. A Rule can manipulate it's own PB, or the PB of another Rule.

Imagine a rule that turns on a light from a Motion sensor. Now imagine you want that to work only on school days, unless you override it with a switch.

One Rule to do that is kind of hard because "school days" has to be weekdays minus all the holidays kids get (and that I don't.) So you need a rather large rule just to figure out if today is a school day. But once you have THAT rule working.. add in the override switch and it can be used to True/False the motion/light Rule's PB.

9 Likes

Yeah, MUCH better. :smiley:

:slight_smile:

PB is very powerful... and you know the old saying...

"With great power comes great confusion."

no, that's not the old saying.. but it probably should have been. :smiley:

2 Likes

Ha! You should copyright that though as that's 99% true with dealing with home automation! :slight_smile:

Bruce has a recent example here:

Of using PB within a single Rule.

1 Like

Thanks guys.....This helps, although I think I just need to create some dummy rules and play a little on my own to see the results. I might be back with more questions, but in the mean time I'm off to play with PB! Thanks again!

I always think of PB as an OVERRIDE/PERMISSIVE.

If PB=false (and used as a restriction) the rule won't execute no matter what the other conditions do.

If PB=true it will allow the rule to execute, if the conditions warrant, but it does not actually force it to execute itself.

5 Likes

You can also use PB as a Condition or Trigger Event (wouldn't do this AND use it as a Restriction in one rule).

As a Condition, you get some added flexibility for true and false actions. This is usually done in conjunction with some other rule that is setting the PB.

3 Likes

So many twists.....we need a Youtube Hubitat Instructional Series on PB!

6 Likes

I'll 2nd that.

2 Likes

I've been using PBs to save the status of devices that don't have "toggle" capability:

On trigger
IF PB=false THEN
PB=true
turn device ON
ELSE
PB=false
turn device OFF

1 Like

Soooo, a year later ā€” have there been any videos made on Private Boolean, its uses and how to examples?

1 Like

I have just started looking at this, but to me, it seems that private boolena, is just a simple variable. Instead of having do define a new boolean variable, it seems, each Rule comes with an inbuilt private variable of boolean type. Just like any other variable, I might use this to capture true/false value.

This is correct. Originally, RM only had this one variable. It can be set by other rules, or a rule can set the PB of other rules. It starts out true. It can be very useful for things such as preventing a rule from being re-triggered while it has repeats and delays pending. This is done by creating Predicate Conditions that PB is true. Set PB false as the first action of the rule, and set it true as the final action.

3 Likes