Simple issue with rule / if & and

Hi,
just trying my first rule … will get info when all three doors are open.

Actuall I use only one door-contact for testing purposes; “DoorHouse”. (also in line 5, there will be regular the next door check like “DoorLivingroom” in real).

But why will the if-part (line 5) not take effect, loginfo from line 7 is not executed.
Because the state from DoorHouse is “OPEN” (check line 2 is successful, loginfo from line 4 is executed))

1 -rule "AirFlow"
2- when  Item DoorHouse changed from CLOSED to OPEN 
3- then
4-     logInfo("contact.rules", "Status DoorHouse {}", DoorHouse)
5-     if( DoorHouse.state == "OPEN")
6 -     {
7 -        logInfo("contact.rules", "########################## I'm here - loginfo part  ...")
8 -     }
9 - end

This is the output from loginfo from line 4:

[smarthome.model.script.contact.rules] - Status DoorHouse DoorHouse (Type=ContactItem, State=OPEN, Label=Haustür, Category=door, Groups=[GF_Hallway])

Hint: I’m a beginner and maybe some mistake with syntax …
I try it also in line 5 with only “DoorHouse” (without ".state) …

Get rid of the quotes.

if( DoorHouse.state == OPEN)

Arghhh … thx!
Thought it was a string …

CLOSED. OPEN, ON. OFF etc. are like pre-defined states for Items. They’re not strings of themselves. Treat them like special constants.

FYI. DoorHouse.state.toString would give you a string.

Now I have the issue,
when DoorHouse was (allready) open, one minute later next door (DoorLivingroom) opens, the if-part will not reached, because the starting rule in line 2 ("…change from closed to open)" was not true.

Hmmm, but as I find, in the “when” -part it’s not possible to check if all three doors are open ( … && …&& …), this can be only done in a if -part.

How can I check in a correct way if all three doors are open? Shure it’s easy … :wink:

In the trigger you’d have to use “or”. When door1 changed or door2 changed, then if door1 and door2 are open, do something; else quit rule

Thanks, working!

You can also put the three doors is a group:

Group:Contact:AND(CLOSED, OPEN) gDoors "All doors [%s]"
Contact DoorHouse "label" (gDoors) { binding }
Contact DoorLivingRoom "label" (gDoors) { binding }

The group item will be CLOSED when ALL doors are CLOSED otherwise will be OPEN
See: https://www.openhab.org/docs/configuration/items.html#group-type-and-state