OpenHAB Exec Binding explained in detail on 433MHz radio transmitter example

Your rule works, the command will be sent, but only the first time. I took a video on how the switch reacts the first time and then no longer. the first time the light bulb lights up and then it is off.when i restart the raspi it works again the first time

Videolink: https://youtu.be/-vRwYClcUKg

What else can you change about the rule? you’re great thanks for everything so far.

log:

13:52:47.794 [INFO ] [.dashboard.internal.DashboardService] - Started dashboard                                                                                                                      at https://192.168.8.111:8443
13:52:48.352 [INFO ] [basic.internal.servlet.WebAppServlet] - Started Basic UI a                                                                                                                     t /basicui/app
13:52:48.432 [INFO ] [arthome.ui.paper.internal.PaperUIApp] - Started Paper UI a                                                                                                                     t /paperui
13:52:48.516 [INFO ] [panel.internal.HABPanelDashboardTile] - Started HABPanel a                                                                                                                     t /habpanel
13:52:48.702 [INFO ] [ui.habmin.internal.servlet.HABminApp] - Started HABmin ser                                                                                                                     vlet at /habmin
13:54:35.708 [INFO ] [smarthome.event.ItemCommandEvent    ] - Item 'Wohnzimmer'                                                                                                                      received command ON
13:54:35.773 [INFO ] [marthome.event.ItemStateChangedEvent] - Wohnzimmer changed                                                                                                                      from NULL to ON
13:54:36.102 [INFO ] [smarthome.event.ItemCommandEvent    ] - Item 'Remote_Send_                                                                                                                     Args' received command 13108705
13:54:36.112 [INFO ] [marthome.event.ItemStateChangedEvent] - Remote_Send_Args c                                                                                                                     hanged from NULL to 13108705
13:54:36.119 [INFO ] [marthome.event.ItemStateChangedEvent] - Remote_Send change                                                                                                                     d from NULL to ON
13:54:36.639 [INFO ] [marthome.event.ItemStateChangedEvent] - Remote_Send change                                                                                                                     d from ON to OFF
13:54:36.653 [INFO ] [marthome.event.ItemStateChangedEvent] - Remote_Send_Out ch                                                                                                                     anged from NULL to sending code[13108705]
13:54:37.167 [INFO ] [se.smarthome.model.script.Wohnzimmer] - Resuts: sending co                                                                                                                     de[13108705]
13:54:37.188 [INFO ] [marthome.event.ItemStateChangedEvent] - Wohnzimmer changed                                                                                                                      from ON to OFF
13:54:38.311 [INFO ] [smarthome.event.ItemCommandEvent    ] - Item 'Wohnzimmer'                                                                                                                      received command ON
13:54:38.322 [INFO ] [marthome.event.ItemStateChangedEvent] - Wohnzimmer changed                                                                                                                      from OFF to ON
13:54:38.323 [INFO ] [smarthome.event.ItemCommandEvent    ] - Item 'Remote_Send_                                                                                                                     Args' received command 13108705
13:54:38.326 [INFO ] [se.smarthome.model.script.Wohnzimmer] - Resuts: sending co                                                                                                                     de[13108705]
13:54:38.334 [INFO ] [marthome.event.ItemStateChangedEvent] - Wohnzimmer changed                                                                                                                      from ON to OFF
13:54:39.270 [INFO ] [smarthome.event.ItemCommandEvent    ] - Item 'Wohnzimmer'                                                                                                                      received command ON
13:54:39.282 [INFO ] [marthome.event.ItemStateChangedEvent] - Wohnzimmer changed                                                                                                                      from OFF to ON
13:54:39.293 [INFO ] [smarthome.event.ItemCommandEvent    ] - Item 'Remote_Send_                                                                                                                     Args' received command 13108705
13:54:39.299 [INFO ] [se.smarthome.model.script.Wohnzimmer] - Resuts: sending co                                                                                                                     de[13108705]
13:54:39.314 [INFO ] [marthome.event.ItemStateChangedEvent] - Wohnzimmer changed                                                                                                                      from ON to OFF
13:54:40.296 [INFO ] [smarthome.event.ItemCommandEvent    ] - Item 'Wohnzimmer'                                                                                                                      received command ON
13:54:40.317 [INFO ] [smarthome.event.ItemCommandEvent    ] - Item 'Remote_Send_                                                                                                                     Args' received command 13108705
13:54:40.322 [INFO ] [marthome.event.ItemStateChangedEvent] - Wohnzimmer changed                                                                                                                      from OFF to ON
13:54:40.327 [INFO ] [se.smarthome.model.script.Wohnzimmer] - Resuts: sending co                                                                                                                     de[13108705]
13:54:40.340 [INFO ] [marthome.event.ItemStateChangedEvent] - Wohnzimmer changed                                                                                                                      from ON to OFF
13:54:41.590 [INFO ] [smarthome.event.ItemCommandEvent    ] - Item 'Wohnzimmer'                                                                                                                      received command ON
13:54:41.600 [INFO ] [marthome.event.ItemStateChangedEvent] - Wohnzimmer changed                                                                                                                      from OFF to ON
13:54:41.606 [INFO ] [smarthome.event.ItemCommandEvent    ] - Item 'Remote_Send_                                                                                                                     Args' received command 13108705
13:54:41.616 [INFO ] [se.smarthome.model.script.Wohnzimmer] - Resuts: sending co                                                                                                                     de[13108705]
13:54:41.628 [INFO ] [marthome.event.ItemStateChangedEvent] - Wohnzimmer changed                                                                                                                      from ON to OFF

@antihero00 I added something to my previous post.

I use postUpdate, this does not trigger the rule.
But I did not test it.

But the problem is if the argument stays the same the command will not be triggered.

If the thing is used by multiple rules it es advised to first check if item is active.

Video is not available.

I’ve done a video update! I have replaced the rule with the new one, but it does not change, send command only at the first time i push the button (look at the video).
The things are only used by this one rule, so far I have only this one configuration.
Thank you

log file:
    17:46:01.207 [INFO ] [el.core.internal.ModelRepositoryImpl] - Loading model 'wohnzimmer.items'
    17:46:08.572 [INFO ] [el.core.internal.ModelRepositoryImpl] - Loading model 'wohnzimmer.rules'
    17:46:09.962 [INFO ] [el.core.internal.ModelRepositoryImpl] - Loading model 'funklicht.sitemap'
    17:46:10.014 [INFO ] [home.event.ItemChannelLinkAddedEvent] - Link 'Remote_Send_Out-exec:command:remote-send:output' has been added.
    17:46:10.019 [INFO ] [home.event.ItemChannelLinkAddedEvent] - Link 'Remote_Send_Args-exec:command:remote-send:input' has been added.
    17:46:10.021 [INFO ] [home.event.ItemChannelLinkAddedEvent] - Link 'Remote_Send-exec:command:remote-send:run' has been added.
    17:46:10.367 [INFO ] [el.core.internal.ModelRepositoryImpl] - Loading model 'funklicht.things'
    17:46:10.473 [INFO ] [smarthome.event.ThingAddedEvent     ] - Thing 'exec:command:remote-send' has been added.
    17:46:10.499 [INFO ] [me.event.ThingStatusInfoChangedEvent] - 'exec:command:remote-send' changed from UNINITIALIZED to INITIALIZING
    17:46:10.506 [INFO ] [me.event.ThingStatusInfoChangedEvent] - 'exec:command:remote-send' changed from INITIALIZING to ONLINE
    17:46:13.155 [WARN ] [g.eclipse.smarthome.core.net.NetUtil] - Found multiple local interfaces - ignoring 192.168.8.109
    17:46:13.158 [INFO ] [.dashboard.internal.DashboardService] - Started dashboard at http://192.168.8.111:8080
    17:46:13.163 [WARN ] [g.eclipse.smarthome.core.net.NetUtil] - Found multiple local interfaces - ignoring 192.168.8.109
    17:46:13.165 [INFO ] [.dashboard.internal.DashboardService] - Started dashboard at https://192.168.8.111:8443
    17:46:13.797 [INFO ] [basic.internal.servlet.WebAppServlet] - Started Basic UI at /basicui/app
    17:46:13.989 [INFO ] [arthome.ui.paper.internal.PaperUIApp] - Started Paper UI at /paperui
    17:46:14.080 [INFO ] [panel.internal.HABPanelDashboardTile] - Started HABPanel at /habpanel
    17:46:14.239 [INFO ] [ui.habmin.internal.servlet.HABminApp] - Started HABmin servlet at /habmin
    17:46:47.240 [INFO ] [smarthome.event.ItemCommandEvent    ] - Item 'Wohnzimmer' received command ON
    17:46:47.297 [INFO ] [marthome.event.ItemStateChangedEvent] - Wohnzimmer changed from NULL to ON
    17:46:47.680 [INFO ] [smarthome.event.ItemCommandEvent    ] - Item 'Remote_Send_Args' received command 13108705
    17:46:47.689 [INFO ] [marthome.event.ItemStateChangedEvent] - Remote_Send_Args changed from NULL to 13108705
    17:46:47.694 [INFO ] [marthome.event.ItemStateChangedEvent] - Remote_Send changed from NULL to ON
    17:46:48.201 [INFO ] [marthome.event.ItemStateChangedEvent] - Remote_Send changed from ON to OFF
    17:46:48.209 [INFO ] [marthome.event.ItemStateChangedEvent] - Remote_Send_Out changed from NULL to sending code[13108705]
    17:46:48.702 [INFO ] [se.smarthome.model.script.Wohnzimmer] - Resuts: sending code[13108705]
    17:46:48.721 [INFO ] [marthome.event.ItemStateChangedEvent] - Wohnzimmer changed from ON to OFF
    17:46:48.733 [INFO ] [marthome.event.ItemStateChangedEvent] - Remote_Send_Args changed from 13108705 to
    17:46:55.277 [INFO ] [smarthome.event.ItemCommandEvent    ] - Item 'Wohnzimmer' received command ON
    17:46:55.287 [INFO ] [marthome.event.ItemStateChangedEvent] - Wohnzimmer changed from OFF to ON
    17:46:55.300 [INFO ] [smarthome.event.ItemCommandEvent    ] - Item 'Remote_Send_Args' received command 13108705
    17:46:55.308 [INFO ] [marthome.event.ItemStateChangedEvent] - Remote_Send_Args changed from   to 13108705
    17:46:55.312 [INFO ] [se.smarthome.model.script.Wohnzimmer] - Resuts: sending code[13108705]
    17:46:55.333 [INFO ] [marthome.event.ItemStateChangedEvent] - Wohnzimmer changed from ON to OFF
    17:46:55.339 [INFO ] [marthome.event.ItemStateChangedEvent] - Remote_Send_Args changed from 13108705 to

@antihero00 I had some time to test it. This is the best solution i could find so far.

set the thing autorun to false.

Thing exec:command:Wohnzimmer_Decke [ command="/home/openhabian/433Utils/RPi_utils/Wohnzimmer_decke.sh %2$s, interval=0, autorun=false]

in the rule manually trigger the execution.

rule "Wohnzimmer"
  when
    Item Wohnzimmer received command ON
  then

     // Check if an other rule uses the transmitter
     while(Remote_Send.state == ON){
        Thread::sleep(500)
     }
     Remote_Send_Args.sendCommand("13108705")
     // triger sending manually
     Remote_Send.sendCommand(ON);

     // wait for the command to complete
     while(Remote_Send.state != OFF){
        Thread::sleep(500)
     }
     logInfo("Wohnzimmer", "Resuts: " + Remote_Send_Out.state )

     // After command is done
     // Set button back so you can reuse it
     Wohnzimmer.postUpdate(OFF)
end

This works for me and executes the command everytime.

Some sidenotes.
If the reseting is done with sendCommand instead of postUpdate it will also work, but it will trigger an execution which is not a good idea.

Josar you are my hero, it works fine. Thank you .

Hi Josar,
great tutorial. Tried it on a Raspberry Pi 3 with OpenHAB2. Followed exactly your steps. But I get the “An exception occurred while formatting the command line with the current time and input values : 'Format specifier ‘%2$s’” but as I’m quite new to OpenHAB, I don’t know how to handle your explanation to this error. Can you give me some newbe step-by-step advice?

Many thanks and best regards
Muhackl

@muhackl666 i think you have to install the

And the string in your input channel has to be properly set. Please post your settings only the error is not enougth to find out the reason.

@muhackl666

Did you do something like

Remote_Send.sendCommand("YOUR STRING")

instead of

Remote_Send_Args.sendCommand("YOUR STRING")

I 99% copy and pasted exactly what you postet in your tutorial. The 1% difference is the code I send to receiver. It’s 11111 1 1 and of cource 11111 1 0.
So there is Remote_Send_Args.sendCommand(“11111 1 1”) for example.

I manually installed regex transformation via openhab console and feature:install openhab-transformation-regex.
What else could it be?

@muhackl666 try to install the exec binding and the regex transformation from paper ui, again.

I encountered a problem with karaf and paper ui Installation.

Please clear the log then restart and post your full log.

I deinstalled the regex binding and reinstalled it - both via paper ui this time. I also installed exec transformation.
I deinstalled and reinstalled the exec binding. And this is the log:

21:58:32.930 [INFO ] [smarthome.event.ExtensionEvent ] - Extension ‘binding-exec’ has been installed.
21:58:32.994 [INFO ] [ome.event.ThingStatusInfoChangedEvent] - ‘exec:command:remote-send’ changed from UNINITIALIZED to INITIALIZING
21:58:33.012 [INFO ] [ome.event.ThingStatusInfoChangedEvent] - ‘exec:command:remote-send’ changed from INITIALIZING to ONLINE
21:58:46.633 [INFO ] [smarthome.event.ExtensionEvent ] - Extension ‘transformation-regex’ has been installed.
21:58:57.561 [INFO ] [smarthome.event.ExtensionEvent ] - Extension ‘transformation-exec’ has been installed.
21:59:54.450 [INFO ] [del.core.internal.ModelRepositoryImpl] - Refreshing model 'exec.things’
21:59:54.505 [INFO ] [smarthome.event.ThingUpdatedEvent ] - Thing ‘exec:command:remote-send’ has been updated.
22:00:42.946 [INFO ] [smarthome.event.ItemCommandEvent ] - Item ‘Remote_Send’ received command ON
22:00:42.993 [INFO ] [smarthome.event.ItemStateChangedEvent] - Remote_Send changed from NULL to ON
22:00:43.013 [ERROR] [nhab.binding.exec.handler.ExecHandler] - An exception occurred while formatting the command line with the current time and input values : 'Format specifier ‘%2$s’'
22:00:43.043 [INFO ] [smarthome.event.ItemStateChangedEvent] - Remote_Send changed from ON to OFF

1 Like

@muhackl666 i dont see where you pressed a switch in the log. As there is no output logged from the rules and also no state change from the switches.

How does Remote_Send gets triggered to change to ON?

When the input channel in this case Remote_Send_Args is not set before triggering the execution there will be this error.
What is shown in the log when you press a switch?

PS: please use the icons above the writing field to format your code or log.

```
your code goes here
```

Exactly this is shown, when I switch the switch in basic ui. The switch goes to the right and after that automatically back to the left (off). In the log, that’s everything that happens:

19:41:52.043 [INFO ] [smarthome.event.ItemCommandEvent ] - Item ‘Remote_Send’ received command ON
19:41:52.060 [ERROR] [nhab.binding.exec.handler.ExecHandler] - An exception occurred while formatting the command line with the current time and input values : 'Format specifier ‘%2$s’'
19:41:52.092 [INFO ] [smarthome.event.ItemStateChangedEvent] - Remote_Send changed from OFF to ON
19:41:52.147 [INFO ] [smarthome.event.ItemStateChangedEvent] - Remote_Send changed from ON to OFF

@muhackl666

  1. are you using the Powerplugs or the LEDstripes example. Please post the content of all your files. Please use the code fence for that.
  2. Did you try to execute the send command from the command line as user pi and it worked?
  3. Did you try to execute the send comamnd as user openah/openhabian, and it worked?
  4. And then you setted up Exec binding, transformation, the files and rebooted?

I at least miss one of this outputs in the logs.

logInfo("Power_Plugs", "Switch Socket "+ num +" to " + plug.state )
...
logInfo("Power_Plug", "Result:" + Remote_Send_Out.state )
  1. What is your setup RPI1/2/3, Openhabian or openhab apt-get installeld?

I’m using the Poweplugs example.

exec.things

Thing exec:command:remote-send [
            command="/opt/raspberry-remote/send %2$s",
            interval=0,
            autorun=true]

powerplug.rules

rule "Poweroutlet B"
    when
        Item Power_Plug_Socket_B received command
    then
        // wait for transmitter to be free
        // State will be NULL if not used before or ON while command is executed
        while(Remote_Send.state == ON){
            Thread::sleep(500)
        }

        if(receivedCommand == ON){
            Remote_Send_Args.sendCommand("11111 1 1")
        }else{
            Remote_Send_Args.sendCommand("11111 1 0")
        }

        // wait for the command to complete
        while(Remote_Send.state != OFF){
            Thread::sleep(500)
        }

        logInfo("Power_Plug", "Result:" + Remote_Send_Out.state )
end

powerplug.items

Switch Power_Plug_Socket_A <poweroutlet>
Switch Power_Plug_Socket_B <poweroutlet>
Switch Power_Plug_Socket_AB <poweroutlet>

Switch Remote_Send      { channel="exec:command:remote-send:run"    }
String Remote_Send_Args { channel="exec:command:remote-send:input"  }
String Remote_Send_Out  { channel="exec:command:remote-send:output" }

powerplug.sitemap

sitemap powerplugs label="Wireless Poweroutlets"
{
    Frame label="Poweroutlets"
    {
        Switch item=Power_Plug_Socket_A label="Power Plug A"
        Switch item=Power_Plug_Socket_B label="Power Plug B"

        Switch item=Power_Plug_Socket_AB label="Power Plug AB"
    }
}

When I do:

sudo -u pi /opt/raspberry-remote/send 11111 1 1

the power outlet switches on. With 0 at the end it switches off.

When I do:

sudo -u openhab /opt/raspberry-remote/send 11111 1 1

the power outlet switches on. With 0 at the end it switches off.

Exactly.

It’s a Raspberry Pi 3 with the latest Raspbian Stretch and Openhab installed like described here: https://docs.openhab.org/installation/linux.html
via

echo 'deb https://dl.bintray.com/openhab/apt-repo2 stable main' | sudo tee /etc/apt/sources.list.d/openhab2.list

and

sudo apt-get install openhab2

and even

sudo apt-get install openhab2-addons

@muhackl666 only thing i can advise now is a fresh install of openhab or the whole pi. I have no further ideas.
But why does your switch automatically turn off again?
And what is the version of your openhab? Mine is

dpkg --list | grep openhab
ii  openhab2   2.2.0-1   all   openhab2

So I set up another raspberry pi3 - everything totally freshly.
And it works fine - at least in basic ui.
So something must have been misconfigured in my previous setup.

Regarding paper ui, it looks like this:

08

The switch can’t be used. Any hints?

Paper UI is a config and maybe testing tool. Not a user UI.

To use you need a Basic UI or an Habpanel or one of the others i don´t now of.

No problem. I’ll get along. You helped me a lot and openHAB is now a lot more useful for me.
Many thanks again.

Hey Josar,
thanks for your great tutorial - I’ve been searching for a way to control my powerplugs via Alexa and openHAB for a long time. Your solution works fine for me.
But sometimes my transmitter signal gets lost or isn’t recognized by the receiver. I’d like to send every command multiple times to make sure the digital and physical state of the device are equal. What is the smartest way to do this? In this thread I found a few helpful things but I don’t know how to put them together.
I’m not sure if this works if I set the thing’s autorun to false:

rule "Poweroutlet B"
    when
        Item Power_Plug_Socket_B received command
    then
        var i = 0
        // wait for transmitter to be free
        // State will be NULL if not used before or ON while command is executed
        while(Remote_Send.state == ON){
            Thread::sleep(500)
        }

        if(receivedCommand == ON){
            Remote_Send_Args.sendCommand("11111 1 1")
        }else{
            Remote_Send_Args.sendCommand("11111 1 0")
        }

        // send the command e.g. 5 times
        while((i=i+1) < 6){
            Remote_Send.sendCommand(ON)

            // wait for the command to complete
            while(Remote_Send.state != OFF){
                Thread::sleep(500)
            }
        }

        logInfo("Power_Plug", "Result:" + Remote_Send_Out.state )
end

I know that I could just edit and test the rule until it works but I’d like to get into openHAB and understand how it’s working.

Best regards
Jannis