Why doesn't this rule fire?

I have a new rule intended to text me if the gate is opened while the garage door is open. I tested it for the first time this morning, and it didn’t fire:

  rule "verifyGarageDoor"
    when
    	Item Gate received update
    then
    	if ((Gate.state == "Open") && (alarmPanelStatusAway == 1) && (GarageDoorLeft.state == "OPEN")) {
    		sendMail("redacted1@vtext.com", "Garage Status", "Door open");
    	//	sendMail("redacted2@vtext.com", "Garage Status", "Door open");
    	}
    end

From run.log, events for the relevant items:

2016-12-11 07:24:26.409 [INFO ] [runtime.busevents             ] - GarageDoorLeft state updated to OPEN
2016-12-11 07:25:08.612 [INFO ] [runtime.busevents             ] - alarmPanelStatusAway state updated to 1
2016-12-11 07:25:26.122 [INFO ] [runtime.busevents             ] - Gate state updated to Open
2016-12-11 07:25:26.135 [INFO ] [runtime.busevents             ] - Gate state updated to Open
2016-12-11 07:25:37.011 [INFO ] [runtime.busevents             ] - GarageDoorLeft state updated to CLOSED
2016-12-11 07:25:38.991 [INFO ] [runtime.busevents             ] - GarageDoorLeft state updated to OPEN
2016-12-11 07:25:50.256 [INFO ] [runtime.busevents             ] - GarageDoorLeft state updated to CLOSED
2016-12-11 07:26:02.643 [INFO ] [runtime.busevents             ] - Gate state updated to Closed
2016-12-11 07:26:02.653 [INFO ] [runtime.busevents             ] - Gate state updated to Closed

Could the double notifications from the gate be causing the event to be missed? (This is a bug in the python program running on an rPI that monitors the gate).
Note: the garage door did in fact close and immediately reopen due to a poor adjustment; exactly what this alert is intended to help us catch.

No logged messages that I could spot. I guess I should set up a logger for scripts and put some debug message in the rule.

I’m certainly a fledgling rule creator, but in my rules with multiple actions I don’t have semicolons at the end of the action.

I think you need to just write, if both items are contacts

rule “verifyGarageDoor"
when
Item Gate received update
then
if ((Gate.state == OPEN) && (alarmPanelStatusAway == 1) && (GarageDoorLeft.state == OPEN)) {
sendMail("redacted1@vtext.com”, “Garage Status”, “Door open”)
// sendMail("redacted2@vtext.com", “Garage Status”, “Door open”)
}
end

Thanks. I’ll check both when I get home.
Too many years of C programming, I don’t even see semi colons anymore. I’m not sure if they are contacts, they may be strings, as they are updated via mqtt.

In any case the use of LogInfo will help debugging!

`LogInfo (“YourRuleName”,“YourItem ={}”,YourItem)"

would print directly into the log:tail of karaf!

I should have mentioned I’m running 1.8.

Or if they are not contacts, try

Gate.state.toString == "Open"

to compare values.

Not to forget, if alarmPanelStatusAway is an item, you will have to use alarmPanelStatusAway.state or maybe alarmPanelStatusAway.state as DecimalType, so, the if clause should look like

if (Gate.state.toString == "Open" && (alarmPanelStatusAway.state as DecimalType) == 1 && GarageDoorLeft.state == OPEN)

as the first one is a string, the second one is supposed to be of type number and the third item is of type contact, this one is directly compared to the state (no quotes!!!)

thanks for all the replies – two typos found (semicolons and missing “.state” on alarmPanel…)

  • Added the .toString method on Gate (a String, maybe I’ll convert to a Contact at some point)
  • Added cast to DecimalType to alarmStatus… (a Number, could probably be a contact also)
  • Removed quotes from “OPEN” on GarageDoorLeft (a Contact)
    I’ll test it tomorrow afternoon (in the meantime, it’ll get some negative tests when the Gate is open when the garage is not) and report back.

Is there documentation in the Wiki on the methods and objects on an Item that can be used from rules? I’ve been unable to find anything; I’d take a crack at drafting something if I had info to go on.

It’s recommended to use openHAB Designer (respectively Eclipse Smarthome Designer when using OH2) to configure openHAB. If doing so, you can simply hit < ctrl > + < space > to show all possible code completions :slight_smile:

I have the impression that Designer is a native executable and not web-based. Is that correct? I run OH on a headless server…

You share your openHAB configuration directory on your headless server via samba to your laptop/desktop etc. On your desktop/laptop you install the Designer and point it to the shared samba config directory to edit / save / test etc.
It is indeed not web-based.

1 Like

Maurits, good tip!
I think I may upgrade to OH2, then start with Designer. My system is pretty stable right now, so I’m not making many changes.

The working version, thanks to everyone’s help:

rule "verifyGarageDoor"
when
    Item Gate received update
then
    if ((Gate.state.toString == "Open") 
            && (alarmPanelStatusAway.state as DecimalType == 1) 
            && (GarageDoorLeft.state == OPEN)) {
	sendMail("redacted@vtext.com", "Garage Status", "Door open")
	}
end