First attempt at proxy - rules not firing

I am relatively new to OpenHab, and trying to use a proxy for the first time. I have a sensor whose state I need to read by polling it periodically via a command-line script. I want to take my polled state and convert it into a regular “sensor” so I can write straightforward rules. I’ve been reading about proxies in these forums and it seems like a good approach. I’ve made a few attempts shown below. In the first one I created a proxy “switch”, in the second a proxy “sensor”, and in the third a proxy “string”. In each case, my logs clearly show that my sensor is being properly read from the command-line poll, but my proxy rules are not firing.

Try #1 - proxy switch:

Item:

Switch  GarageDoorSwitch  "Garage door open [%s]"

Rules:

/* Check for switches open every second */
rule "Check hard-wired switches"
when
        Time cron "* * * * * ?" // every second
then
        val String gpioState = executeCommandLine("/opt/openhab/configurations/scripts/checkGpio.sh@@18", 100)
        if (gpioState == "CLOSED") {
                logInfo("Check hard-wired switches", "Garage door is currently closed: {}", gpioState)
                GarageDoorSwitch.sendCommand(OFF)
        }else{
                logInfo("Check hard-wired switches", "Garage door is currently open: {}", gpioState)
                GarageDoorSwitch.sendCommand(ON)
        }
end

/* Rules for proxy switch */
rule "Garage door is open"
when
        GarageDoorSwitch received command ON
then
        logInfo("Garage door", "Garage Door NEWLY OPENED!")
end

rule "Garage door is closed"
when
        GarageDoorSwitch received command OFF
then
        logInfo("Garage door", "Garage Door NEWLY CLOSED!")
end

Try #2 using a Contact:

Item:

Contact GarageDoorOpen  "Garage door open [%s]"

Rules:

/* Check for switches open every second */
rule "Check hard-wired switches"
when
        Time cron "* * * * * ?" // every second
then
        val String gpioState = executeCommandLine("/opt/openhab/configurations/scripts/checkGpio.sh@@18", 100)
        if (gpioState == "CLOSED") {
                logInfo("Check hard-wired switches", "Garage door is currently closed: {}", gpioState)
                GarageDoorOpen.sendCommand(CLOSED)
        }else{
                logInfo("Check hard-wired switches", "Garage door is currently open: {}", gpioState)
                GarageDoorOpen.sendCommand(OPEN)
        }
end

rule "Garage door is open"
when
        GarageDoorOpen changed to OPEN
then
        logInfo("Garage door", "Garage Door NEWLY OPENED!")
end

rule "Garage door is closed"
when
        GarageDoorOpen changed to CLOSED
then
        logInfo("Garage door", "Garage Door NEWLY CLOSED!")
end

Try #3, Proxy as a String

Item:

String  GarageDoorProxy "Garage door open [%s]"

Rules:

/* Check for switches open every second */
rule "Check hard-wired switches"
when
        Time cron "* * * * * ?" // every second
then
        val String gpioState = executeCommandLine("/opt/openhab/configurations/scripts/checkGpio.sh@@18", 100)
        if (gpioState == "CLOSED") {
                logInfo("Check hard-wired switches", "Garage door is currently closed: {}", gpioState)
                GarageDoorProxy.postUpdate(gpioState)
        }else{
                logInfo("Check hard-wired switches", "Garage door is currently open: {}", gpioState)
                GarageDoorProxy.postUpdate(gpioState)
        }
end

/* Rules for proxy switch */
rule "Garage door has changed"
when
        GarageDoorProxy updated
then
        logInfo("Garage door", "Garage Door is NEWLY: {}", GarageDoorProxy)
end

In all cases, the log shows:

2016-10-22 16:59:10.119 [INFO ] [.m.s.Check hard-wired switches] - Garage door is currently closed: CLOSED
2016-10-22 16:59:11.107 [INFO ] [.m.s.Check hard-wired switches] - Garage door is currently open: OPEN
2016-10-22 16:59:12.108 [INFO ] [.m.s.Check hard-wired switches] - Garage door is currently open: OPEN
2016-10-22 16:59:13.108 [INFO ] [.m.s.Check hard-wired switches] - Garage door is currently open: OPEN
2016-10-22 16:59:14.108 [INFO ] [.m.s.Check hard-wired switches] - Garage door is currently open: OPEN
2016-10-22 16:59:16.117 [INFO ] [.m.s.Check hard-wired switches] - Garage door is currently closed: CLOSED

I’m sure it’s something basic… thanks. -Ken

Look in the event.log file and see if your proxy item is being updated. A quick scan of what you are doing revealed no hosting errors.

I found one mistake in all of my attempts, I was missing the word “Item” in the when-clauses of all of my rules.After correcting this I found that the postUpdate() attempts were causing the proxy’s rules to fire, but were happening every second when the rule says “when Item GarageDoorProxy updated”. Your tip to check the events log helped, because I could see the events were firing, I just needed to be more specific about what I was looking for it change to. This is working now:

Item:

Switch  GarageDoorSwitch        "Garage door open [%s]"

Rules:

/* Check for switches open every second */
rule "Check hard-wired switches"
when
        Time cron "* * * * * ?" // every second
then
        val String gpioState = executeCommandLine("/opt/openhab/configurations/scripts/checkGpio.sh@@18", 100)
        if (gpioState == "CLOSED") {
                //logInfo("Check hard-wired switches", "Garage door is currently closed: {}", gpioState)
                GarageDoorSwitch.postUpdate(OFF)
        }else{
                logInfo("Check hard-wired switches", "Garage door is currently open: {}", gpioState)
                GarageDoorSwitch.postUpdate(ON)
        }
end

/* Rules for proxy switch */
rule "Garage door has changed"
when
        Item GarageDoorSwitch changed to ON
then
        logInfo("Garage door", "Garage Door is NEWLY: {}", GarageDoorSwitch.state)
end

Thanks! -Ken