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

execbinding
433mhz
wiringpi
Tags: #<Tag:0x00007f6ce94f8de8> #<Tag:0x00007f6ce94f8bb8> #<Tag:0x00007f6ce94f8a28>

(Josar) #1

I started as absolut beginner with openhab and had some trouble getting things to work, so had a thread where i got helpt to get the 433MHz transmitter working with OpenHAB and the Exec Binding 2.x. This I will post now as an Tutorial.

I set up a fresh istallation of “Raspbian GNU/Linux 9 (stretch)” and installed OpenHAB just followed my own thread and found some more information i missed at the first time. It is based on the Tutorial from here.

First make sure you connect your transmitter with the Raspberry like follows. Have a look at the RPI pinout.

Pin ATAD Data to 11 - GPIO17 
Pin GND       to 6  - GND 
Pin VCC       to 4  - +5V

433mhzsender-300x123

As raspberry-remote uses wiringpi make sure it is installed.

gpio -v
gpio readall

If this does not work install wiringpi as described by Gordons Projects. Or use apt-get as described in the wiringPi package

Now we need some executable program which controls the transmitter. We can use the raspberry-remote for that. It has to be build, copied to a folder and the user privileges for openhab has to be set. if you change the directory make sure you do it everywhere.

mkdir SourceCode
cd SourceCode
git clone https://github.com/xkonni/raspberry-remote.git
cd raspberry-remote
make send 

This is the remote which is delivered with the power plugs, it can control 4 devices A, B, C, D.

I configured my device to match the Address 10010 and the device B(2) as seen in the picture. Replace the Address and the device number to match your setting.

Try sending a command to your device with ./send <Address> <Device Number> <Off/On>.

./send 10010 2 1

Add openhab or openhabian, 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/openhabian.

sudo adduser openhab gpio
sudo -u openhab SourceCode/raspberry-remote/send 10010 2 1

Then the exec Binding and regex transformation have to be installed i use the Karaf 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.
I recommend that you had allready opened the UI of OpenHAB once before configuring the Basic UI, which this tutorial explains. Try to open it in your browser, edit localhost to the IP of you RPI if you open the page from an other device.

http://localhost:8080/start/index

Back to the shell 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.

sudo nano /etc/openhab2/things/exec.things
 Thing exec:command:remote-send [
            command="/home/pi/SourceCode/raspberry-remote/send %2$s",
            interval=0,
            autorun=true]
  1. “exec:command” refers to the binding. “:remote-send” is an arbitrary name.
  2. “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. It Is transformed by the “openhab-transformation-regex”.
  3. “interval=0” disables periodic execution
  4. “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 are located at “/etc/openhab2/items/powerplugs.items”

sudo nano /etc/openhab2/items/powerplugs.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" }
  1. 3 switch items [Power_Plug_Socket_A, _B, _AB] with an arbitrary name and the icon of a poweroutlet. This are used to define the layout of the UI later and store the state of the UI.
  2. 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.
  3. 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.
  4. 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”.

sudo nano /etc/openhab2/sitemaps/powerplugs.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"
    }
}

This is explained in detail in 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”.

sudo nano /etc/openhab2/rules/powerplugs.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("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", "Result:" + 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.

Try to open the page to display the switches, access it via following command, edit localhost to the IP of your RPI if you open the page from an other device.

http://localhost:8080/basicui/app

To also control power plug A copy paste the rule for "Poweroutlet B" and change Power_Plug_Socket_B to Power_Plug_Socket_A. Also change both sendCommand("10010 2 0/1") to sendCommand("10010 1 0/1").

If you want to control A and B with a rule for "Poweroutlet AB", have a look at the git page of the remote which explains in detail the usage. So again copy the rule change the rule to "Poweroutlet AB" and change Power_Plug_Socket_B to Power_Plug_Socket_AB. Also change the sendCommand("10010 2 1") to sendCommand("10010 1 10010 2 1"). This sends the command on to both plugs A(1) and B(2). I will refrain from explaining C and D as a challenge. The raspberry-remote can also control more then 4 devices but then the remote is useless, again have a look at the git page. I think explaining it with the remote increases the understandability and helps to distinguish.

Copying the rule will produce a lot of multiple code so please have a look at this post explaining how to use groups.

Additional:
Logging can be done with

ssh -p 8101 openhab@localhost
Password:habopen
openhab> log:tail

A side note: in the the OpenHab terminal the items can be listet with the command “smarthome:items”.

openhab>smarthome:items list
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.
Also @twolthaus and @domeninini for pointing out minor typos and privilege specification wich leaded me to the group permissions for the openhab user and the gpio, which is the best solution i could think of, in place of root for openhab.


Frequent seen logging

[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 in the command the transformation of the input channel is use. So having %2$s in the command and the command is triggered before there is an value in the input channel.
Or when the exec binding is triggered by .sendCommand to the run channel instead of the input channel.

 [ERROR] [.script.engine.ScriptExecutionThread] - Rule 'Poweroutlet B': An error occurred during the script execution: The name '<unkown>' cannot be resolved to an item or type.

After i edited the items and rules for all 3 GUI switches i had this error. Restarting the RPI got it runningn

[hab.binding.exec.handler.ExecHandler] - Couldn’t transform response because transformationService of type ‘REGEX’ is unavailable

You forgot to install the regex transformation service.


Rules with Groups

@domeninini found some time, this would be my solution.
@rlkoshak do you have any suggestions to improve the rules? Is it possible to reduce this to one? One thing which bothers me is, when pressing the group switch all switches will be updated thus the group rule will fire and then four times the single rule. Is there a way to prevent that. Are there special triggers for group items and where would this documented?

  1. Set mapdb persistance

openhab2/persistence/mapdb.persist

Strategies {
        default = everyUpdate
}

Items {
        // persist all items on every change and restore them from the db at startup
        * : strategy = everyChange, restoreOnStartup
}
  1. Change Items to be grouped and also the names from Power_Plug_Socket_A to Power_Plug_Socket_1 which is used to encode the number for sending the command.
Group:Switch:OR(OFF, ON) gPlugs <poweroutlet>

Switch Power_Plug_Socket_1 <poweroutlet> (gPlugs)
Switch Power_Plug_Socket_2 <poweroutlet> (gPlugs)
Switch Power_Plug_Socket_3 <poweroutlet> (gPlugs)
Switch Power_Plug_Socket_4 <poweroutlet> (gPlugs)
  1. Change sitemap
sitemap powerplugs label="Wireless Poweroutlets"
{
        Frame label="Poweroutlets"
        {
          Switch item=Power_Plug_Socket_1 label="Power Plug A"
          Switch item=Power_Plug_Socket_2 label="Power Plug B"
          Switch item=Power_Plug_Socket_3 label="Power Plug C"
          Switch item=Power_Plug_Socket_4 label="Power Plug D"

          Switch item=gPlugs label="All Plugs"
        }
}
  1. Change rules
rule "Single Plug"
  when
    Item gPlugs received update
  then
    // give persistence time to catch up
    Thread::sleep(100)

    val plug = gPlugs.members.filter[s|s.lastUpdate("mapdb") !==null].sortBy[lastUpdate("mapdb")].last as SwitchItem
    val num = plug.name.toString.split("Power_Plug_Socket_").get(1)
    
    logInfo("Power_Plugs", "Switch Socket "+ num +" to " + plug.state )
    
    // wait if transmitter is used from other rule
    // State will be NULL if not used before 
    // or ON while command is executed
    while(Remote_Send.state == ON){
        Thread::sleep(500)
    }

    if(plug.state == ON){
      Remote_Send_Args.sendCommand("10010 " + num +" 1")
    }else{
      Remote_Send_Args.sendCommand("10010 " + num +" 0")
    }

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

rule "All Plugs"
  when
  // using "received command" to avoid trigger 
  // when gPlugs is Updated when the last Switch is pressed
  // only trigger when switch is actually changed by user
    Item gPlugs received command
  then
    // give system some time 
    // doesn't work everytime when this delay is removed
    Thread::sleep(100)

    logInfo("All_Power_Plugs", "Switch all Sockets to " + gPlugs.state )

    // wait if transmitter is used from other rule
    // State will be NULL if not used before 
    // or ON while command is executed
    while(Remote_Send.state == ON){
        Thread::sleep(500)
    }

    if(gPlugs.state == ON){
      Remote_Send_Args.sendCommand("10010 1 10010 2 10010 3 10010 4 1")
    }else{
      Remote_Send_Args.sendCommand("10010 1 10010 2 10010 3 10010 4 0")
    }

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

As of openHAB 2.2 Rules for groups are a lot easier
have a look here for more details. Thanks again to @rlkoshak for pointing out this feature.

  1. No persistance
  2. Just grouping
  3. One rule
  4. Adding a lock, so the execution of the rule is blocked all member are change by the group.
Group:Switch:OR(OFF, ON) gPlugs <poweroutlet>

Switch Power_Plug_Socket_1 <poweroutlet> (gPlugs)
Switch Power_Plug_Socket_2 <poweroutlet> (gPlugs)
Switch Power_Plug_Socket_3 <poweroutlet> (gPlugs)
Switch Power_Plug_Socket_4 <poweroutlet> (gPlugs)

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" }
import java.util.concurrent.locks.ReentrantLock

val ReentrantLock transmitter = new ReentrantLock

rule "Single Plug"
  when
    Item Power_Plug_Socket_1 received command or
    Item Power_Plug_Socket_2 received command or
    Item Power_Plug_Socket_3 received command or
    Item Power_Plug_Socket_4 received command 
  then
    // give system time to catch up
    //Thread::sleep(200)

    logInfo("Power_Plug", "Member " + triggeringItem.name + " to " + receivedCommand)
    

    try {
      // lock transmitter so other executed rules dont#t use it at the same time
      transmitter.lock()
      val num = triggeringItem.name.toString.split("Power_Plug_Socket_").get(1) 
      
      if(receivedCommand == ON){
        Remote_Send_Args.sendCommand("10010 " + num +" 1")
      }else{
        Remote_Send_Args.sendCommand("10010 " + num +" 0")
      }

      // wait for the command to complete
      while(Remote_Send.state != OFF){
          Thread::sleep(100)
      }
      // mulltiple trigger do not work if there is no break here
      // maybe external skript needs some time to properly free resources.
      Thread::sleep(400)
      logInfo("Power_Plug", Remote_Send_Out.state.toString.replaceAll("\r|\n"," ") )

    }catch(Throwable t) {}
    finally {
        transmitter.unlock()
    }
 end

Be aware of the implicite variables triggeringItem and receivedCommand


LED Stripes
I will post my solution for my LEDs stripes as additional example.

This is the LED controller and the RF remote.
remote

I decoded the commands which the remote send with RFSniffer from 433Utils which also contains send and sendcode to controll the transceiver.

So getting it done is then straight forward, just add a thing, items, a sitemap and a rule to controll the LED stripe.

exec.things

Thing exec:command:remote-codesend [
            command="/home/pi/SourceCode/433Utils/RPi_utils/codesend %2$s",
            interval=0,
            autorun=false]

ledStripe.itmes

// LED Stripe 433MHz
Group:Switch:OR(OFF, ON) gLedStripe_1

Switch LED_Stripe_OnOff (gLedStripe_1)
Switch LED_Stripe_LightMode (gLedStripe_1)
Switch LED_Stripe_BrightUp (gLedStripe_1)
Switch LED_Stripe_BrightDown (gLedStripe_1)
Switch LED_Stripe_100 (gLedStripe_1)
Switch LED_Stripe_50 (gLedStripe_1)
Switch LED_Stripe_25 (gLedStripe_1)
String PlaceHolder ""
Switch LED_Stripe_ModeNext (gLedStripe_1)
Switch LED_Stripe_ModePrev (gLedStripe_1)
Switch LED_Stripe_faster (gLedStripe_1)
Switch LED_Stripe_slower (gLedStripe_1)

Switch Remote_CodeSend      { channel="exec:command:remote-codesend:run"    }
String Remote_CodeSend_Args { channel="exec:command:remote-codesend:input"  }
String Remote_CodeSend_Out  { channel="exec:command:remote-codesend:output" }

ledStripe.sitemap

sitemap ledStripelabel="Wireless ledStripe"
{
        Frame label="LED Stripe"
        {
          Switch item=LED_Stripe_OnOff label="ON/OFF"
          Switch item=LED_Stripe_LightMode label="Light"
          Switch item=LED_Stripe_100 label="100%"
          Switch item=LED_Stripe_50 label=" 50%"
          Switch item=LED_Stripe_25 label=" 25%"
          Text item=PlaceHolder label="" icon="none"         
          Switch item=LED_Stripe_BrightUp label="Brightness +"
          Switch item=LED_Stripe_BrightDown label="Brightness -"
          Switch item=LED_Stripe_ModeNext label="Mode Up"
          Switch item=LED_Stripe_ModePrev label="Mode Down"
          Switch item=LED_Stripe_faster label="Speed Up"
          Switch item=LED_Stripe_slower label="Speed Down"
        }
}

ledStripe.rules

import java.util.concurrent.locks.ReentrantLock

val ReentrantLock transmitter = new ReentrantLock

rule "LED Stripe 1"
  when
  // this will get easier with feature release 
    Item LED_Stripe_OnOff received command or
    Item LED_Stripe_LightMode received command or
    Item LED_Stripe_BrightUp received command or
    Item LED_Stripe_BrightDown received command or
    Item LED_Stripe_100 received command or
    Item LED_Stripe_50 received command or
    Item LED_Stripe_25 received command or
    Item LED_Stripe_ModeNext received command or
    Item LED_Stripe_ModePrev received command or
    Item LED_Stripe_faster received command or
    Item LED_Stripe_slower received command 
  then
    
    //logInfo("LED_Stripe", "Member " + triggeringItem.name + " to " + receivedCommand)
    
    try {
      // lock transmitter so other executed rules dont't use it at the same time
      transmitter.lock()
      // manual reset, somehow it get stuck sometimes. This avoids a lock when state of Remote_CodeSend is not updated properly.
      Remote_CodeSend.sendCommand(OFF)

      switch triggeringItem.name {
        case "LED_Stripe_OnOff"     : Remote_CodeSend_Args.sendCommand("11607809")
        case "LED_Stripe_LightMode" : Remote_CodeSend_Args.sendCommand("11607812")
        case "LED_Stripe_BrightUp"  : Remote_CodeSend_Args.sendCommand("11607813")
        case "LED_Stripe_BrightDown": Remote_CodeSend_Args.sendCommand("11607814")
        case "LED_Stripe_100"       : Remote_CodeSend_Args.sendCommand("11607815")
        case "LED_Stripe_50"        : Remote_CodeSend_Args.sendCommand("11607816")
        case "LED_Stripe_25"        : Remote_CodeSend_Args.sendCommand("11607817")
        case "LED_Stripe_ModeNext"  : Remote_CodeSend_Args.sendCommand("11607819")
        case "LED_Stripe_ModePrev"  : Remote_CodeSend_Args.sendCommand("11607821")
        case "LED_Stripe_faster"    : Remote_CodeSend_Args.sendCommand("11607823")
        case "LED_Stripe_slower"    : Remote_CodeSend_Args.sendCommand("11607825")
        default                     : logInfo("LED", "Error in switch!")
      }

      // manual trigger transmitter
      // If Remote_CodeSend_Args is set to the same value it does not trigger when autorun=true,
      // so set autorun=false and use manual trigger to be able to trigger one command multiple times.
      Remote_CodeSend.sendCommand(ON)

      // wait for the command to complete
      while(Remote_CodeSend.state != OFF){
         Thread::sleep(100)
      }
      //logInfo("LED_Stripe", Remote_CodeSend_Out.state.toString.replaceAll("\r|\n"," ") )

      // reset switch signalize command is finished
      triggeringItem.postUpdate(OFF)
 
    }catch(Throwable t) {}
    finally {
        transmitter.unlock()
    }
 end  

Exec Binding on Raspi for 433 MHz
OpenHAB sudo [Exec Binding]
Shutdown Pi using exec binding in OH2.1 (openhabian)
Looking for the ultimate beginners guide
Group rules trigger
Pass parameters to bash script
Is there a better way?
Simple On/Off Switch with Exec-Command
Simple On/Off Switch with Exec-Command
How to show DHT22 stats on HAB panel
Running a python script when Channel triggered
433 MHz sendCommand problem
Exec 2 Binding: Multiple outputs?
Wireless sockets in openhab
Permissions issue when running a python script
Check for status before Triggering Command
When using apt-get install, how to monitor errors and troubleshoot?
Openhab2 RPI System Temperature and DS18B20 OneWire Chart with persistence
Which user and rights for executeCommandLine?
Receiving 433mhz and send to sonoff switch
Exec binding with php script return data
Old heating upgrade with servomotor, raspberry and openHAB
Read GPIO state ,use it to change icon (switch)
No switch button in BasicUI
What basic skills do I need to use openHAB?
Rules execbindings DHT11 String
Backup Configuration Button in Sitemap - Run script
How to show DHT22 stats on HAB panel
No switch button in BasicUI
(Dominik B) #2

Understanding explaind. I will test this when finding a secondary SD-Card. Good Job :+1:


(Rich Koshak) #3

Fantastic tutorial! Thank you for contributing to the community.


BasicUI frustrating me
(Dominik B) #4

I tried the tutorial and it works well !
For those of you who want to add more than just one sockets, you only have to add

Switch Power_Plug_Socket_B_x <poweroutlet> 

in the items-file and replace the “_x” with a unique name. Further, add

Switch item=Power_Plug_Socket_B_x label="Power Plug B_x"

in the sitemap-file and again, replace the “_x” with a arbitrary but unique name.

The rule I copied 1:1 but replaced the names again.

@Josar Could you please implement a group, which is able to switch all those sockets at once ?


(Josar) #5

@domeninini I added some more information to the tutorial maybe you schould read it carefully. :face_with_raised_eyebrow: :wink:
I used Switch Power_Plug_Socket_A <poweroutlet> instead of Switch Power_Plug_Socket_B_x <poweroutlet> which better represents the remote.
I also showed executing multiple devices with one dedicated switch AB.
If i find some more time i will post a setting which reduces the code by using groups, or someone working throught this could do that. :smirk:


(Peter) #6

Hy. I hope I find help here. I’ve been trying to use a 433 mhz module for a long time with openhab.
I can use it in the shell with the following command: /home/openhabian/433Utils/RPi_utils/./codesend 13108705.

And now I try desperately to integrate this command with exec binding (version 2). I hope who can help, I try to send the command as a push button.
Where is my mistake? Post my composition. Thank you

.things

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

.sh

#!/bin/sh


if [ "$1" = "off" ] || [ "$1" = "0" ] || [ "$1" = "OFF"  ]; then
        /home/openhabian/433Utils/RPi_utils/./codesend 13108705
else
        /home/openhabian/433Utils/RPi_utils/./codesend 13108705
fi

rule

rule "Poweroutlet B"
  when
    Item Wohnzimmer_Decke received command
  then
     if(receivedCommand == ON){
        Remote_Send_Args.sendCommand("13108705")
     }else{
       Remote_Send_Args.sendCommand("10010 2 0")
     }

      // wait for the command to complete, state will be NULL if not used befor$
      while(Remote_Send.state != OFF){
         Thread::sleep(500)
      }
      logInfo("Power_Plug", "Resuts are: \n" + Remote_Send_Out.state )
end

.items

Group Licht_EG "Licht" 

Switch Wohnzimmer_Decke (Licht_EG) [ "Switchable" ] { channel="exec:command:Wohnzimmer_Decke:run", autoupdate="false" }

.sitemap

sitemap Schneeberggasse16 label="Erdgeschoss" {
    Frame label="Licht" {
        Switch item=Wohnzimmer_Decke mappings=[ "ON"="ON" ] icon="light"
        Switch item=Wohnzimmer_Led mappings=[ "ON"="ON", "OFF"="OFF" ]
        Switch item=steckdoseG3Switch mappings=[ "ON"="ON", "OFF"="OFF" ]
        Switch item=steckdoseG4Switch mappings=[ "ON"="ON", "OFF"="OFF" ]
        
        Switch item=Licht mappings=[ "ON"="ON", "OFF"="OFF" ]
        
        Switch item=Dash_Switch
        }
}

(Josar) #7

Could you please format your post like you did here

Did you try to execute the command as user openhabian as explained?
This is a crucial step to make sure openhab is able to execute the command! Make sure to take the right user openhab for self installed, openhabian for openhabian.

Make sure to add openhab/openhabian to the group which is necessary to execute your commands. Most probably gpio. I don’t know what kind off 433MHz transciever you use.

Second you don’t need the shell Skript. Put your call to codesend in the thing as explained above in the tutorial. Have a closer look there.

Please post the output of

  1. Executions as user openhabian from commandline.
  2. After adding openhabian to the right group and successful executing 1. the output of the log from the rule.

(Peter) #8

Thank you . I will try this tomorow


(Peter) #9

Hy.
Have everything rebuilt now, it still not works. Where can my mistake lie.

wohzimmer.items

Group Licht_EG "Licht"

Switch Wohnzimmer

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" }

funklicht.sitemap

sitemap funklicht label="Erdgeschoss" {
    Frame label="Licht" {
        Switch item=Wohnzimmer icon="light"
        }
}

funklicht.things

Thing exec:command:remote-send [ command="/home/openhabian/433Utils/RPi_utils/./codesend %2$s", interval=0, autorun=true ]

wohnzimmer.rules

rule "Wohnzimmer"
  when
    Item Wohnzimmer received command
  then
     if(receivedCommand == ON){
        Wohnzimmer.sendCommand("13108705")
     }else{
       Remote_Send_Args.sendCommand("13108705")
     }

      // wait for the command to complete, state will be NULL if not used before or ON while command is executed
      while(Remote_Send.state != OFF){
         Thread::sleep(500)
      }
      logInfo("Wohnzimmer", "Resuts are: \n" + Remote_Send_Out.state )
end

etc/sudoers file edited with visudo , I hope the entries are correct.

#
# This file MUST be edited with the 'visudo' command as root.
#
# Please consider adding local content in /etc/sudoers.d/ instead of
# directly modifying this file.
#
# See the man page for details on how to write a sudoers file.
#
Defaults        env_reset
Defaults        mail_badpass
Defaults        secure_path="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"

# Host alias specification

# User alias specification

# Cmnd alias specification

# User privilege specification
root    ALL=(ALL:ALL) ALL
openhab ALL=(ALL) NOPASSWD: ALL
www-data ALL=(ALL) NOPASSWD: ALL
openhabian ALL=(ALL) NOPASSWD: ALL

# Allow members of group sudo to execute any command
%sudo   ALL=(ALL:ALL) ALL
openhab ALL=(ALL) NOPASSWD: ALL
www-data ALL=(ALL) NOPASSWD: ALL
openhabian ALL=(ALL) NOPASSWD: ALL
openhabian /home/openhabian/433Utils/RPi_utils/./codesend 13108705

# See sudoers(5) for more information on "#include" directives:

#includedir /etc/sudoers.d

and the log file

17:44:14.478 [INFO ] [el.core.internal.ModelRepositoryImpl] - Refreshing model 'wohnzimmer.items'
17:44:14.523 [WARN ] [el.core.internal.ModelRepositoryImpl] - Configuration model 'wohnzimmer.items' has errors, therefore ignoring it: [6,25]: missing '}' at 'Decke'
[6,30]: extraneous input '"  (Licht_EG) [ "' expecting RULE_ID
[6,76]: extraneous input ':' expecting RULE_ID

17:44:20.880 [WARN ] [basic.internal.render.SwitchRenderer] - Cannot determine item type of 'Wohnzimmer'
org.eclipse.smarthome.core.items.ItemNotFoundException: Item 'Wohnzimmer' could not be found in the item registry
        at org.eclipse.smarthome.core.internal.items.ItemRegistryImpl.getItem(ItemRegistryImpl.java:60)[98:org.eclipse.smarthome.core:0.9.0.b5]
        at org.eclipse.smarthome.ui.internal.items.ItemUIRegistryImpl.getItem(ItemUIRegistryImpl.java:658)[136:org.eclipse.smarthome.ui:0.9.0.b5]
        at org.eclipse.smarthome.ui.basic.internal.render.SwitchRenderer.renderWidget(SwitchRenderer.java:50)[176:org.eclipse.smarthome.ui.basic:0.9.0.b5]
        at org.eclipse.smarthome.ui.basic.internal.render.PageRenderer.renderWidget(PageRenderer.java:164)[176:org.eclipse.smarthome.ui.basic:0.9.0.b5]
        at org.eclipse.smarthome.ui.basic.internal.render.PageRenderer.processChildren(PageRenderer.java:129)[176:org.eclipse.smarthome.ui.basic:0.9.0.b5]
        at org.eclipse.smarthome.ui.basic.internal.render.PageRenderer.processChildren(PageRenderer.java:150)[176:org.eclipse.smarthome.ui.basic:0.9.0.b5]
        at org.eclipse.smarthome.ui.basic.internal.render.PageRenderer.processPage(PageRenderer.java:92)[176:org.eclipse.smarthome.ui.basic:0.9.0.b5]
        at org.eclipse.smarthome.ui.basic.internal.servlet.WebAppServlet.service(WebAppServlet.java:152)[176:org.eclipse.smarthome.ui.basic:0.9.0.b5]
        at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:812)[81:org.eclipse.jetty.servlet:9.2.19.v20160908]
        at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:587)[81:org.eclipse.jetty.servlet:9.2.19.v20160908]
        at org.ops4j.pax.web.service.jetty.internal.HttpServiceServletHandler.doHandle(HttpServiceServletHandler.java:71)[172:org.ops4j.pax.web.pax-web-jetty:4.3.0]
        at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:143)[80:org.eclipse.jetty.server:9.2.19.v20160908]
        at org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:577)[79:org.eclipse.jetty.security:9.2.19.v20160908]
        at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:223)[80:org.eclipse.jetty.server:9.2.19.v20160908]
        at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1127)[80:org.eclipse.jetty.server:9.2.19.v20160908]
        at org.ops4j.pax.web.service.jetty.internal.HttpServiceContext.doHandle(HttpServiceContext.java:287)[172:org.ops4j.pax.web.pax-web-jetty:4.3.0]
        at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:515)[81:org.eclipse.jetty.servlet:9.2.19.v20160908]
        at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:185)[80:org.eclipse.jetty.server:9.2.19.v20160908]
        at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1061)[80:org.eclipse.jetty.server:9.2.19.v20160908]
        at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:141)[80:org.eclipse.jetty.server:9.2.19.v20160908]
        at org.ops4j.pax.web.service.jetty.internal.JettyServerHandlerCollection.handle(JettyServerHandlerCollection.java:80)[172:org.ops4j.pax.web.pax-web-jetty:4.3.0]
        at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:97)[80:org.eclipse.jetty.server:9.2.19.v20160908]
        at org.eclipse.jetty.server.Server.handle(Server.java:499)[80:org.eclipse.jetty.server:9.2.19.v20160908]
        at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:311)[80:org.eclipse.jetty.server:9.2.19.v20160908]
        at org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:257)[80:org.eclipse.jetty.server:9.2.19.v20160908]
        at org.eclipse.jetty.io.AbstractConnection$2.run(AbstractConnection.java:544)[71:org.eclipse.jetty.io:9.2.19.v20160908]
        at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:635)[83:org.eclipse.jetty.util:9.2.19.v20160908]
        at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:555)[83:org.eclipse.jetty.util:9.2.19.v20160908]
        at java.lang.Thread.run(Thread.java:748)[:1.8.0_152]
17:44:20.890 [ERROR] [ui.internal.items.ItemUIRegistryImpl] - Cannot retrieve item 'Wohnzimmer' for widget org.eclipse.smarthome.model.sitemap.Switch
17:44:20.894 [ERROR] [ui.internal.items.ItemUIRegistryImpl] - Cannot retrieve item for widget org.eclipse.smarthome.model.sitemap.Switch
17:44:20.899 [ERROR] [ui.internal.items.ItemUIRegistryImpl] - Cannot retrieve item for widget org.eclipse.smarthome.model.sitemap.Switch
17:44:20.903 [ERROR] [ui.internal.items.ItemUIRegistryImpl] - Cannot retrieve item for widget org.eclipse.smarthome.model.sitemap.Switch
17:44:20.907 [ERROR] [ui.internal.items.ItemUIRegistryImpl] - Cannot retrieve item 'Wohnzimmer' for widget org.eclipse.smarthome.model.sitemap.Switch
17:44:20.911 [ERROR] [ui.internal.items.ItemUIRegistryImpl] - Cannot retrieve item 'Wohnzimmer' for widget org.eclipse.smarthome.model.sitemap.Switch
17:44:20.915 [ERROR] [ui.internal.items.ItemUIRegistryImpl] - Cannot retrieve item 'Wohnzimmer' for widget org.eclipse.smarthome.model.sitemap.Switch
17:44:23.028 [INFO ] [thome.io.rest.core.item.ItemResource] - Received HTTP POST request at 'items/Wohnzimmer' for the unknown item 'Wohnzimmer'.
17:44:23.896 [INFO ] [thome.io.rest.core.item.ItemResource] - Received HTTP POST request at 'items/Wohnzimmer' for the unknown item 'Wohnzimmer'.
17:49:14.246 [INFO ] [el.core.internal.ModelRepositoryImpl] - Refreshing model 'funklicht.things'
17:49:14.266 [INFO ] [smarthome.event.ThingRemovedEvent   ] - Thing 'exec:command:Wohnzimmer_Decke' has been removed.
17:49:14.274 [INFO ] [smarthome.event.ThingRemovedEvent   ] - Thing 'exec:command:Wohnzimmer_Led' has been removed.
17:49:14.285 [INFO ] [smarthome.event.ThingRemovedEvent   ] - Thing 'exec:command:Wohnzimmer_Deckecontrol' has been removed.
17:49:14.292 [INFO ] [smarthome.event.ThingRemovedEvent   ] - Thing 'exec:command:steckdoseG3-status' has been removed.
17:49:14.303 [INFO ] [smarthome.event.ThingRemovedEvent   ] - Thing 'exec:command:Wohnzimmer_Deckestatus' has been removed.
17:49:14.345 [INFO ] [smarthome.event.ThingUpdatedEvent   ] - Thing 'exec:command:remote-send' has been updated.
17:53:53.341 [INFO ] [thome.io.rest.core.item.ItemResource] - Received HTTP POST request at 'items/Wohnzimmer' for the unknown item 'Wohnzimmer'.
17:53:54.881 [INFO ] [thome.io.rest.core.item.ItemResource] - Received HTTP POST request at 'items/Wohnzimmer' for the unknown item 'Wohnzimmer'.
17:54:21.591 [INFO ] [thome.io.rest.core.item.ItemResource] - Received HTTP POST request at 'items/Wohnzimmer' for the unknown item 'Wohnzimmer'.
17:54:21.993 [INFO ] [thome.io.rest.core.item.ItemResource] - Received HTTP POST request at 'items/Wohnzimmer' for the unknown item 'Wohnzimmer'.
17:54:22.392 [INFO ] [thome.io.rest.core.item.ItemResource] - Received HTTP POST request at 'items/Wohnzimmer' for the unknown item 'Wohnzimmer'.
17:54:22.765 [INFO ] [thome.io.rest.core.item.ItemResource] - Received HTTP POST request at 'items/Wohnzimmer' for the unknown item 'Wohnzimmer'.
17:54:23.365 [INFO ] [thome.io.rest.core.item.ItemResource] - Received HTTP POST request at 'items/Wohnzimmer' for the unknown item 'Wohnzimmer'.

i hope you can help me.Thank you


(Josar) #10

Can you execute the command from commandline as user openhabian?

Why do you fiddle with sudoers?
Did you add openhabian to the gpio group?

What do you try to achieve here? Wohnzimmer ist a switch which can be on or off. Not a string.

Please try to follow the instructions step by step.

  1. Execute the command as user openhabian and post the result.
    Maybe the returned information will help getting the command to execute, mostly by adding the user to the group. Soduer rights are mostly not required.

Please remove all other stuff, as there are errors listet in the log which obviously contains data which is not listet here, which has errors.

And please use the preview to make sure the formating is properly, also or even more when copy pasting.

Sometimes/often it helps to restart the rpi when the files are changed a lot.

If it is really necessary to get sudoers for openHAB it is explained here


(Alex) #11

Hi Josar,

thank you very much for this tutorial. Everything works now and I´m very happy!

As I started with the “automatic” Installation by openhabian, I had a few things, that confused me. Perhaps someone else helps this out.

I was confused, in which Directory I should install the raspberry-remote, so I installed it in “/home/openhabian/” - which I guessed right - as I learned later :slight_smile:

As I had installed the raspberry-remote i got a error:

RCSwitch.h:31:26: fatal error: wiringPi.h: No such file or directory
     #include <wiringPi.h>
                          ^
compilation terminated.
<builtin>: recipe for target 'RCSwitch.o' failed
make: *** [RCSwitch.o] Error 1

so i figured out, that i have to install wiringPi first.

I upgraded my Raspberry with

sudo apt-get update && sudo apt-get upgrade

and Installed wiringPi in my “raspberry-remote” directory with

git clone git://git.drogon.net/wiringPi
cd wiringPi/
./build

After finishing this, i switched back in my raspberry-remote directory and now i could use

make send

The last Thing, I had to change, was in the exec.things-File. I had to change the Directory to this:

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

Thank you again for your hard work and this Tutorial! Now as Christmas is over, i´ll have to find some other Things, that i will switch on and off in the meantime :stuck_out_tongue_winking_eye:

Alex


(Josar) #12

@Lucky i think this should also work for installing wiringpi:

sudo apt-get install wiringpi 

But thank you for the hint for all who are using openhabian.


(Peter) #13

openhab / openhabian have always been users of gpio

[23:34:08] openhabian@openHABianPi:~$ sudo adduser openhabian gpio
[sudo] password for openhabian:
The user `openhabian' is already a member of `gpio'.
[23:44:00] openhabian@openHABianPi:~$ sudo adduser openhab gpio
The user `openhab' is already a member of `gpio'.
[23:44:14] openhabian@openHABianPi:~$  sudo -u openhabian /home/openhabian/433Utils/RPi_utils/./codesend 13108705
sending code[13108705]
[23:44:46] openhabian@openHABianPi:~$  sudo -u openhabian /home/openhabian/433Utils/RPi_utils/./codesend 13108705
sending code[13108705]
[23:46:21] openhabian@openHABianPi:~$

I just want to send the radio command (13108705 decimalcode) as a push button. I control radio modules that I integrate into my light circuit (surge circuit). as easy as it is possible I do not want to prove if it is on or off. if I press in openhab on the switch it should send once the radio command.

sudo -u openhabian /home/openhabian/433Utils/RPi_utils/./codesend 13108705

works without problems the wireless module, but in the log, nothing appears.

get the following errors when pressing the switch.

23:57:39.418 [INFO ] [thome.io.rest.core.item.ItemResource] - Received HTTP POST request at 'items/Wohnzimmer' for the unknown item 'Wohnzimmer'.

(Josar) #14
  1. GPIO , check.
  2. Commandline execution, check.
    There will be nothing logged, because it is not executed in openHAB, it is executed with the user rights of OpenHAB. And as this works we know there is something wrong with your thing, item, sitemap or rule.

Please edit your rule

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")

      // 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)

// Reset argument, as it will not trigger execution next time the rule executed if the argument is the same.
Remote_Send_Args.postUpdate(" ")

end

What happens? What is logged?


(Peter) #15

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

(Josar) #16

@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.


(Peter) #17

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

(Josar) #18

@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.


(Peter) #19

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


(Mu Hackl) #21

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