Nested Parenthetical Sub-Expressions

Is there a guide for beginners anywhere to help explain what Nested Parenthetical Sub-Expressions are and best practices for their use in rule creation.

I'm not aware of any Rule Machine-specific guides, but the parentheses here mean more or less the same they do in traditional algebra (though technically this is Boolean algebra), but if you're not a math person, hang on and it should still make sense. :smiley:

By the above, I just mean they help define the order of evaluation. By default, this evaluation will happen left to right with equal precedence for AND, OR, and other operators (except NOT, which attaches to the element directly next to it--where "element" is usually a single item but could also be something in parentheses, and then it applies to that entire expression).

So, if you have something like:

Motion 1 is active AND Contact 1 is open OR Contact 2 is open is equivalent to this:

(Motion 1 is active AND Contact 1 is open) OR Contact 2 is open

...and, as such, will evaluate to "true" only if both motion 1 is active and contact 1 is open; or contact 2 is open; or both. If you want it to evaluate to "true" only if motion 1 is active and one or both of the contact sensors is open, then you'd need to write it like this instead:

Motion 1 is active AND (Contact 1 is open OR Contact 2 is open)

With nested expressions, it's the same idea, just with more parentheses, which allows you to create more complex conditions. Things inside parentheses get evaluated first, as always. You can make conditionals that are arbitrarily complex, as needed according to the logic you need to make your rule do what it wants.

Again, I'm not aware of any RM-specific guidance having been issued on this topic. But like with any part of any rule, I think simpler is better--and here it really helps because simpler conditions are easy to edit and less error-prone to create (and why would you make something more complex than it needs to be?). But if you need to do it, you certainly can!

1 Like

Maybe if you give a short explanation of what you are trying to accomplish, someone will have a suggestion how to make it work or give examples. Don't describe it in terms of what the rule should be structured like, just a brief sentence or two what should set off the rule (trigger), and what should happen when it is triggered.

E.G. "I want the bathroom light to come on when the door is closed and there is motion active".

1 Like

I figured it out thanks for the responses

Download the Hubitat app