Simple On/Off Switch with Exec-Command

Hello to all,
I’m using the community for the first time and the openhab2 too.
I had a problem, and don’t find a solution at searching.

I want to control my 433MHz powerplugs with openhab2.
I had installed openhab2 at my raspberry pi3. And can controll my powerplug from the commandline.

I installed the exec binding 2.0 as addon.
When i create a new command as thing and create a switch as item, then i can run the command.

But at the sitemap, my switch will fire the command at slide switch to on. That is right.
But when i slide to off, nothing will do.

I read at many posts at the community, that you can use a exec command like this one:
Switch test “Test” {exec=">[ON:/Users/name/Documents/openhab/conf/scripts/SteckdoseG1 15 1] >[OFF:/Users/name/Documents/openhab/conf/scripts/SteckdoseG1 15 0]"}

But this solution doesn’t work at execbinding 2.0

How can i translate such a function to version 2.0?

Can any one help me?

Thank you :slight_smile:

The exec 2.0 binding works very differently from the 1.x version binding. See the 2.0 readme.

I don’t use this binding myself but I think what I would do is:

  • Use a Number Item
  • `Thing exec:command:myscript [command="/Users/name/Documents/openhab/conf/scripts/SteckdoseG1 15 %2$s"]
  • Use mappings=[1="On", 0="Off"] on the Sitemap

Again, I don’t use this binding so have no idea if the above would work.

The problem is solved.
At a other topic, the problem discussed.

And in this topic the solution was created:

Thanks to you.

How can i close the topic?

Hi Florian,

I’m curious, what package you used for your 433MHz devices. I tried a few weeks ago and couldn’t get it running. I tried pilight, but couldn’t record the commands from the remote… Do you have a link to a HowTo you used? Thanks!

You can’t close it, but there should be an icon where you can mark it as SOLVED.

Thomas, do you understand a german tutorial?

natürlich! :wink:

Okay :slight_smile:
I will write in english, okay it’s not the best, but i think this thread should be english :wink:

You can use this german tutorial.
https://tutorials-raspberrypi.de/raspberry-pi-funksteckdosen-433-mhz-steuern/

But i installed all at /opt/rc-switch
And you must change the permissions for openhab user…

Give the permissions 777 for all files and folders in this folder rc-switch… and the owner must be openhab…
Then it works good :slight_smile:
Which plugs do you use?

Greets :slight_smile:

Thanks for the tutorial. My plugs are “Etekcity” and they don’t have DIP-Switches. I found a tutorial which should sniff the traffic on 433MHz and use it to turn them on and off - but I couldn’t connect to them… (sorry, german also)


I’ll try your tutorial, if I get home. Perhaps I’m lucky! :wink:

Okay…

Can you change something at your plugs or nothing?
I dont have a dip, but i can change a group and a itemnumber…

But when you can nothing change, then maybe they communicate and change their address…
i hearted about this… then you have a problem, because they change their on/off-command sometimes…

1 Like

Hi Thomas,
if you use the arduino-hardware with your PI, than take a look at this community-entry. MartinVW is writing a binding for arduino. Maybe this could help you!

Many greetings
Karl Heinz

AFAIR, I could change the channel or something (for not having my neighbour switching mine), but the codes come by sniffing. I’ll have a try. It’s not bad, if it doesn’t work, I bought the plugs for christmas lighting, where I couldn’t reach the outlet. But I’ll see.

Thanx for pointing me to this, presently I don’t have an arduino, but I’m keen on learning that also! :wink:

Let us know if it’s work…
I want to make a tutorial at my website…

sure - I will test it again the next days and keep you updated.
edit: I’m lacking the 330ohm-resistor. I’ll try next week.

I’m having the exact same issue, finding it difficult to migrate from OH1 to OH2 and get my 433mhz switches working with the exec binding.

@SnitzelWeck92 could you detail your exact setup / fix? I’m finding it difficult pinpointing the exact solution in the posts you’ve referenced.

hello Albert,
i will post my setting:

.things

//SteckdoseG1
Thing exec:command:steckdoseG1-control [ command="/opt/rc-switch/433Utils/RPi_utils/steckdose1.sh %2$s", interval=0, autorun=true ]
Thing exec:command:steckdoseG1-status [ command="/opt/rc-switch/433Utils/RPi_utils/steckdose1.sh status", interval=0, timeout=5 ]

//SteckdoseG2
Thing exec:command:steckdoseG2-control [ command="/opt/rc-switch/433Utils/RPi_utils/steckdose2.sh %2$s", interval=0, autorun=true ]
Thing exec:command:steckdoseG2-status [ command="/opt/rc-switch/433Utils/RPi_utils/steckdose2.sh status", interval=0, timeout=5 ]

//SteckdoseG3
Thing exec:command:steckdoseG3-control [ command="/opt/rc-switch/433Utils/RPi_utils/steckdose3.sh %2$s", interval=0, autorun=true ]
Thing exec:command:steckdoseG3-status [ command="/opt/rc-switch/433Utils/RPi_utils/steckdose3.sh status", interval=0, timeout=5 ]

//SteckdoseG4
Thing exec:command:steckdoseG4-control [ command="/opt/rc-switch/433Utils/RPi_utils/steckdose4.sh %2$s", interval=0, autorun=true ]
Thing exec:command:steckdoseG4-status [ command="/opt/rc-switch/433Utils/RPi_utils/steckdose4.sh status", interval=0, timeout=5 ]

.items

Group grp_steckdosen "Steckdosen" <poweroutlet>

String steckdoseG1Switch "Steckdose G1" <poweroutlet> (grp_steckdosen) [ "Switchable" ] { channel="exec:command:steckdoseG1-control:input", channel="exec:command:steckdoseG1-status:output", autoupdate="true" }
String steckdoseG2Switch "Steckdose G2" <poweroutlet> (grp_steckdosen) [ "Switchable" ] { channel="exec:command:steckdoseG2-control:input", channel="exec:command:steckdoseG2-status:output", autoupdate="true" }
String steckdoseG3Switch "Steckdose G3" <poweroutlet> (grp_steckdosen) [ "Switchable" ] { channel="exec:command:steckdoseG3-control:input", channel="exec:command:steckdoseG3-status:output", autoupdate="true" }
String steckdoseG4Switch "Steckdose G4" <poweroutlet> (grp_steckdosen) [ "Switchable" ] { channel="exec:command:steckdoseG4-control:input", channel="exec:command:steckdoseG4-status:output", autoupdate="true" }

.sitemap

sitemap steckdosen label="Steckdosen" {
    Frame label="Funksteckdosen Gruppe G" {
        Switch item=steckdoseG1Switch mappings=[ "ON"="ON", "OFF"="OFF" ]
        Switch item=steckdoseG2Switch mappings=[ "ON"="ON", "OFF"="OFF" ]
        Switch item=steckdoseG3Switch mappings=[ "ON"="ON", "OFF"="OFF" ]
        Switch item=steckdoseG4Switch mappings=[ "ON"="ON", "OFF"="OFF" ]
        
        Switch item=grp_steckdosen mappings=[ "ON"="ON", "OFF"="OFF" ]
        
        Switch item=Dash_Switch
        }
}

.sh

#!/bin/sh


if [ "$1" = "off" ] || [ "$1" = "0" ] || [ "$1" = "OFF"  ]; then
        /opt/rc-switch/433Utils/RPi_utils/SteckdoseG1 15 0
else
        /opt/rc-switch/433Utils/RPi_utils/SteckdoseG1 15 1
fi

The Installation of rc-switch an wiring-pi is like here:
https://tutorials-raspberrypi.de/raspberry-pi-funksteckdosen-433-mhz-steuern/4

I hope i can help you with my summary…

2 Likes

Ok, so now I tested different approaches, so basically I got through this one again - but without the transistors:

Whats was the key, I don’t know, but basically what I did was:

  1. putting in a Raspbian SDCard (could also be a openHABian, I guess - but not tested with that one as this PI isn’t near the 433 devices)
  2. connecting the Sender and Receiver basically as shown in this pic but I connected the FS1000A (Sender) to the 3V PIN
  3. Installing an configuring the Software as described in Raspberry Pi - Pilight mit 433MHz Modulen zur Hausautomatisierung
  4. So, whenever I pushed a button at the remote, I got the payload via pilight-receive. and could use that in the config.json and with that I can control the outlets.

e.g. I got this sent after pressing the remote:

pi@raspberrypi3 ~ $ pilight-receive
        "message": {
                "id": "A2",
                "unit": 12,
                "state": "on"
        },
        "origin": "receiver",
        "protocol": "clarus_switch",
        "uuid": "0000-b1-23-eb-45678a",
        "repeats": 3

In that case, you can change the /etc/pilight/config.json:

{
        "devices": {
 
                "Switch1": {
                        "protocol": [ "clarus_switch" ], // 'protocol' of payload-message: be sure it's listed here: https://wiki.pilight.org/doku.php/protocols 
                        "id": [{
                                "id": "A2", // 'id' of payload-message
                                "unit": 12 // 'unit' of payload-message
                        }],
                        "state": "on"
                }

        },
        "rules": {},
        "gui": {
                "Switch1": {
                        "name": "Switch Nr 1",
                        "group": [ "MeineSwitches" ],
                        "media": [ "all" ]
                }
 
        },
        "settings": {
                "log-level": 4,
                "pid-file": "/var/run/pilight.pid",
                "log-file": "/var/log/pilight.log",
                "receive-repeats": 1,
                "webserver-enable": 1,
                "webserver-root": "/usr/local/share/pilight/",
                "webserver-port": 80,
                "webserver-cache": 1
        },
        "hardware": {
                "433gpio": {
                        "sender": 0,
                        "receiver": 1
                }
        },
        "registry": {}
}

so the Attributes you’re looking for are:

after that, you can contorl your outlet via the Web-Gui on http://[IP-ADDRESS]:[PORT]/, e.g. http://192.168.1.10:80 (or port 5001 as per default).
via shell, you can use pilight-send as described here: https://wiki.pilight.org/doku.php/psend

Hint:
pilight isn’t restricted to 433MHz power outlets, as you can see in the protocol-list, there many more devices like weatherstations, motion sensors, presence detectors, … basically every 433 MHz device should be controllable via pilight.

hey guys,

thank you for your answers here, especially Florian.
Now there is one question left for my part. Is there a possibility to implement the things, items, etc. directly in the jsondb? Or do I need to use the separate files? And whats the best way to edit the jsondb file? I made the experience that the jsondb content manually added is deleted after a reboot of OH2.

Best regards,
Max

Great tutorial.But I never got it to work. It wouldn’t let my user “openhabian” execute the command. I tried with raspberry-remote and wiringpi. wiringpi stated an error message like “Unable to open /dev/mem or /dev/gpiomem…” I tried several solutions with adding more rights to that openhabian user but without success. And I haven’t been able to run the command in openhab as sudo.

Update: Solved with chmod 666 /dev/gpiomem. Works great!

Hi guys,

is it possible to configure a simple on-off-switch with the exec command in the Paper UI?
I was able to connect a switch item to the “running” channel of a Thing based on the exec binding but the Switch cannot be toggled. I am not sure how I can set-up different states ( ON OFF ) in the command field within the Paper UI to get the switch to work.

Thanks and best regards,
Martin