IF variable is anything other than these two strings THEN problem

I can do this with a few rules and virtual switches, but there's gotta be something simple in my rule that's wrong. Anyone with a suggestion?
image

So if this variable "SystemStatus" is anything but "Grid Status Pending" or "OnGrid" I'd like it to turn on Backup Mode... Works like a charm when "OnGrid" (i.e. nothing happens), but When "Grid Status Pending" (per logs) the Action runs and Backup Mode flips to On... Not what I want. Other stuff happens when it goes back to "OnGrid" lower in the rule, so changed is the trigger to keep it all in one rule if possible.

To start, I think you want the conditional statement to be an AND instead of OR.

What are the other possible values? I tend to lean more towards explicit conditions in rules vs implicit.

1 Like

The condition you're describing is IF NOT (a OR b), which logically equates to, as mentioned above, IF (NOT a AND NOT b).

1 Like

Thanks both!
I don't have the full list of values, the API is... imcomplete. I believe I started with AND and talked myself out of it because then it would have to be BOTH and my head exploded... Will adjust and flex my logic muscle! Cheers.

1 Like

I know that feeling.

With an OR statement, if any sub-condition is true, then the overall condition is true.
With an AND statement, if any sub-condition is false, then the overall condition is false.

Think of it this way. Imagine the status is OnGrid.

IF (
	SystemStatus != "Grid Pending" ("This is true")
	OR
	SystemStatus != "OnGrid"  ("This is false")
	)

So, going back to the above...since you're using an OR statement, and one of these is TRUE, then your IF statement is TRUE and the action is ran.

If you use an AND statement, since one condition if FALSE, then the IF statement is FALSE and the rule would move on.

Another way to think of this using math. This doesn't work in every scenario, but it'll work for this one.

TRUE=1
FALSE=0
OR=Addition (sort of)
AND=Multiplication

So, our condition above would be represented as

IF(1 + 0) = IF(1) = TRUE

Change the operator to AND we get

IF(1 X 0) = IF(0) = FALSE
2 Likes

Don't you have to buy me a drink before you talk to me like that?? :wink:

Thank you. The expanded helps. The "And"=* is a new way to think about the 'word' for me, but in a binary world I get it... I'll use that again when smoke escapes the ears next.

I was hung up on the 'when it happened'. i.e. the rule would fire on change of the variable from OnGrid to Pending and I assumed that had something to do with it rejecting the first IF for some reason. Now I get it... its the fact that the rule fired at all... it did done did do what it was programmed to do ... and left me a steamer on the carpet....

... I oughta just stay in my lane and color inside the lines.... Cheers.

1 Like

On second thought... so does this mean I could have skipped the ! in the two equals expressions and used OR even though I want to fire if the variable isn't one of those?... Oh, here we go again, I need a whisky... suffice it to say,.. I had it, but there's a hole in my net... where are the crayons.....

Download the Hubitat app