SOLVED: Boolean expressionsin for if-statements in rules

Hi all,

is there a notation for “not” in rules? Something like:

if (!isWeekend() && !isBankHoliday() && status_vacation.state==OFF) {
// workday
do soemthing
}

I only succeed with this version:

if (isWeekend() || isBankHoliday() || status_vacation.state==ON) {}
else {
// no holiday & no vacation -> workday
do something
}

I’ve tried this with openHAB 2.5 and want to simplify my rules. Any hint or idea?

Cheers
Mike

I am not sure but a messy workaround would be to use an else statement.

Did you try:

if !(isWeekend() || isBankHoliday() || status_vacation.state==ON) 
   { // do your stuff 
}

Just put the exclamation mark before the whole parenthesis as from the looks of it, you really are looking for a NOR boolean expression.

Hi Markus,
yes I’m looking for a NOR, because if you want the behavior on “free” days, you have to keep in mind that you can have three different reasons. Of course it would be possible to use multiple if or an else. But I like it the stylish way :wink:

And thanks for your tip, which helped!. But if you have to take the complete parenthesis in brackets, then it works. means:

if (!(isWeekend() || isBankHoliday() || status_vacation.state==ON) )
{ // do your stuff
}

Have you tried:

if (isWeekend() == false && isBankHoliday() == false && status_vacation.state==OFF) { // do your stuff }

Thanks! I had not tested the formula and failed to mention that. Glad you figured it out.
By the way, if you format your post with code fences it makes for much easier reading: How to use code fences

:+1: changed

Hi Partone,

tried your version too and it works even!

Thx
Mike