I live in an area with a lot of wildfire smoke. My air purifiers are set to turn on if EITHER AirNow or their internal monitors say the air is not good.
However, I am trying to create a rule which says if BOTH of the monitors CHANGE to good the purifiers turn off.
I don't want them to turn off simply because both are good, because I often have them on while using cleaning chemicals and the monitors don't pick those up.
I realize that they may not both change at the same time, so if 1 CHANGES to to good AND the other reports good that would also work, I just can't figure out a way to program that
Note: In this example, I happened to use two switches as my triggers and my Required Expression. I also used the same two switches in my Action. You would use your air quality monitor sensors as your triggers and in your Required Expression. IN your Actions, you would turn off the purifier.
It is better than the version I would have used, which is trigger on either, but nest the desired actions within a conditional block that required both to be on.
required expression combinedCategoryName !=Good OR aqiDanger !=Good
trigger combinedCategoryName =Good AND aqiDanger =Good
Because as you can see, the purifier thinks everything is great. As soon as I turn it off, it's going to get very nasty in here.
However, there are sometimes where AirNow combinedCategoryName reads as Good, but the purifier aqiDanger does not, so removing aqiDanger won't really solve the problem,
Triggers are events, not states/conditions. They do not have truth values, and thus cannot be ANDed. When a trigger event happens, the rule is triggered -- unless a required expression is used, in which case the expression must evaluate to true in order for the rule to trigger. So, required expressions are one way to control how a rule reacts (or doesn't) to a trigger event. The other, as mentioned by @aaiyar, is to use conditional actions.
On a related note, this part confuses me a bit:
The sensor can't be good unless it changed to good -- i.e., the state/condition cannot be X unless an event making it X previously happened. That event could be a trigger. But, again, events don't have truth values; they are just an instant in time. So, if you need to check states (beyond just knowing that the device is in whatever state you know one trigger event may have just resulted in), you'll have to use conditions somehow: conditional actions, required expression, etc.
Ignoring everything else that you want and ignoring the required expression feature since this can be done entirely with (I think) easier-to-understand conditional actions, something like this could work:
Trigger events:AirNow AQI combinedCategoryName *changed* OR Big Purifier aqiDanger aquDanger *changed*
Actions to run:
IF (AirNow AQI combinedCategoryName = Good AND Big Purifier aqiDanger aquDanger = Good) THEN
Off: Big Purifier, Small Purifier
END-IF
That's sort of a "classic" Rule Machine way of thinking. Required expressions are relatively new and probably could be used in place of some of this; I'm just having a harder time thinking of how the logic in that expression would need to work right now, and nothing I can think of would save you any work in the actions. (But this could be me just stuck in this "classic thinking...)
Okay yes! I think that is exactly what I need! Initially, I was hesitant to use changed because I didn't want it to turn off if the monitor changed from bad to worse. But I think this solves it perfectly! Thank you