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