Exec Binding on Raspi for 433 MHz

sounds like the best option… i didn’t know about the legacy options thank you

Hi Rob,
your post from feb, but I would have a question.

I did the setup for the 433 MHz devices as shown in the link from your post. I am getting an error when executing the .sh script in the shell. The error message is

./switchOff.sh: line 2:  5067 Segmentation fault      /opt/rc-switch/rcswitch-pi/send 11011 $1 0

My script looks like this:

#!/bin/bash
for run in {1..5}
do
/opt/rc-switch/rcswitch-pi/send 11011 $1 0
done

I also added my user openhabian to the sudo visudo groups as following:

# User privilege specification 
openhabian ALL=NOPASSWD: /opt/rc-switch/switch*

which is the correct folder for the .sh script. By terminal it is possible for me to switch the light on or of. But not by openHab. Exec Binding is installed by Paper UI and I assume when it it possible to execute the .sh file my item definition will work as well.

Can someone help me?

I recognise the Segmentation fault error message, but can’t remember the cause. I think it was permissions related and if you can run it from the CLI I’d say that’s the case. What user is Openhab running under? Can you add that to the visudo group too?

I’ve since moved away from using a Pi with the Exec Binding and now have an ESP with an RF module hooked up so I can turn things on and off via MQTT.

Hi Rob,

thank you for the response.

I am running openhabian and the user is there as well openhabian. Connecting ssh with 8180 I am using the user openhanded. I will try tomorrow to ad this user as well to the visudo group. Main problem is that I can’t execute the .sh file which is required for the exec command from openHab system afterwards.

Any other guesses?

I was able to solve the segmentation fault issue. I had to create a thing and ad the following command:

.things:
Thing exec:command:on [command="/opt/rc-switch/switchOn.sh 3"]
Thing exec:command:off [command="/opt/rc-switch/switchOff.sh 3"]

After that with the following .item command:

.items
Switch ONLAmpe2		"Lampe2 On" 	{ channel="exec:command:on:run"}
Switch OFFLAmpe2	"Lampe2 Off" 	{ channel="exec:command:off:run"}

I am now able to switch the light on and off. The only thing I am wondering about is that after switching the light on, some seconds after this action, the lamp gets switched of again and on and off…I have no clue why. Any thoughts?

2017-10-08 18:12:46.769 [ItemStateChangedEvent ] - ONLAmpe2 changed from OFF to ON
2017-10-08 18:12:47.283 [ItemStateChangedEvent ] - ONLAmpe2 changed from ON to OFF
2017-10-08 18:13:23.052 [ItemStateChangedEvent ] - ONLAmpe2 changed from OFF to ON
2017-10-08 18:13:25.554 [ItemStateChangedEvent ] - ONLAmpe2 changed from ON to OFF

How close are your neighbours? Try another channel maybe?

Do you see the switch change state in OpenHAB?

Hi Rob,

neighbors shouldn’t be the problem - or they play around a lot ;-).

Changed the channel now to:

channel="exec:command:ON:input"

Still no changes.

Is my .sh correct?

Switch status is changing but I don’t achieve to use just one switch for ON and OFF. I assume I have to change the .items line to combine on and off for one switch. I will search further…

It looks like you’re using the 2.0 exec binding which I don’t have any experience of, so can’t help with channels. Sorry.

Hey
I’m a beginner with Openhab but maybe my syntax can help. I’m using Openhab 2 with the exec Binding 2.1.0 (current one).

.items:

String dose_00011_1 “Stehlampe Schreibtisch” [ “Switchable” ] { channel=“exec:command:funkdose_control_1:input”, channel=“exec:command:device-nas-status:output”, autoupdate=“false” }

.things:

Thing exec:command:funkdose_control_1 [ command=“sudo /opt/raspberry-remote/send 00011 1 %2$s”, interval=0, autorun=true ]

.sitemaps:
Switch item=dose_00011_1 mappings=[“1”=“An”, “0”=“Aus”]

Hope this helps !

1 Like

works with the app and the HABPanel

Hi all, this is how I send my 433 commands.

I’m using 433Utils: https://github.com/ninjablocks/433Utils

Basically I have just one thing and one item for the EXEC binding. I send different strings to that through a rule. autorun=true makes sure that the exec command is executed once the input changes (by the rule). In the rule, I always repeat the command, then 0, then the command (essentially sending the command twice) as sometimes the RF-switch did not react. Now it works perfectly!

Make sure that interval = 0 means the command is NOT repeated (otherwise the default is 5 sec i believe, @Woogi).

The other 3 items are just the switches I used for the UI which trigger the different rules.

A bit complicated maybe but works fantastic!

// THING 433 switches
Thing exec:command:433switch [command="/home/openhabian/433Utils/RPi_utils/codesend %2$s", interval=0, timeout=10, autorun=true ]

// ITEMS
Switch RFSwitch1 "Media Center"
Switch RFSwitch2 "TV"
Switch RFSwitch3 "Bedroom Light" (BedroomLights)
String RFString "RF String" {channel="exec:command:433switch:input"}

// RULES
rule "433 Switch 1"
when
    Item RFSwitch1 changed
then
    if(RFSwitch1.state == ON) {
        sendCommand(RFString, "1381717")
        Thread::sleep(1000)
        sendCommand(RFString, "0")
        Thread::sleep(1000)
        sendCommand(RFString, "1381717")
    }
    else {
        sendCommand(RFString, "1381716")
        Thread::sleep(1000)
        sendCommand(RFString, "0")
        Thread::sleep(1000)
        sendCommand(RFString, "1381716")
    }
end

rule "433 Switch 2"
when
    Item RFSwitch2 changed
then
    if(RFSwitch2.state == ON) {
        sendCommand(RFString, "1394005")
        Thread::sleep(1000)
        sendCommand(RFString, "0")
        Thread::sleep(1000)
        sendCommand(RFString, "1394005")
    }
    else {
        sendCommand(RFString, "1394004")
        Thread::sleep(1000)
        sendCommand(RFString, "0")
        Thread::sleep(1000)
        sendCommand(RFString, "1394004")
    }
end

rule "433 Switch 3"
when
    Item RFSwitch3 changed
then
    if(RFSwitch3.state == ON) {
        sendCommand(RFString, "1397077")
        Thread::sleep(1000)
        sendCommand(RFString, "0")
        Thread::sleep(1000)
        sendCommand(RFString, "1397077")
    }
    else {
        sendCommand(RFString, "1397076")
        Thread::sleep(1000)
        sendCommand(RFString, "0")
        Thread::sleep(1000)
        sendCommand(RFString, "1397076")
    }
end



// SITEMAP
Switch    item=RFSwitch2 label="TV"	
Switch    item=RFSwitch1 label="Mediacenter Plug"
Switch    item=RFSwitch3 label="Bedroom Light"

Hey David,

your code sounds more understanding than my one, but unfortunately, it doesn’t work with my Pi. Do you need special rights or something like this ?

Dominik

And whats you sitemap for this ?

Hi,

I’m using the 433Utils (updated the post with the link. I’ve installed it to the homefolder and it works after compiling).

I added the sitemap to the post above -> it’s just a switch with ON and OFF, works perfectly :slight_smile:

Hi both, thanks for your reply.

@domeninini: how is the second thing definition for your NAS status? Could you post this as well?

@SpaceGlider: in your rule, if you switch on, you send the house code and “0”, why not “1” for on and why again the number?

Kindly

The code is the RF-code to switch ON (or OFF) the individual plug. This may differ from type to type. The “0” is sent only because the EXEC only executes when the input changes. If I send the code twice, EXEC will do nothing because the value did not change. That is why I go from the code to 0 and back to the code. I had to “sniff” the code with the receiver part. I just wanted to demonstrate my OH2 setup with rules and items. If you found a way to make your plugs switch, why not use your things/items with a rule too?

Martin,

I don’t know exactly what you mean with “NAS status” and “second definition” - I only have that one and only thing definition I wrote on the top. Maybe it helps to see my whole files (caution, now a long file follows…)

ITEMS - FILE

GNU nano 2.7.4                                                                                                Datei: mittag.items                                                                                                           

Group gWeather
Number Graz_Temperatur "Aussentemperatur [%.1f °C]" <temperature> (gWeather) { channel="yahooweather:weather:graz:temperature" }
Number Graz_Humidity   "Luftfeuchtigkeit [%d %%]"   <humidity>    (gWeather) { channel="yahooweather:weather:graz:temperature" }
Number Graz_Pressure   "Luftdruck [%.1f mbar]"      <pressure>    (gWeather) { channel="yahooweather:weather:graz:pressure" }


// GROUPS


Group:Switch:OR(ON,OFF) alllamps "All Lights"



// WOHNZIMMER

String dose_00011_1 "Stehlampe Schreibtisch" <light>  (Alle_Lampen)                             [ "Switchable" ] { channel="exec:command:funkdose_control_1:input", channel="exec:command:device-nas-status:output", autoupdate="false" }
String dose_00011_2 "Stehlampe Sofa"         <light>  (Alle_Lampen)                             [ "Switchable" ] { channel="exec:command:funkdose_control_2:input", channel="exec:command:device-nas-status:output", autoupdate="false" }

String dose_00010_1 "Schreibtischlampe"      <network>                             [ "Switchable" ] { channel="exec:command:funkdose_control_3:input", channel="exec:command:device-nas-status:output", autoupdate="false" }
String dose_00010_2 "Lowboard Lampe"         <network>                             [ "Switchable" ] { channel="exec:command:funkdose_control_4:input", channel="exec:command:device-nas-status:output", autoupdate="false" }
String dose_00010_3 "Couchtisch Beleuchtung" <network> (licht, gMyLights) [ "Switchable" ] { channel="exec:command:funkdose_control_5:input", channel="exec:command:device-nas-status:output", autoupdate="false" }
String dose_00010_4 "LED Lowboard"           <network> (licht, gMyLights) [ "Switchable" ] { channel="exec:command:funkdose_control_6:input", channel="exec:command:device-nas-status:output", autoupdate="false" }
String dose_00010_5 "Vitrine"                <network> (licht, gMyLights) [ "Switchable" ] { channel="exec:command:funkdose_control_7:input", channel="exec:command:device-nas-status:output", autoupdate="false" }

THINGS - FILE

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

Thing exec:command:funkdose_control_3 [ command="sudo /opt/raspberry-remote/send 00010 1 %2$s", interval=0, autorun=true ]
Thing exec:command:funkdose_control_4 [ command="sudo /opt/raspberry-remote/send 00010 2 %2$s", interval=0, autorun=true ]
Thing exec:command:funkdose_control_5 [ command="sudo /opt/raspberry-remote/send 00010 3 %2$s", interval=0, autorun=true ]
Thing exec:command:funkdose_control_6 [ command="sudo /opt/raspberry-remote/send 00010 4 %2$s", interval=0, autorun=true ]
Thing exec:command:funkdose_control_7 [ command="sudo /opt/raspberry-remote/send 00010 5 %2$s", interval=0, autorun=true ]

SITEMAPS - FILE

sitemap default label="Dominik und Helena"
{
     Frame label="Wohnzimmer" {
   //Switch item=alllamps
     Switch item=dose_00010_1 mappings=[1="An", 0="Aus"]
     Switch item=dose_00010_2 mappings=[1="An", 0="Aus"]
     Switch item=dose_00010_3 mappings=[1="An", 0="Aus"]
     Switch item=dose_00010_4 mappings=[1="An", 0="Aus"]
     Switch item=dose_00011_1 mappings=[1="An", 0="Aus"]
     Switch item=dose_00011_2 mappings=[1="An", 0="Aus"]
     Switch item=dose_00010_5 mappings=[1="An", 0="Aus"]
    }

Frame label="Wetter in Graz von Yahoo" {
   Text item=Graz_Temperatur
   Text item=Graz_Humidity
   Text item=Graz_Pressure
   Text item=Date
    }
}

Not be confused with the group “alllaps” - this doesn’t work yet !

I just wrote a tutorial about how this works in OpenaHAB2. This does not execute with sudo but if you need to read how to get sudo working with exec.

Hi erverybody!!

Sorry for the late response, I had to reinstall openhabian from scratch again, but now, thank to @domeninini, @Rob_Pope and @Josar I was able to switch the blogs based on the tutorial from the previous post. Thank you so much!

@domeninini I meant the peace of code: "

I did not understand where the device-nas-status is used for.

But due to the fact that it is solved, thanks again and enjoy your Sunday!

Nice to hear this ! Your welcome :wink: