Totally Confused with Private Booleans & Rule Machine

I’m having a really tough time understanding private booleans. I’ve been going back and forth and spent almost a week trying to get everything to work. :grimacing:

I have a smart dimmer switch with smart bulbs in my bathroom and I’m trying to use motion lighting with a certain delay AND switch control manually with the switch when I need it to cancel the delay, but I just can’t get the booleans to work. I’ve spent countless hours reading on the forums and documentation, but I still don’t understand how they work with the IF statements. There was only one example in the documentation.

Really eliciting some help here. I’m totally confused. I’ve been reading my logs and looking at skipped actions. I’m just completely confused on where I need to place the Boolean and how to make button controller changes the boolean in RM.

It's not clear to me where the switch fits into this rule, so I assume there is something else to account for that. It is, then, also not clear to me exactly what you want this specific rule to handle, but here's my guess: turn on the lights when motion becomes active, then turn them off after a delay, but all only if Private Boolean is true? If so, as written, your "off" will happen even when Private Boolean is false--those actions are outside of the conditional that checks for this--so you'd need something like this instead.

IF (Private Boolean is True) THEN
  Dimmers per mode: ... (per mode levels here like you have)
  On: Bathroom Fan & Light
  Set Private Boolean False
  Wait for conditions: Motion inactive --> duration 0:00:30
  Off/Dim Lights (etc.)
  Set Private Boolean True
END-IF

(If you do want the "Off" to happen regardless, then....good job, and ignore me. :smiley: )

The goal of Private Boolean here is to basically make sure these actions run only once, regardless of how many times your trigger event (motion becoming active) happens in the meantime. Private Boolean is only special because it's built-in to every rule without you needing to create a local Boolean variable yourself, but it's otherwise pretty similar (except you can set it from other rules, unlike local variables, but then there are also hub variables where you could do this). [EDITED TO ADD: you can use Private Boolean for anything you want--it's just a variable, and like any variable, only does something if you use it somewhere, however you may want to.]

Before going farther, it may make sense to ask yourself: do you care to prevent these actions from running more than once? Without this "check" in place, if motion becomes active during day mode, then the lights will get set to 95%, and if motion goes inactive for less than 30 seconds and becomes active again, then lights will then...get dimmed to 95%, which they likely already are. So the only reason you'd really need to do this if you want to avoid sending "On" or "Set Level" commands to your device when it's already on or set to that level--which in most cases is completely harmless (and has no real-world effect)--or if you plan on manually adjusting the level in the meantime and don't want new motion to take it back to the settings in your rule. Private Boolean might just be complicating things here.

Some other things you might want to know about rules in case you don't that may help explain how/why all of the above would work:

  • any trigger event cancels all "Waits," so you don't need to worry about the wait/duration for motion inactive--it's cancelled, along with everything after it, and your actions start over with new motion (note: this is for waits, not delays, which behave differently)
  • trigger events are the only thing (besides manually running the rule actions or running these actions from another rule or the Rule Machine API) that make your actions begin "running."
  • not necessarily a problem, but "adjust by -100" is a bit of an odd action; if you want to turn off, the "Off" action should work, or if you want to perform a fade that the "off" action doesn't do for you, the "Set dimmer" action (which calls "Set Level" on the device) lets you specify a transition time, which most devices obey, and for most devices a "Set Level" to 0 is otherwise the same as "Off"--though, again, some devices may vary here and "Off" might be a safer choiec if it works for you.

Finally, I'm not sure I see anything here that the built-in Motion Lighting app or likely even Simple Automation Rules (which used to be called Simple Lighting if it gives you any clues as to the nature of the app's original featureset) could handle, so you might want to look in those first if you haven't already. Easier than writing a rule. :smiley:

4 Likes

I think it would be better if you would explain what you are trying to do, and when it should happen in non-rule terms. "I want the bathroom light to go on except when I double tap a switch" or something like that.

I found it to be easier to have Private Boolean separated out of the main rule. It makes it easier to write, easier to diagnose, and you can reuse the PB in multiple rules if desired. You certainly can have it incorporated like you did, but to me two shorter and simpler rules was far better than one convoluted one.

But to me, this looks like Motion Lighting (as mentioned above) could handle things much simpler than this rule. If you want lights to have a warning before going out, or to fade out, then I really like Lights On Motion Plus community app. It has some really slick features that I think Motion Lighting should have had. [RELEASE] Lights on Motion Plus (dim before off, remember individual bulb states, etc.)

1 Like

Can you explain why you have this set up this way? Its usually either a smart switch or smart bulbs.

I realize it has nothing to do with your question, I was just curious.

1 Like

Thanks everyone! I’m out running errands today, but I will assuredly get back to everyone.

I have a Zooz Zen30 Switch. Using the bottom button for fan and light, since it’s wired as one, and controlling the smart bulbs once the switch comes on.

That makes sense. Thanks!

Thanks!! I got it working.

Thank you!!! It’s working now.

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.