Openhab 2 exec binding 2.0 configuration

Hi all,
I used the old exec binding-syntax to control relais via some sort of “init-script”.

Switch so_pin29	 "Schalter 29" {exec=">[ON:/opt/openhab/scripts/ on] >[OFF:/opt/openhab/scripts/ off] <[/opt/openhab/scripts/ stat:6000:REGEX((.*?))]"}

I just don’t see, how i should rebuild this with the new exec-syntax.
I tried the following:

exec:command:relais29office [command="/opt/openhab/scripts/ %2$s", transform="REGEX((.*?))", autorun=false]

and then the item:

Switch so_pin29	 "Schalter 29"	{channel="exec:command:relais29office:run"}

first i realized is, that the switch only run the script in the case it is put “ON” … and nothing in the case it is put “OFF”

1 Like

so it’s not possibile to use exec binding with Switch item by executing one script for ON and another one for OFF ?
Is it possibile to run older 1.8 exec binding under openhab 2.0 ?


You can decide in your script what happens.

Here an example:
if [ “$1” = “off” ] || [ “$1” = “0” ];
// do something
// do something else

Hello to all,
has anyone solved the problem?

I coded now:


Thing exec:command:steckdoseG2 [command="/opt/rc-switch/433Utils/RPi_utils/ %2$s", transform="REGEX((.*?))", autorun=false]


Switch stecker {channel="exec:command:steckdoseG2:run"}


if [ "$1" = "off" ] || [ "$1" = "0" ] || [ "$1" = "OFF"  ]; then
        /opt/rc-switch/433Utils/RPi_utils/SteckdoseG2 15 0
        /opt/rc-switch/433Utils/RPi_utils/SteckdoseG2 15 1

Can anyone help me with this problem?

Thank you.

This is a simplified version of what I’m using to start/stop my NAS:

Thing exec:command:device-nas-control [ command="/path/to/script %2$s", interval=0, autorun=true ]

String network_device_nas_switch "NAS" { channel="exec:command:device-nas-control:input", autoupdate="false" }

Switch item=network_device_nas_switch mappings=[ "ON"="ON", "OFF"="OFF" ]

This will either send “ON” or “OFF” to the script provided as “command”.

Thanks, but i get this error:
[ERROR] [hab.binding.exec.handler.ExecHandler] - An exception occurred while formatting the command line with the current time and input values : ‘Format specifier ‘%2$s’’

Can you help? Thanks.

Honestly, no idea. I found my working configuration by searching the forums. I do not really understand the OH2 configuration concepts yet. Here is an intermediate version which actually worked at the time of writing but had some limitations: Trigger Exec Binding switch with HUE Emulation [SOLVED]

My current configuration is much more complex but I can post it if you need it.

maybe it will helps… that will be nice :slight_smile:

Alex, the script of your link works fine :slight_smile:

Ok, here we go. That configuration allows me to start my NAS using the Amazon Echo and it actually represents the current state of the switch by querying if the device is online:

Thing exec:command:device-nas-control “NAS Control Command” [ command="/home/openhab/bin/device-nas %2$s", interval=0, timeout=10, autorun=true ]
Thing exec:command:device-nas-status “NAS State Command” [ command="/home/openhab/bin/device-nas status", interval=20, timeout=5 ]

String network_device_nas_control “NAS Control” { channel=“exec:command:device-nas-control:input”, channel=“exec:command:device-nas-status:output”, autoupdate=“false” }
String network_device_nas_status “NAS Status” { channel=“exec:command:device-nas-status:output” }
Switch network_device_nas_switch “NAS” (group_location_livingroom) [ “Switchable” ]

Switch item=network_device_nas_switch


rule "NAS Switch"
    Item network_device_nas_switch changed
    logInfo("Network", "Switching NAS " + network_device_nas_switch.state.toString + ": " + network_device_nas_control.state.toString)

rule "NAS State"
    Item network_device_nas_status changed
    logInfo("Network", "Switching NAS " + network_device_nas_status.state.toString + ": " + network_device_nas_control.state.toString)
1 Like

Any idea if there’s been a resolution of this problem yet? (exec 2 requiring String objects and no longer working with Number objects)?

I’m trying to migrate from OH1.8 to OH2 but I can’t bring over all my sensor data as Numbers, and every attempt to parse the Strings into Floats etc fails.

1 Like

Same here. Only String works… Number does not work.

My current workaround is to create a stub String item that is bound to the exec binding channel and a second Number item that is populated from the String by a simple rule.

Yeah this is what I’ve been doing too , though it’s a bit ugly having a hundred or so lines of code just parsing each string into a number

Just wondering. Would using a generic lambda function reduce the amount of code to maintain?

Hello Alex,

could you also please provide the script that you are running?

Thank you very mich :slight_smile:

Hello Lucan,

here you go:


THIS_NAME="$(basename "${0}")"


case "${1}" in
                exec sudo /usr/sbin/etherwake "${HOST_MAC}" >/dev/null 2>&1

                exec ssh -o ConnectTimeout=3 -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -l "${HOST_USER}" "${HOST_NAME}" "sudo /sbin/poweroff" >/dev/null 2>&1

                ping -c 1 -W 1 "${HOST_NAME}" >/dev/null 2>&1

                if [ $? -eq 0 ] ; then
                        echo "ON"
                        exit 0

                echo "OFF"
                exit 1

                echo "Usage: ${THIS_NAME} <on|off|status>"
                exit 1

exit 0
1 Like

Thank you so much! I’ve made a few changes so it fits my needs and everything works perfectly

Switching from Number to String also solved the problem for me… :slight_smile:

I think there will be a solution for that in the next version oft the exec binding.

I use one rule for all strings to convert them.
It only needs one additional line for each item. And this will be reduced in future to only one group, have a look here.