Skip to content

Got it to Work (Pfffft!!) \o/

Cause: A broken/non persistent console feature:install command that apparently does not update the addons database or RTFM applies to me too.

What I Noticed

I'm sure I installed openhab-binding-exec but for some reason it got uninstalled.

Console Result (feature:list | grep 'exec'`)

openhab-binding-exec                              │ 2.5.11           │          │ Uninstalled │ openhab-addons-2.5.11    │ Exec Binding
openhab-transformation-exec                       │ 2.5.11           │ x        │ Started     │ openhab-addons-2.5.11    │ Exec Transformation
So I installed it again using the console command
feature:install openhab-binding-exec
After that I watched the logs ignoring the zwave lines using this command.
openhab-cli showlogs | grep -iv zwave

Look at the last line "THE FEATURE GETS AUTO UNINSTALLED!!"

==> /var/log/openhab2/openhab.log <==
2020-12-17 20:54:50.983 [DEBUG] [c.internal.ExecWhitelistWatchService] - Updated command whitelist: [, /usr/local/bin/example.sh %2$s]

==> /var/log/openhab2/events.log <==
2020-12-17 20:54:50.998 [hingStatusInfoChangedEvent] - 'exec:command:example' changed from UNINITIALIZED to INITIALIZING
2020-12-17 20:54:51.023 [hingStatusInfoChangedEvent] - 'exec:command:example' changed from INITIALIZING to ONLINE

==> /var/log/openhab2/events.log <==
2020-12-17 20:55:01.268 [vent.ItemStateChangedEvent] - SF_String changed from 2020-12-17 20:54 to 2020-12-17 20:55
2020-12-17 20:55:01.472 [vent.ConfigStatusInfoEvent] - ConfigStatusInfo [configStatusMessages=[]]
2020-12-17 20:55:01.477 [vent.ConfigStatusInfoEvent] - ConfigStatusInfo [configStatusMessages=[]]
2020-12-17 20:55:01.496 [vent.ConfigStatusInfoEvent] - ConfigStatusInfo [configStatusMessages=[]]
2020-12-17 20:55:01.505 [vent.ConfigStatusInfoEvent] - ConfigStatusInfo [configStatusMessages=[]]
2020-12-17 20:55:01.506 [vent.ConfigStatusInfoEvent] - ConfigStatusInfo [configStatusMessages=[]]

==> /var/log/openhab2/events.log <==
2020-12-17 20:55:20.310 [hingStatusInfoChangedEvent] - 'exec:command:example' changed from ONLINE to UNINITIALIZED
2020-12-17 20:55:20.314 [hingStatusInfoChangedEvent] - 'exec:command:example' changed from UNINITIALIZED to UNINITIALIZED (HANDLER_MISSING_ERROR)
2020-12-17 20:55:20.406 [thome.event.ExtensionEvent] - Extension 'binding-exec' has been uninstalled.
What am I missing here? Am I tripping over a bug again? So I added all bindings in the addons.cfg configuration file and that kept the binding addon to be installed.

So My Tested Example Configuration

This for the prosperity of openhab2 users not struggling for days by just finding this post.

File: services/addons.cfg (most important!!!)

binding = zwave,astro,avmfritz,network,http1,exec

File: things/example.things

Thing exec:command:example "Example Handler" @ "Home" [ command="/usr/local/bin/example.sh %2$s", interval=0,timeout=10, autorun=true ]

File: items/example.items

// Arguments to be placed for '%2$s' in command line
String ExampleInput "Example Args" { channel="exec:command:example:input" }
// Output of command line execution 
String ExampleOutput "Example Output" { channel="exec:command:example:output" }
// Switch to trigger the rule "Example trigger handler".
Switch ExampleTrigger "Example Trigger"

File: rules/example.rules

rule "Example trigger handler"
when
    Item ExampleTrigger changed
then
    if (ExampleTrigger.state == ON)
        ExampleInput.sendCommand("ON")
    else
        ExampleInput.sendCommand("OFF")
end

File: misc/exec.whitelist

# For security reasons all commands that are used by the exec binding or transformation need to be whitelisted.
# Every command needs to be listed on a separate line below.
/usr/local/bin/example.sh

File: /usr/local/bin/example.sh

#!/bin/bash
echo "Call: $1 $2"  >> "/tmp/output.txt"
echo "OK"
Watch the file to see if script is called at all using:
tail -F /tmp/output.txt`
Test access by openhab user using:
sudo -u openhab /usr/local/bin/example.sh "Call using sudo"

Openhab Log (Lines of Joy!!!)

openhab-cli console log:tail

Result command 'ON'.

21:40:35.168 [INFO ] [smarthome.event.ItemCommandEvent     ] - Item 'ExampleTrigger' received command ON
21:40:35.170 [INFO ] [smarthome.event.ItemStateChangedEvent] - ExampleTrigger changed from OFF to ON
21:40:35.171 [INFO ] [smarthome.event.ItemCommandEvent     ] - Item 'ExampleInput' received command ON
21:40:35.173 [INFO ] [arthome.event.ItemStatePredictedEvent] - ExampleInput predicted to become ON
21:40:35.175 [TRACE] [ing.exec.internal.handler.ExecHandler] - Executing command '/usr/local/bin/example.sh %2$s' after a change of the input channel to 'ON'
21:40:35.176 [DEBUG] [ing.exec.internal.handler.ExecHandler] - Passing to shell for parsing command.
21:40:35.177 [DEBUG] [ing.exec.internal.handler.ExecHandler] - OS: *NIX (Linux)
21:40:35.177 [TRACE] [ing.exec.internal.handler.ExecHandler] - The command to be executed will be '[sh, -c, /usr/local/bin/example.sh ON]'
21:40:35.175 [INFO ] [smarthome.event.ItemStateChangedEvent] - ExampleInput changed from OFF to ON
21:40:35.181 [DEBUG] [ing.exec.internal.handler.ExecHandler] - Exec [OUTPUT]: 'OK'
21:40:35.182 [DEBUG] [ing.exec.internal.handler.ExecHandler] - Transformed response is 'OK'

Result command 'OFF'.

21:40:40.183 [INFO ] [smarthome.event.ItemCommandEvent     ] - Item 'ExampleTrigger' received command OFF
21:40:40.185 [INFO ] [smarthome.event.ItemStateChangedEvent] - ExampleTrigger changed from ON to OFF
21:40:40.187 [INFO ] [smarthome.event.ItemCommandEvent     ] - Item 'ExampleInput' received command OFF
21:40:40.189 [INFO ] [arthome.event.ItemStatePredictedEvent] - ExampleInput predicted to become OFF
21:40:40.193 [INFO ] [smarthome.event.ItemStateChangedEvent] - ExampleInput changed from ON to OFF
21:40:40.193 [TRACE] [ing.exec.internal.handler.ExecHandler] - Executing command '/usr/local/bin/example.sh %2$s' after a change of the input channel to 'OFF'
21:40:40.194 [DEBUG] [ing.exec.internal.handler.ExecHandler] - Passing to shell for parsing command.
21:40:40.194 [DEBUG] [ing.exec.internal.handler.ExecHandler] - OS: *NIX (Linux)
21:40:40.195 [TRACE] [ing.exec.internal.handler.ExecHandler] - The command to be executed will be '[sh, -c, /usr/local/bin/example.sh OFF]'
21:40:40.202 [DEBUG] [ing.exec.internal.handler.ExecHandler] - Exec [OUTPUT]: 'OK'
21:40:40.204 [DEBUG] [ing.exec.internal.handler.ExecHandler] - Transformed response is 'OK'