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

@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

Thank you @Josar for this great thread.
I’m up and running now, except for one thing, for which I would really appreciate your input.

I’m using the exec binding to control my Air Conditioning unit (AC) through a WEB interface.
With the control (aka POST) bit in place, how would you go about getting polled (aka GET) values returned by a bash script into the exec:command framework?
(My current script returns “0” or “1” for OFF or ON, for temperature values strings like “23.5” are returned.)

I want to regularly refresh/update AC values in OH2 because AC parameters can be changed from phone APP(s) or even the AC remote. (There is no working OH1/OH2 binding for my AC)

Cheers

@Jannis501 i would also do it like this. But did not test it for validity.

But i think the command will automatically send 3 times by the routine. So you should think about better placement or antenna setup.

Maybe you need an additional sleep after the wait for the transceiver to be available again.

@OMR did you had a look at the http binding? I think that is what you need.

https://docs.openhab.org/addons/bindings/http1/readme.html

Looks interesting, but I already done the http part in my bash scripts.
I feel that the polling bit is the only thing lacking from the exec2 binding, but it can perhaps be achieved with the use of a timer and a post-update into the virtual switch.

Then you have multiple options.

  1. set up a thing with Intervall for each value you want to update.
  2. set up a rule with a cron expression. And trigger the updates in the rule.

But i still think your solution has more overhead then doing it with the http binding.

1 Like

so after reading and going through a lot of sites and this page here I was not really able to get it happening but I think I’m close to to where I wanted to be but please I need some more help, I would like if someone can point me to the right path for setting up my 433MHZ door sensor. I have installed 433UTILS into my Pi since I find it easier to deal with, please tell me where I went wrong, here is what my items, rules and things look like :
RULES : rule "DOORSENSOR"
when
Item DOORSENSOR chaned to OPEN
then
postUpdate (433Utils/RPi_utils.state == OPEN){
}

if(receivedCommand == 14756833){ postUpdate DOORSENSOR.statusCommand =(“OPEN”) }else{ if DOORSENSOR.stateCommand =(“CLOSE”) postUpdate (433Utils/RPi_utils.state == CLOSE) }

end

ITEMS : Switch DOORSENSOR { channel=“exec:command:./RFSniffer:run” }
String DOORSENSOR { channel=“exec:command:./RFSinffer:input” }

THINGS :Thing exec:command:./RFSniffer [
command="/home/pi/433Utils/RPi_utils/./RFSniffer 14756833",
interval=2,
autorun=true]

I need statues for OPEN/CLOSE for door sensor to appear on habpanel. Using Raspberry Pi 3 with OH2