Exec Binding

This binding integrates the possibility to execute arbitrary shell commands.

Supported Things

Currently, the binding supports a single type of Thing, being the command Thing.

Binding Configuration

The binding does not require any specific configuration.

Linux: Note that the commands are executed in the context and with the privileges of the process running the Java Virtual Machine. On a Linux system the system user openhab needs to have the privileges needed to execute your intended command. It is advised to test the correct operation of the command in the scope of the openhab user on the command line first:

sudo -u openhab <YOUR COMMAND>

It is not advised to run the virtual machine as superuser/root.

Thing Configuration

. The "command" Thing requires the command to execute on the shell. Optionally one can specify:

  • transform - A transformation to apply on the execution result,
  • interval - An interval, in seconds, the command will be repeatedly executed,
  • timeout - A time-out, in seconds, the execution of the command will time out, and lastly,
  • autorun - A boolean parameter to make the command execute immediately every time the state of the input channel has changed.

For each command a separate Thing has to be defined.

Thing exec:command:uniquename [command="/command/to/execute here", interval=15, timeout=5, autorun=false]

The command itself can be enhanced using the well known syntax of the Java formatter class syntax. The following parameters are automatically added:

  • the current date (as java.util.Date, example: %1$tY-%1$tm-%1$td)
  • the current State of the input channel (see below, example: %2$s)


All Things support the following channels:

Channel Type IDItem TypeDescription
inputStringInput parameter to provide to the command
outputStringOutput of the last execution of the command
exitNumberThe exit value of the last execution of the command
runSwitchSend ON to execute the command, the current state tells whether it is running or not
lastexecutionDateTimeTime/Date the command was last executed, in yyyy-MM-dd'T'HH:mm:ss.SSSZ format

Minimal Example


Thing exec:command:apc [command="/usr/local/bin/apcaccess status", interval=15, timeout=5]
Thing exec:command:myscript [command="php ./configurations/scripts/script.php %2$s", transform="REGEX((.*?))"]


String APCRaw "[%s]" (All) {channel="exec:command:apc:output"}
String APCRunning {channel="exec:command:apc:run"}
String APCExitValue {channel="exec:command:apc:exit"}
String APCLastExecution {channel="exec:command:apc:lastexecution"}

Full Example

Following is an example how to set up an exec command thing, debug it with a rule and set the returned string to an Number Item.

For this to work also the openHAB RegEx Transformation has to be installed


// "%2$s" will be replace by the input channel, this makes it possible to use one command line with different arguments.
// e.g: "ls" as <YOUR COMMAND> and "-a" or "-l" as additional argument set to the input channel in the rule.
Thing exec:command:yourcommand [ command="<YOUR COMMAND> %2$s", interval=0, autorun=false ]


Switch YourTrigger
Number YourNumber "Your Number [%.1f �C]"

// state of the execution, is running or finished
Switch yourcommand {channel="exec:command:yourcommand:run"}
// Arguments to be placed for '%2$s' in command line
String yourcommand_Args {channel="exec:command:yourcommand:input"}
// Output of command line execution 
String yourcommand_out {channel="exec:command:yourcommand:output"}


// Name of file and name of sitemap has to be the same
sitemap demo label="Your Value"
        Frame {
            Switch item=YourTrigger
            Text item=YourNumber


rule "Your Execution"
     Item YourTrigger changed
        if(YourTrigger.state == ON){
                yourcommand_Args.sendCommand("Additional Argument to command line for ON")
                yourcommand_Args.sendCommand("Additional Argument to command line for OFF")

      // wait for the command to complete
      // State will be NULL if not used before or ON while command is executed
      while(yourcommand.state != OFF){
      // Trigger execution
      // Logging of command line result
      logInfo("Your command exec", "Result:" + yourcommand_out.state )
      // If the returned string is just a number it can be parsed
      // If not a regex or another transformation can be used
            (Integer::parseInt(yourcommand_out.state.toString) as Number )


OpenHAB community thread with a detailed example.