Adding second condition to when

If I wanted to have two conditions on a rule like below, how would I format it?

when
Item JRSIPhone_Online changed from OFF to ON AND GarageDoorOpener_Doorstatus changed from Closing to Closed

Right now it errors when I add the second AND Part.

Thanks.

JR

This is not possible.

openHAB rule triggering is event based and it is highly unlikely that two events happen at exactly the same time.
Have a lok at your example. This rule would just fire if the Garage Door is closed at the same time your iphone goes online.

What you really want is triggering on one event, but just if a special state condition is set.

Using your example you want the rule to trigger when the garage door is just closed and if your iphone is online. Or the other way round, off course.

Your only option is to check the state condition within the rule using an if statement.

Of course you are able to use several trigger events combined with an or, just the and is impossible.

Kind of figured as much after I wrote it and was thinking it over.

Not sure if I should do some kind of loop that once the phone shows up, it starts checking on the garage door. In the event I walked out the front door for a while it would be looping forever since the garage is never triggered. Maybe it waits for 10 seconds and if the state of the garage door doesn’t change during that it just gives up and no friendly greeting. Just thinking it thru.

Thanks.

JR

As mentioned above you would want your rule to look something like this:

when
    Item JRSIPhone_Online changed from OFF to ON or,
    GarageDoorOpener_Doorstatus changed from Closing to Closed
then
    if(JRSIPhone_Online.state == ON && GarageDoorOpener_Doorstatus.state == Closed)
Item_somthing.sendCommand(ON)
end

Avoiding loops whenever possible.

Like he said - no , no , never, not ever, no!
It takes a while to get used to event driven rules, it’s a way of thinking. You don’t really want to keep checking the garage door, you only want to decide about doing X or not when the door changes.

Isn’t the if statement going to trigger immediately after the phone gets on Wi-Fi and fail? So:

  1. Pull into the garage.
  2. Device gets on Wi-Fi because it’s available in the garage.
  3. Get out of car
  4. Push the close button for the garage door
  5. Walk in the house

So won’t the when statement pass right after item 2 and then immeidately fail the if statement and end?

Thanks.

JR

Yep. Then the rule will run again in a minute, when the garage door closes.

Please don’t. Trigger the Rule on either event, then check to see if the other happened recently enough. If so then you know to give the greeting. It doesn’t matter what order the events occur in.

Never just wait around inside a Rule with a while loop or a Thread::sleep or something. You only get five simultaneously running Rules. When you run out, all your Rules stop.

When writing Rules for OH, you need to think first and foremost about events. Events are what drive your Rules. You don’t need to wait for events in a Rule. Just trigger your Rule based on all the events you care about, then check the states to see if you should take action or not.