Troubleshooting Exec-Binding addon in OH2 - simple light switch with bash script

I’m trying to get a simple exec binding to work to work in OH2. I’ve followed this guide as a basis.

The exec binding runs a bash script that turns ON or OFF a 433mhz mains power switch. The switches work both with the hardware remote and if I run the script manually via SSH.

Here’s my setup.

lights.things

Thing exec:command:PowerSwitch1Switch-control [ command="/usr/local/bin/openhab2/433-3pin-switch-1.sh %2$s", interval=0, autorun=true ]
Thing exec:command:PowerSwitch1Switch-status [ command="/usr/local/bin/openhab2/433-3pin-switch-1.sh status", interval=0, timeout=5 ]

//433Switch2
Thing exec:command:PowerSwitch2Switch-control [ command="/usr/local/bin/openhab2/433-3pin-switch-2.sh %2$s", interval=0, autorun=true ]
Thing exec:command:PowerSwitch2Switch-status [ command="/usr/local/bin/openhab2/433-3pin-switch-2.sh status", interval=0, timeout=5 ]

//433Switch3
Thing exec:command:PowerSwitch3Switch-control [ command="/usr/local/bin/openhab2/433-3pin-switch-3.sh %2$s", interval=0, autorun=true ]
Thing exec:command:PowerSwitch3Switch-status [ command="/usr/local/bin/openhab2/433-3pin-switch-3.sh status", interval=0, timeout=5 ]

//433Switch4
Thing exec:command:PowerSwitch4Switch-control [ command="/usr/local/bin/openhab2/433-3pin-switch-4.sh %2$s", interval=0, autorun=true ]
Thing exec:command:PowerSwitch4Switch-status [ command="/usr/local/bin/openhab2/433-3pin-switch-4.sh status", interval=0, timeout=5 ]

lights.items


Switch PowerSwitch1Switch "Power Switch 1" <poweroutlet> (grp_PowerSwitches) [ "Switchable" ] { channel="exec:command:PowerSwitch1Switch-control:input", channel="exec:command:PowerSwitch1Switch-status:output", autoupdate="true" }
Switch PowerSwitch2Switch "Power Switch 2" <poweroutlet> (grp_PowerSwitches) [ "Switchable" ] { channel="exec:command:PowerSwitch2Switch-control:input", channel="exec:command:PowerSwitch2Switch-status:output", autoupdate="true" }
Switch PowerSwitch3Switch "Power Switch 3" <poweroutlet> (grp_PowerSwitches) [ "Switchable" ] { channel="exec:command:PowerSwitch3Switch-control:input", channel="exec:command:PowerSwitch3Switch-status:output", autoupdate="true" }
Switch PowerSwitch4Switch "Power Switch 4" <poweroutlet> (grp_PowerSwitches) [ "Switchable" ] { channel="exec:command:PowerSwitch4Switch-control:input", channel="exec:command:PowerSwitch4Switch-status:output", autoupdate="true" }
Group grp_PowerSwitches "Power Switches" <poweroutlet>

Switch PowerSwitch1Switch "Power Switch 1" <poweroutlet> (grp_PowerSwitches) [ "Switchable" ] { channel="exec:command:PowerSwitch1Switch-control:input", channel="exec:command:PowerSwitch1Switch-status:output", autoupdate="true" }
Switch PowerSwitch2Switch "Power Switch 2" <poweroutlet> (grp_PowerSwitches) [ "Switchable" ] { channel="exec:command:PowerSwitch2Switch-control:input", channel="exec:command:PowerSwitch2Switch-status:output", autoupdate="true" }
Switch PowerSwitch3Switch "Power Switch 3" <poweroutlet> (grp_PowerSwitches) [ "Switchable" ] { channel="exec:command:PowerSwitch3Switch-control:input", channel="exec:command:PowerSwitch3Switch-status:output", autoupdate="true" }
Switch PowerSwitch4Switch "Power Switch 4" <poweroutlet> (grp_PowerSwitches) [ "Switchable" ] { channel="exec:command:PowerSwitch4Switch-control:input", channel="exec:command:PowerSwitch4Switch-status:output", autoupdate="true" }

.sitemap

sitemap home label="Home Panel" {
    Frame label="Power Switches" {
        Switch item=PowerSwitch1Switch mappings=[ "ON"="ON", "OFF"="OFF" ]
        Switch item=PowerSwitch2Switch mappings=[ "ON"="ON", "OFF"="OFF" ]
        Switch item=PowerSwitch3Switch mappings=[ "ON"="ON", "OFF"="OFF" ]
        Switch item=PowerSwitch4Switch mappings=[ "ON"="ON", "OFF"="OFF" ]

        Switch item=grp_PowerSwitches mappings=[ "ON"="ON", "OFF"="OFF" ]
        }
}

.sh

#!/bin/sh


if [ "$1" = "off" ] || [ "$1" = "0" ] || [ "$1" = "OFF"  ]; then
        /usr/local/bin/433Utils/RPi_utils/codesend 8944270
else
        /usr/local/bin/433Utils/RPi_utils/codesend 8944271
fi

I’ve use Karaf console to up the LOG level (via Karaf SSH Console openhab> log:set:INFO followed by log:tail to monitor the output) to INFO but I don’t get any meaningful errors or indications that the script has been executed via the Exec Binding.

Is there any other way to set logging that would detail what’s going wrong?

Hi sentur,

do you have solved your problem?

I’m new to openhab and going my fisrt steps.
The first I try is to switch an LED on the GPIO of a RasPi3 - where openHAB runs.
So similar to your problem.

What I have done:

  • set up a little script for switching the GPIO-port number 4 by “on/off”, “ON/OFF” or “1/0” (it can executed as user openhab from the bash)
  • installed the exec-binding via Paper-UI
  • definded a “thing” manually:
Thing exec:command:led_control_command "LED Control command" [ command="/home/pi/scripts/gpio.py 4 %2$s" , interval=0]
  • defined a “item” manuelly:
Switch led_control_item "LED Control" { channel="exec:command:led_control_command", autoupdate="true" }
  • defined a “sitemap” manually:
sitemap EsWerdeLicht label="mache Licht an" {
    Frame label="raspiGPIO" {
        Switch item=led_control_item icon="light"
    }
}

I can see the sitemap in the BasicUI and play with the switch-Icon. The events get logged:

2017-12-31 13:17:20.456 [vent.ItemStateChangedEvent] - led_control_item changed from OFF to ON
2017-12-31 13:17:20.601 [ome.event.ItemCommandEvent] - Item 'led_control_item' received command OFF
2017-12-31 13:17:20.610 [vent.ItemStateChangedEvent] - led_control_item changed from ON to OFF
2017-12-31 13:17:20.793 [ome.event.ItemCommandEvent] - Item 'led_control_item' received command ON
2017-12-31 13:17:20.803 [vent.ItemStateChangedEvent] - led_control_item changed from OFF to ON

So far so good. But nothing else happens. What did I forget or what goes wrong?

Somethimes it goes fast …

I’ve changed the item from:

Switch led_control_item "LED Control" { channel="exec:command:led_control_command", autoupdate="true" }

to:

Switch led_control_item "LED Control" { channel="exec:command:led_control_command:run", autoupdate="true" }

An now I’m able to switch my LED ON.
But:

… I can’t switch off, this is done after a few second automatically
… the state of the light-icon in the sitemap does not change
… an the LED is not complete off, it glows a little bit

Toggeling the switch in the UI sends this into the event.log:

2017-12-31 13:51:10.641 [ome.event.ItemCommandEvent] - Item 'led_control_item' received command ON
2017-12-31 13:51:10.650 [vent.ItemStateChangedEvent] - led_control_item changed from OFF to ON
2017-12-31 13:51:10.794 [vent.ItemStateChangedEvent] - led_control_item changed from ON to OFF

But the OFF-command is not send to the script itself (I can see this, because my script is logging its calls itself)

However …