Garage Door Alert 2 Doors - Check if light is on

Hi I have a 2 garage doors that have door sensors attached to them. I set my rule so three lights in the house turn on when either of the garage doors are open.
I find that sometimes if both doors are open and one closes that my alert lights will turn off. What do I need to do so my rule is smart enough to keep the light on or do some kind of check.

/GARAGE DOOR ALARMS/

rule “willie garage door ON”

when

Item WillGarageDoorSensor received update OPEN

then

/turn tv alert lights on/

GarageAlert.sendCommand(ON)

OfficeFloorLight.sendCommand(ON)

XXmasTree.sendCommand(ON)

end

rule “willie garage door OFF”

when

Item WillGarageDoorSensor received update CLOSED

then

/turn tv alert lights off/

GarageAlert.sendCommand(OFF)

OfficeFloorLight.sendCommand(OFF)

XXmasTree.sendCommand(OFF)

end

rule “nic garage door ON”

when

Item NicGarageDoorSensor received update OPEN

then

/turn tv alert lights on/

GarageAlert.sendCommand(ON)

OfficeFloorLight.sendCommand(ON)

XXmasTree.sendCommand(ON)

end

rule “nic garage door OFF”

when

Item NicGarageDoorSensor received update CLOSED

then

/turn tv alert lights off/

GarageAlert.sendCommand(OFF)

OfficeFloorLight.sendCommand(OFF)

XXmasTree.sendCommand(OFF)

end

Spacing is important. Please use code fences.

How to use code fences - Tutorials & Examples - openHAB Community

Basically, when the status of either door changes you will need to check the status of both doors in order to determine if the lights should be on or off. If both doors are CLOSED then turn the lights off, else turn the lights on. I don’t have a door sensor nor your items, but the following rule should get you close to what you need.

rule “garage door status”
when
    Item WillGarageDoorSensor received update
 or Item NicGarageDoorSensor  received update
then 
    if (WillgarageDoorSensor.status==CLOSED && NicGarageDoorSensor.Status==CLOSED) {
        GarageAlert.sendCommand(OFF)
        OfficeFloorLight.sendCommand(OFF)
        XXmasTree.sendCommand(OFF)
    }
    else 
    {
        GarageAlert.sendCommand(ON)
        OfficeFloorLight.sendCommand(ON)
        XXmasTree.sendCommand(ON) 
    }
end
1 Like

Thanks @JimH
I’ll give it a try!

Hi @JimH i’m getting an error for “status”
Any idea of what is wrong?
i’m using visual studio code
garagerule

VSCode is catching this. What does it say? Probably something like there is no status method. Replace status with state.

Remove the blanks and replace Status with State
like WillGarageDoorSensor.State

THe error message went away but the lights don’t come on.
Wondering if something to do with the brackets above garageAlert.

alert rule

The sendCommands in the “else” should be sending an “ON” command instead of an “OFF” command. Once you save the Rules file you will need to open or close one of the garage doors so that one of the items receives an update (more on that later)

If that doesn’t fix it please verify that the sensors’ state is CLOSED. Perhaps it is ON/OFF instead. If you defined the sensors using PaperUI go to PaperUI --> Control, locate the sensors, and see what state is displayed. If you defined the sensors’ items in an .items file open the .items file in VSCode and hover over the item name in order to see the current state.

The other thing i would recommend is changing the “when” clause from “received update’ to"changed”. I believe this will cause the lights to be set correctly when openHAB starts up.

@JimH thanks for the help! Switching the OFF command with ON was the solution. See attached.captureapr6