Check for status before Triggering Command

Hello OpenHAB community - This is my first post, as an OpenHAB NooB…So go easy ;-).

I am trying to get my head around a problem I am having, and thought someone out there could probably answer this pretty quickly.

I have successfully automated my garage door using a Fibaro Z-Wave Switch and Sensor. The Garage Motor design is pretty basic…i.e. its not a roller shutter type mechanism, it just responds to a button push.

Press Once -> Open (until fully open) - > Press Again - > Stop -> Press Again - > Close (until fully closed).

the Fibaro switch works excellently and the Sensor tells me if the door is open or closed. Brilliant.

I have created a rule, which closes the garage door at 10pm, every night, if I have left it open (which is a god-send when I am tucked up in bed in my PJ’s at which point my wife sais…“Is the Garage closed?”

I have integrated into HomeKit, and I can ask Siri to Open or Close the door. All works flawlessly.

However, here is the problem.

I want to check the status of the door, before triggering the OPEN (or Close) command. But the way rules are constructed, I can’t work out how to do this.

Basically I want to put an “IF” statement into the “when” block of the rule. to say something like.

If (GarageDoorSensor.State == OPEN)
Item OpenGarage received Command ON IGNORE.

Does that make sense?

What I am trying to get the logic to perform is “if the door is open, don’t open it again”. (and vice versa).

However, the way the rule logic seems to work is you can only apply the “then” statement after the action has been triggered.

This is what I currently have:

Item GarageDoorOpen received command ON // AT which point, the door has been triggered and the Garage door is starting to Close

if(Garage_Door_State.state == ON) { //check the status of the door

                    sendCommand(Garage_Door,ON) // stops the door.



Which is what I currently have. This works (to an extent), but not before the Garage door has started to close, and I would prefer it to Ignore the command altogether, if the state is OPEN.

This actually brings me on to a sub-problem in that - this code will only executes twice, then stops working altogether, until I edit and re-save the default.rules file. Then it will work twice again…and no more. Weird. I am sure it has something to do with the way I have coded this.

The action I am trying to perform in itself is pretty simple - the logic, is pretty simple - but it seems very tricky to implement.

Any advice greatly appreciated. Its not the end of the world if I can’t get this working - as it just means I need to check the app for the status of the door, before I issue a command. But, it would be a nice feature.


You can’t. (rule triggers are events, not steady states)

Set the rule up to trigger when required, and do the test in the then block.
psuedo rule -

time is 10pm
if door is open
close door
do nothing

I think what I would do to try and create a glitch free solution, is to use a virtual item to represent the door. Maybe a string, so it can have more than two states OPEN CLOSED MOVING AJAR. Use autoupdate=false so that you can control its state by rules

Write rules that trigger on commands (from UI or other rules) sent to virtual item, and interpret those into switch ‘pushes’

door received command OPEN
if door state is CLOSED
send switch push (for start open)
postupdate door (MOVING)
send switch push off
else ignore

door received command STOP
if door state is MOVING
send switch push (for stop)
postUpdate door AJAR
send switch push off
else ignore


More rules should update the virtual state

sensor changed to OPEN
postUpdate door OPEN


Don’t be afraid to make a half dozen rules to manage the real door. Then have other rules e.g. the 10pm trigger, send simple commands to the virtual door.

Thanks Rossko57, I think I understand what your saying! Needs a read through a couple of times, but I get the gist…

I had the auto update=false in the back of my mind so will explore that too.


Let the rule trigger and then make the logic have a look here for a simple setup.

     Item OpenGarageCommand changed from OFF to ON
    if(   GarageDoorSensor.state == OFF ){ 
      // I expect the sensor to be ON when the door ist closed 
     // Do nothing or state it was already closed.

I hope I have understand the problem and this helps.