Thank you very very much, this is the solution.
Me as an absolute beginner can not understand how things run with a documentation which does not include all elements an how they play together.
So a will recap this and Post it for other who are in the same position, please correct me if I am wrong.
The raspberry-remote has to be build, copied to an folder and the user privileges for openhab has to be set. Change the path to match the path to your raspberry-remote.
mkdir SourceCode
cd SourceCode
git clone https://github.com/xkonni/raspberry-remote.git
cd raspberry-remote
make send
Add openhab to the usergroup gpio so it is allowed to acces the gpio of the RPI and then try to use the send command as user openhab. Replace the Adress and the Receiver Number to match your setting. The 1 at the end is the command for on, replace it with zero to shut off.
sudo adduser openhab gpio
sudo -u openhab SourceCode/raspberry-remote/send 10010 2 1
Then the exec Binding has to be installed via Paper UI or using the karaf console.
localhost:8080/paperui/index.html#/extensions
Search for exec and install the Binding. Also install regex transformation or open the console
ssh -p 8101 openhab@localhost
Password:habopen
feature:install openhab-binding-exec
feature:install openhab-transformation-regex
logout
Now everything should be ready for setting up the OpenHAB UI.
We start with a thing to connect to the exec binding. This will contain the command without or with parts of the arguments. This file will be at “/etc/openhab2/things/exec.things”. I called it “exec” like the binding.
Thing exec:command:remote-send [
command="/home/pi/SourceCode/raspberry-remote/send %2$s",
interval=0,
autorun=true]
- “exec:command” refers to the binding. “:remote-send” is an arbitrary name.
- “command=…” is the command line to execute, “%2$s” will be replaced by the command send to the input channel. Which connects an item to this thing.
- “interval=0” disables periodic execution
- “autorun=true” immediatly execute the command when the input channel got an command.
To connect the thing to the switch on the sitemap we need items. they the are located at “/etc/openhab2/items/powerplugs.items”
Switch Power_Plug_Socket_B <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" }
- A switch item with an arbitrary name and the icon of a poweroutlet. This is used to define the layout of the UI later and store the state of the UI.
- A Switch item connected to the run channel of our thing, this will contain information about the status of the thing, like is it running or not.
- A String item connected to the input channel of our thing. This can contain the arguments which will replace the “%2$s” at the thing definition.
- A String item connected to the output channel of our thing, This will contain the return value of the executed command.
To have an visual representation of our switch we need an sitemap. This is located at “/etc/openhab2/sitemaps/powerplugs.sitemap” and has to be named same as the sitemap, here “powerplugs”.
sitemap powerplugs label="Wireless Poweroutlets"
{
Frame label="Poweroutlets"
{
Switch item=Power_Plug_Socket_B label="Power Plug B"
}
}
This is explained int detail int the Tutiorials. Major detail is “item=Power_Plug_Socket_B” this connects the UI to the switch item which was defined previously.
Last thing to do is defining some rules which triggers desired actions. The rules are located at “/etc/openhab2/rules/powerplugs.rules”.
rule "Poweroutlet B"
when
Item Power_Plug_Socket_B received command
then
if(receivedCommand == ON){
Remote_Send_Args.sendCommand("10010 2 1")
}else{
Remote_Send_Args.sendCommand("10010 2 0")
}
// wait for the command to complete
while(Remote_Send.state != OFF){
Thread::sleep(500)
}
logInfo("Power_Plug", "Resuts are: \n" + Remote_Send_Out.state )
end
Rules are also explained in the Tutorials. Basic thing to get some action is “Remote_Send_Args.sendCommand(“10010 2 1”)” sending a command to the input channel. This will set the state of the item Remote_Send_Args to “10010 2 1” and the autorun defined in the thing will cause an execution of the command line. While the thing is in action the state of the item Remote_Send will reflect this by beeing “ON”. After the command is executed the item Remote_Send_Out will contain the last return value of the executed command.
A side note: in the the OpenHab terminal the items can be listet with the command “smarthome:items”.
openhab>smarthome:items
Power_Plug_Socket_B (Type=SwitchItem, State=OFF, Label=null, Category=poweroutlet)
Remote_Send (Type=SwitchItem, State=OFF, Label=null, Category=null)
Remote_Send_Args (Type=StringItem, State=10010 2 0, Label=null, Category=null)
Remote_Send_Out (Type=StringItem, State=using pin 0
sending systemCode[10010] unitCode[2] command[0], Label=null, Category=null)
Thank you rlkoshak and steve1 for your assistance. Hopefully this helps others understand how things work.
Additional:
[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''
This Error is displayed when the exec binding is triggered by .sendCommand to the run channel instead of the input channel.