[n00b] how to check two or more items in an IF statement?

I’m n00b, I know…I am trying to do an IF statement that checks multiple items like:


Switch Phone1 "Phone 1" { channel="network:device:10_1_10_234:online" }
Switch Phone2 "Phone 2" { channel="network:device:10_1_10_98:online" }
Switch Phone3 "Phone 3" { channel="network:device:10_1_10_234:online" }


if (Phone1.state == OFF && Phone1.state == OFF && Phone1.state == OFF)
        logInfo("PRESENCE","No phone is connected")

I just tried it with Phone1 connected and the other 2 offline and it executes the loginfo…what is wrong with this? Is it ok to use && as an AND operator?

I see no difference on 3 items in rules, all is if Phone1 is off

Phone1 is now ON while Phone2/3 are off so i would expect no loginfo to happen and yet it is happening and I am not sure why

As hamwong says, look again at what you showed us

if (Phone1.state == OFF && Phone1.state == OFF && Phone1.state == OFF)

All the terms are Phone1
There is no mention of Phone2 and Phone3

Ahhh now I see what you mean, that was a typo sorry, the correct statement is:

if (Phone1.state == OFF && Phone2.state == OFF && Phone3.state == OFF)

if you sure the rules is right as your last statement, than you have to make sure OH phone1 state is same as your phone,
what I mean is you set

Switch Phone1 "Phone 1" { channel="network:device:10_1_10_234:online" }

but may be status is not yet updated to OH, also, you didn’t show us full rules,
did you write in rules what should OH do when phone 1 is on?


if (Phone1.state != ON && Phone2.state != ON && Phone3.state != ON)