Hello,
So I am working on logic for my thermostat and I need to do some IF blocks that have multiple and/ or statements within them, I want it to flow like below, but I can not seem to find how to separate blocks of IF’s with an OR. I want the rule when triggered to evaluate a series of IF blocks and only execute actions when one of them is true.
IF MODE is 1
And cool temperature is 75
Or heat temperature is 67
OR
IF MODE is 2
And cool temperate is 70
Or heat temperature is 66
Then
Do these things.
Any advice? If I do this as one big run on, the rule does not seem to work for me…
Do you have a screenshot of what you have tried to create in Rule Machine?
1 Like
Seems like part of the issue is figuring out how to use the GUI. In that case, perhaps a video would be helpful. Here is one that's a couple years old now and for Rule 4.0, but the Rule 5.1 (current version) interface isn't that different with regards to conditional actions, so it will still be applicable:
Maybe it will help--what you want is possible in a single expression (combination of conditions, combined with operators like OR and optionally one or more sets of parentheses for precedence if needed). Their most complicate expression is a bit simpler, but same idea.
2 Likes
Or here's one I prepared earlier / just now:
You will want to use the IF-THEN conditional option. After you create your first condition, you get a drop-down allowing you to choose whether to use an AND or an OR between statements.
1 Like
Following on from @bertabcd1234 's suggestion about parenthesis, you will probably need something like this....
IF ( MODE is 1
And ( cool temperature is 75
Or heat temperature is 67 )
)
OR
( MODE is 2
And ( cool temperate is 70
Or heat temperature is 66 )
)
Then
Do these things.
2 Likes
It works perfect if the set of modes at the top are active, but the rule skips all actions if sleep is active, I’m figuring it’s nesting and not using proper OR logic
Yes, I wouldn't expect that rule to work the way you need it to. You need to use the Sub-Expression option when building up the conditions, similar to the text version I posted previously.
Note - In case you need to / want to clear the conditional actions, you won't need to re-create them, they will still be there for you to select in the list of existing conditions.
It always pays, I think, to use parenthesis (sub-expressions) in any language when using OR, it makes it more explicit in what is going to happen. I can never really remember what would happen when a list of AND and OR linked conditions are strung together.
2 Likes
Hmmm. Yes, that is essentially what I was suggesting, but see if you can get the first part of each IF inside the sub-expression... Not sure if you can.... Try selecting Sub-Expression as the first thing after beginning to add the IF-THEN action... Adding the mode in Day, Night, Dusk as the first part of the sub-expression.
I'd also suggest thinking about how the temperature conditions are likely to play out. You may need to include a operating state / mode condition as well. i.e. you don't want to be assessing the cooling set point when in heating, and vice-versa.
I was able to nest the entire thing in the sub expression. I will continue to flesh it out and test it, but so far it’s working as I want it to.
Thank you everyone!
2 Likes
Glad I happened upon this post, it's very helpful - I'd never noticed the "sub expression" before. Previously when I've had rules like that I've had to go back in to edit and insert parenthesis where needed, to get things working.
2 Likes