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

@ramy_rutu as stated before with your approach what you want to do is not possible.

So please try to do something which is possible, then it will make sense to correkt your code.

Maybe try to read out the temperatures of your RPI.

Hey @ramy_rutu here you go.

Hey there.
At the moment I try to implement the 433MHz sender. When I fire up the send command from root it is working fine:

/opt/SourceCode/raspberry-remote# ./send 100001 1 1
using pin 0
sending systemCode[100001] unitCode[1] command[1]

When I try to send the same command as the openhab user I get the following error:

/opt/SourceCode/raspberry-remote# sudo -u openhab ./send 100001 1 1
using pin 0
wiringPiSetup: Must be root. (Did you forget sudo?)

I installed openhabian on a fresh debian installation with the setup wizard, because it’s a BananaPi (first edition, Dualcore, 1GB RAM)

I had to create the “gpio” group manually, it wasn’t created during the openhabian setup. Maybe there’s a fault. I tried a lot of things I’ve found in the forums but nothing worked.

Maybe someone have a clue what’s going wrong on my installation.

If you need more informations please tell me what to do :slight_smile:

Thanks a lot!
kovu94

What I’ve tested until now:

sudo visudo:

#
# 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
%sudo   ALL=(ALL:ALL) ALL
openhab ALL=(ALL) NOPASSWD: ALL
www-data ALL=(ALL) NOPASSWD: ALL
openhabian ALL=(ALL) NOPASSWD: ALL

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

#includedir /etc/sudoers.d

  • chmod 777 for the send file
  • several right things I’ve found in the forums
  • several things in the openhab files (things, items, sitemap, etc.) - but I think it wont work until it works from command line
  • exec binding is installed (several attempts, first with habmin, after it through paperUI)

Details for the bananapi:

login as: root
 ____                                  ____  _
| __ )  __ _ _ __   __ _ _ __   __ _  |  _ \(_)
|  _ \ / _` | '_ \ / _` | '_ \ / _` | | |_) | |
| |_) | (_| | | | | (_| | | | | (_| | |  __/| |
|____/ \__,_|_| |_|\__,_|_| |_|\__,_| |_|   |_|


Welcome to ARMBIAN 5.38 stable Debian GNU/Linux 9 (stretch) 4.14.18-sunxi
System load:   0.45 0.36 0.40   Up time:       20 min
Memory usage:  23 % of 998MB    IP:            192.168.178.5
CPU temp:      36°C
Usage of /:    16% of 15G

Is it possible that we can check that the “gpio” group has the correct bindings in the system. I’m not a linux crack but I think there are some permissions I’ve to give to the group after creating it.

The point of the gpio group is that the files that represent the GPIO pins have permission to read/write for the group gpio.

Taken from a raspberry pi

rich@cerberos:~   ls -l /sys/class/gpio/
total 0
-rwxrwx--- 1 root gpio 4096 Jan 29 16:17 export*
lrwxrwxrwx 1 root gpio    0 Jan 29 16:17 gpiochip0 -> ../../devices/platform/soc/3f200000.gpio/gpio/gpiochip0/
lrwxrwxrwx 1 root gpio    0 Jan 29 16:17 gpiochip100 -> ../../devices/gpiochip2/gpio/gpiochip100/
lrwxrwxrwx 1 root gpio    0 Jan 29 16:17 gpiochip128 -> ../../devices/gpiochip1/gpio/gpiochip128/
-rwxrwx--- 1 root gpio 4096 Jan 29 16:17 unexport*

When I look on my Banana Pi I see that those files only have permissions for root.

rich@chiron:~   ls -l /sys/class/gpio/
total 0
--w------- 1 root root 4096 Feb 12 11:50 export
lrwxrwxrwx 1 root root    0 Feb 12 11:50 gpiochip0 -> ../../devices/platform/soc/1c20800.pinctrl/gpio/gpiochip0/
lrwxrwxrwx 1 root root    0 Feb 12 11:50 gpiochip352 -> ../../devices/platform/soc/1f02c00.pinctrl/gpio/gpiochip352/
--w------- 1 root root 4096 Feb 12 11:50 unexport

Since sys is a tmpfs directory (meaning it gets created and populated on system boot) I don’t know how one would change the permissions on these files and have them stick through a reboot.

So I’m guessing you cannot access the GPIO on a Banana Pi as any user other than root.

@kovu94 and @rlkoshak i never did it myself but i think this could help to get it work.

and be aware that the udev rule has to be adapted from

/sys/devices/platform/soc/*.gpio/gpio

to

/sys/devices/platform/soc/*.pinctrl/gpio

or maybe

/sys/devices/platform/soc/*/gpio

or use

1 Like

I’m sure I tested this last weekend but I’ll try it again tomorrow because I’m not sure I made the dist-upgrade.

If it will not work I have to switch to a original raspberry, as @rikoshak mentioned. Maybe it’s by design for the banana pi.

Many thanks for you pointing me in the right direction. I’m back tomorrow evening with the results.

Good night :slight_smile:

Sorry. It doesn’t seem to work.

The udev rule is edited this way:

# /etc/udev/rules.d/80-gpio-noroot.rules
# Acces to GPIO without root
#
#  Change group
SUBSYSTEM=="gpio", PROGRAM="/bin/sh -c '/bin/chown -R root:gpio /sys/devices/platform/soc@01c00000/1c20800.pinctrl/gpio'"
# set acces permission
SUBSYSTEM=="gpio", PROGRAM="/bin/sh -c '/bin/chmod -R ug+rw /sys/devices/platform/soc@01c00000/1c20800.pinctrl/gpio'"

Because that’s the only “soc” in the folder:

[15:27:15] root@bananapi:/sys/devices/platform/soc@01c00000/1c20800.pinctrl/gpio# ls -la
total 0
drwxrwxr-x 3 root gpio 0 Feb 13 15:24 .
drwxr-xr-x 5 root root 0 Feb 13 15:26 ..
drwxrwxr-x 3 root gpio 0 Feb 13 15:24 gpiochip0
[15:27:17] root@bananapi:/sys/devices/platform/soc@01c00000/1c20800.pinctrl/gpio#

I use this version of WiringPi at the moment, the one you suggested doesn’t work.

Error with your Version:

Unable to determine hardware version. I see: Hardware   : Allwinner sun7i (A20) Family
,
 - expecting BCM2708, BCM2709 or BCM2835.
If this is a genuine Raspberry Pi then please report this
to projects@drogon.net. If this is not a Raspberry Pi then you
are on your own as wiringPi is designed to support the
Raspberry Pi ONLY.

It seems to work:

[15:31:46] root@bananapi:/opt/SourceCode/WiringBP# gpio readall
 +-----+-----+---------+------+---+--Banana Pro--+---+------+---------+-----+-----+
 | BCM | wPi |   Name  | Mode | V | Physical | V | Mode | Name    | wPi | BCM |
 +-----+-----+---------+------+---+----++----+---+------+---------+-----+-----+
 |     |     |    3.3v |      |   |  1 || 2  |   |      | 5v      |     |     |
 |   2 |   8 |   SDA.1 | ALT5 | 0 |  3 || 4  |   |      | 5V      |     |     |
 |   3 |   9 |   SCL.1 | ALT5 | 0 |  5 || 6  |   |      | 0v      |     |     |
 |   4 |   7 | GPIO. 7 |   IN | 0 |  7 || 8  | 1 | ALT2 | TxD     | 15  | 14  |
 |     |     |      0v |      |   |  9 || 10 | 0 | IN   | RxD     | 16  | 15  |
 |  17 |   0 | GPIO. 0 |   IN | 0 | 11 || 12 | 0 | IN   | GPIO. 1 | 1   | 18  |
 |  27 |   2 | GPIO. 2 |   IN | 0 | 13 || 14 |   |      | 0v      |     |     |
 |  22 |   3 | GPIO. 3 |   IN | 0 | 15 || 16 | 0 | IN   | GPIO. 4 | 4   | 23  |
 |     |     |    3.3v |      |   | 17 || 18 | 0 | IN   | GPIO. 5 | 5   | 24  |
 |  10 |  12 |    MOSI | ALT5 | 0 | 19 || 20 |   |      | 0v      |     |     |
 |   9 |  13 |    MISO | ALT5 | 0 | 21 || 22 | 0 | IN   | GPIO. 6 | 6   | 25  |
 |  11 |  14 |    SCLK | ALT5 | 0 | 23 || 24 | 0 | ALT5 | CE0     | 10  | 8   |
 |     |     |      0v |      |   | 25 || 26 | 0 | ALT5 | CE1     | 11  | 7   |
 |   0 |  30 |   SDA.0 |   IN | 1 | 27 || 28 | 1 | IN   | SCL.0   | 31  | 1   |
 |   5 |  21 | GPIO.21 |   IN | 0 | 29 || 30 |   |      | 0v      |     |     |
 |   6 |  22 | GPIO.22 | ALT4 | 0 | 31 || 32 | 0 | ALT4 | GPIO.26 | 26  | 12  |
 |  13 |  23 | GPIO.23 |   IN | 0 | 33 || 34 |   |      | 0v      |     |     |
 |  19 |  24 | GPIO.24 |   IN | 0 | 35 || 36 | 0 | IN   | GPIO.27 | 27  | 16  |
 |  26 |  25 | GPIO.25 |   IN | 0 | 37 || 38 | 0 | IN   | GPIO.28 | 28  | 20  |
 |     |     |      0v |      |   | 39 || 40 | 0 | IN   | GPIO.29 | 29  | 21  |
 +-----+-----+---------+------+---+----++----+---+------+---------+-----+-----+
 | BCM | wPi |   Name  | Mode | V | Physical | V | Mode | Name    | wPi | BCM |
 +-----+-----+---------+------+---+--Banana Pro--+---+------+---------+-----+-----+
[15:31:49] root@bananapi:/opt/SourceCode/WiringBP#

@rlkoshak - when I use “ls -l /sys/class/gpio” now it looks good:

[15:31:49] root@bananapi:/opt/SourceCode/WiringBP# ls -l /sys/class/gpio/
total 0
-rw-rw---- 1 root gpio 4096 Feb 13 15:25 export
lrwxrwxrwx 1 root gpio    0 Feb 13 15:25 gpiochip0 -> ../../devices/platform/soc@01c00000/1c20800.pinctrl/gpio/gpiochip0
lrwxrwxrwx 1 root gpio    0 Feb 13 15:25 gpiochip413 -> ../../devices/platform/soc@01c00000/1c2ac00.i2c/i2c-0/0-0034/axp20x-gpio/gpio/gpiochip413
-rw-rw---- 1 root gpio 4096 Feb 13 15:25 unexport
[15:32:30] root@bananapi:/opt/SourceCode/WiringBP#

But still this damn error:

[15:33:42] root@bananapi:/opt/433Utils/RPi_utils# sudo -u openhab ./codesend 9385235
wiringPiSetup: Must be root. (Did you forget sudo?)
[15:33:50] root@bananapi:/opt/433Utils/RPi_utils#

I think I’m going for an original RPi3 soon…

@kovu94 How are the permissions of

pi@raspberrypi:~ $ ls -l /sys/class/gpio/
total 0
-rwxrwx--- 1 root gpio 4096 Feb 13 23:02 export
lrwxrwxrwx 1 root gpio    0 Feb 13 00:07 gpio27 -> ../../devices/platform/soc/3f200000.gpio/gpiochip0/gpio/gpio27
lrwxrwxrwx 1 root gpio    0 Feb 12 12:46 gpiochip0 -> ../../devices/platform/soc/3f200000.gpio/gpio/gpiochip0
lrwxrwxrwx 1 root gpio    0 Feb 12 12:46 gpiochip100 -> ../../devices/gpiochip2/gpio/gpiochip100
lrwxrwxrwx 1 root gpio    0 Feb 12 12:46 gpiochip128 -> ../../devices/gpiochip1/gpio/gpiochip128
-rwxrwx--- 1 root gpio 4096 Feb 12 12:46 unexport

Maybe add a udevrule to adjust this permissions, additionally. And also for the folders where the links show to.
As the gpiochipxxx files created when configuring the pins i think. So could you try to set up a pin as output and then list the folder to see the permission for it when the pin is actually there?

So my setup looks as follows:

pi@raspberrypi:/sys/class/gpio $ ls -l
total 0
-rwxrwx--- 1 root gpio 4096 Feb 13 23:02 export
lrwxrwxrwx 1 root gpio    0 Feb 13 00:07 gpio27 -> ../../devices/platform/soc/3f200000.gpio/gpiochip0/gpio/gpio27
lrwxrwxrwx 1 root gpio    0 Feb 12 12:46 gpiochip0 -> ../../devices/platform/soc/3f200000.gpio/gpio/gpiochip0
lrwxrwxrwx 1 root gpio    0 Feb 12 12:46 gpiochip100 -> ../../devices/gpiochip2/gpio/gpiochip100
lrwxrwxrwx 1 root gpio    0 Feb 12 12:46 gpiochip128 -> ../../devices/gpiochip1/gpio/gpiochip128
-rwxrwx--- 1 root gpio 4096 Feb 12 12:46 unexport

pi@raspberrypi:/sys/class/gpio $ ls -l ../../devices/platform/soc/3f200000.gpio/gpiochip0/gpio/gpio27
total 0
-rwxrwx--- 1 root gpio 4096 Feb 13 00:07 active_low
lrwxrwxrwx 1 root gpio    0 Feb 13 00:07 device -> ../../../gpiochip0
-rwxrwx--- 1 root gpio 4096 Feb 13 23:02 direction
-rwxrwx--- 1 pi   pi   4096 Feb 13 23:02 edge
drwxrwx--- 2 root gpio    0 Feb 13 00:07 power
lrwxrwxrwx 1 root gpio    0 Feb 13 00:07 subsystem -> ../../../../../../../class/gpio
-rwxrwx--- 1 root gpio 4096 Feb 13 00:07 uevent
-rwxrwx--- 1 pi   pi   4096 Feb 13 00:07 value

pi@raspberrypi:/sys/class/gpio $ ls -l ../../devices/platform/soc/3f200000.gpio/gpio/gpiochip0
total 0
-rwxrwx--- 1 root gpio 4096 Feb 12 12:46 base
lrwxrwxrwx 1 root gpio    0 Feb 12 12:46 device -> ../../../3f200000.gpio
-rwxrwx--- 1 root gpio 4096 Feb 12 12:46 label
-rwxrwx--- 1 root gpio 4096 Feb 12 12:46 ngpio
drwxrwx--- 2 root gpio    0 Feb 12 12:46 power
lrwxrwxrwx 1 root gpio    0 Feb 12 12:46 subsystem -> ../../../../../../class/gpio
-rwxrwx--- 1 root gpio 4096 Feb 12 12:46 uevent

pi@raspberrypi:/sys/class/gpio $ ls -l ../../devices/gpiochip2/gpio/
total 0
drwxrwx--- 3 root gpio 0 Feb 12 12:46 gpiochip100

pi@raspberrypi:/sys/class/gpio $ ls -l ../../devices/gpiochip2/gpio/gpiochip100
total 0
-rwxrwx--- 1 root gpio 4096 Feb 12 12:46 base
lrwxrwxrwx 1 root gpio    0 Feb 12 12:46 device -> ../../../gpiochip2
-rwxrwx--- 1 root gpio 4096 Feb 12 12:46 label
-rwxrwx--- 1 root gpio 4096 Feb 12 12:46 ngpio
drwxrwx--- 2 root gpio    0 Feb 12 12:46 power
lrwxrwxrwx 1 root gpio    0 Feb 12 12:46 subsystem -> ../../../../class/gpio
-rwxrwx--- 1 root gpio 4096 Feb 12 12:46 uevent

Please post how your files look like when a pin is configured.

And somehow your path is different to what @rlkoshak posted. You have an /soc@ does the normal folder not exist?

Is the user openhab added to the group gpio.

pi@raspberrypi:~ $ sudo -u openhab groups
openhab video gpio

Did you reboot ? This is sometimes neccessary. :smile:

@Josar - Thanks for trying to help. I tried the last days a lot to get the GPIOs working. In the end I gave up. I ordered a RPi3 and today I migrated my configuration.
Then in the second try the GPIO is working and finally I’m able to switch my powerplugs.
It definitely has something to do with this damn BananaPi. Now he’s retired and maybe used again in future as a proxy or something.

BTW - for my cheap plugs I’ve used this tutorial which is working fine with GPIO:

Again - thank you very much for your help!
Have a nice weekend.

@Josar Thanks for putting this tutorial together. I am using nearly 99% RF outlets and a rooted Wink Hub 1 that also uses exec binding, so this helps a lot. However, I followed what you had very closely and am getting the following error during the testing:

Cannot convert ‘5330371’ to a command type which item ‘Outlet_Power_Args’ accepts: [OnOffType, RefreshType].

Here are my files, simple for now as I am trying to figure this all out.

exec.things

Thing exec:command:outlet-power [ 
           command="/home/pi/python_scripts/automation/v2/codesend %2$s",
           interval=0,
           autorun=true]

rf_outlets.items

Switch rf_plug_LR_lamp <poweroutlet>

Switch Outlet_Power         { channel="exec:command:outlet-power:run"       }
Switch Outlet_Power_Args    { channel="exec:command:outlet-power:input"     }
Switch Outlet_Power_Out     { channel="exec:command:outlet-power:output"    }

rf_outlets.sitemap (Probably less important)

sitemap rf_outlets label="RF Outlets"
{
    Frame label="RF Outlets"
    {
        Switch item=rf_plug_LR_lamp label="Living Room Lamp"
    }
}

rf_outlets.rules

rule "Living Room Lamp"
    when
        Item rf_plug_LR_lamp received command
    then
        // wait for transmitter to be free
        // state will be NULL if not used before or ON while command is executed
        while(Outlet_Power.state == ON){
            Thread::sleep(500)
        }

        if(receivedCommand == ON){
            Outlet_Power_Args.sendCommand("5330371")
        } else {
            Outlet_Power_Args.sendCommand("5330380")
        }

        // wait for the command to complete
        while(Outlet_Power.state != OFF){
            Thread::sleep(500)
        }

        logInfo("RF Outlets","Result:" + Outlet_Power_Out.state)
end

Essentially, the same exact thing that you did, by my code isn’t in 3 parts, only 1 but don’t know why this would matter. Any ideas what is happening and what I can do to correct it? Thanks!

**EDIT: Totally figured out what I missed (guess I didn’t follow as closely as I thought).

Instead of

Switch Outlet_Power_Args    { channel="exec:command:outlet-power:input"     }
Switch Outlet_Power_Out     { channel="exec:command:outlet-power:output"    }

in my items file, it should be:

String Outlet_Power_Args    { channel="exec:command:outlet-power:input"     }
String Outlet_Power_Out     { channel="exec:command:outlet-power:output"    }

The command isn’t actually executing like I would expect, but the error is gone now. On to figure out why it isn’t executing.

Switch vs String, Input and output only supports strings at the moment.

Can you execute the command as user openhab in the command line as described above?

So I actually can. I have been getting misdirected (perhaps) on chasing down adding openhab to sudoers with no password, but I don’t think that is the problem here.

The script is actually located here:

/home/pi/python_scripts/automation/v2/codesend

When logged in as pi, and in /home/pi, I can run

sudo -u openhab /home/pi/python_scripts/automation/v2/codesend 5330380  (or the ON variant code)

And it works perfectly.

Not sure what it says, but I can also run the same exact command from

/etc/openhab2

And it works as well.

In my log, all I am getting is the following:

23:23:45.792 [INFO ] [smarthome.event.ItemStateChangedEvent] - Outlet_Power_Args changed from NULL to 5330371
23:23:47.888 [INFO ] [smarthome.event.ItemCommandEvent ] - Item ‘rf_plug_LR_lamp’ received command OFF
23:23:47.900 [INFO ] [smarthome.event.ItemStateChangedEvent] - rf_plug_LR_lamp changed from ON to OFF
23:23:47.907 [INFO ] [smarthome.event.ItemCommandEvent ] - Item ‘Outlet_Power_Args’ received command 5330380
23:23:47.909 [INFO ] [smarthome.event.ItemStateChangedEvent] - Outlet_Power_Args changed from 5330371 to 5330380
23:23:49.524 [INFO ] [smarthome.event.ItemCommandEvent ] - Item ‘rf_plug_LR_lamp’ received command ON
23:23:49.527 [INFO ] [smarthome.event.ItemStateChangedEvent] - rf_plug_LR_lamp changed from OFF to ON
23:23:49.533 [INFO ] [smarthome.event.ItemCommandEvent ] - Item ‘Outlet_Power_Args’ received command 5330371
23:23:49.538 [INFO ] [smarthome.event.ItemStateChangedEvent] - Outlet_Power_Args changed from 5330380 to 5330371

So this part looks like it is working, but the one thing I don’t really know - Is it really sending that command? And, if so, is it getting rejected for some reason. In a way, since it works when I run it as sudo -u openhab from multiple locations, it should be working from here, right?

Is there a way I can tell if this command is actually getting sent? All the log really tells me is that it is getting the OFF or ON command and the ARGS are getting changed.

please use the code fences also for logs not the blockqoutes. There are buttons for that at the right top of the textfield. This makes this a lot easier to read.

```
your log goes here
```

If this works, all is good, but your binding, thing, item or sitemap has errors.
As the path starts with / it should work from everywhere as this is an absolute path.

sudo -u openhab /home/pi/python_scripts/automation/v2/codesend 5330380

I copy pasted your stuff and changed my path, and command. And to answer your question: you know it worked when something happened e.g the led goes off :wink: .

And the log should show the result of the executed command.

[INFO ] [pse.smarthome.model.script.RF Outlets] - Result:sending code[5330380]
[INFO ] [smarthome.event.ItemStateChangedEvent] - Outlet_Power_Args changed from 5330380 to 11607809
[INFO ] [smarthome.event.ItemStateChangedEvent] - Outlet_Power changed from OFF to ON
[INFO ] [smarthome.event.ItemStateChangedEvent] - Outlet_Power changed from ON to OFF
[INFO ] [smarthome.event.ItemStateChangedEvent] - Outlet_Power_Out changed from sending code[5330380] to sending code[11607809]

Everything works in my setup. But your log is missing the execution.
Uninstalling the exc binding results in the same output as yours.

[INFO ] [smarthome.event.ItemCommandEvent     ] - Item 'rf_plug_LR_lamp' received command ON
[INFO ] [pse.smarthome.model.script.RF Outlets] - Result:sending code[11607812] // this is the old state so missing in your log.
[INFO ] [smarthome.event.ItemStateChangedEvent] - rf_plug_LR_lamp changed from OFF to ON
[INFO ] [smarthome.event.ItemCommandEvent     ] - Item 'Outlet_Power_Args' received command 11607809
[INFO ] [smarthome.event.ItemStateChangedEvent] - Outlet_Power_Args changed from 11607812 to 11607809

Install the exec binding and you should be good to go.

Edit: :bulb:

If it is something as simple as that, I will be happy, but also that would be incredibly ironic! I was thinking last night as I was going to bed that maybe I am looking I’m the wrong place. That maybe it had to do with the binding itself. I am not in front of my setup and won’t be till later, but I was wondering if it had something to do with the fact that I have exec1 installed as well. Wait, now that I said that I think I know exactly what is wrong! (Insert lightbulb here) I’m not going to say until I check it, but will report back for posterity. Thanks again!

Wow, so yeah, I was thinking WAY too hard about this. As I am sure you have probably already figured out, I didn’t have the exec binding installed!

I have a “good” reason :slight_smile: When I initially installed, I had installed the exec1 binding as I was going to use that but later decided to just move forward with the exec 2 version. I totally never went back in and changed it! I can’t believe that. I know we have all done it, but it still sucks! Hours of work until my eyes were crossed and it was something so simple. It is on now though, this was all I needed to figure out to get fully migrated. Thanks again!

Mike

@Josar OK, so I have my entire setup to where it is working. I even had quite a significant amount of delay (as compared to my OH1, exec1 binding). I just removed the thread::sleep(500) items and it is near instant (I don’t have a lot going on and my hardware can seem to keep up just fine without it, except on the rule that turns on all my basement lights (or OFF). Needed to add a tiny bit of sleep (as well as fix ssh multithreading) to make them consistent.

However, in dealing with certain instances where I have to issue a command multiple times to get it to work, I came across some weirdness in my logs. Looking back at your response comparing my logs with yours, I noticed it is present there but on your log I don’t see it. (Note, my commands not working sometimes very well could be due to my transmitter because I see in the log the command fires, so that isn’t really my concern here, in fact, these logs still show up this way with my ssh commands (zigbee) to my rooted wink hub.

Anyway, what I am seeing is it looks like my devices are getting change from ON to OFF then OFF to ON immediately (or vice versa). And I have no clue why this would be happening. Hoping you or someone else can see what I may be missing:

Whenever I only turn an Item on (or off), each time I get the following in the logs:

12:30:02.975 [INFO ] [smarthome.event.ItemCommandEvent     ] - Item 'rf_plug_LR_lamp' received command ON
12:30:03.016 [INFO ] [pse.smarthome.model.script.RF Outlets] - Result:Sending Code: 5330236. PIN: 0. Pulse Length: 189
12:30:03.088 [INFO ] [smarthome.event.ItemStateChangedEvent] - rf_plug_LR_lamp changed from OFF to ON
12:30:03.240 [INFO ] [smarthome.event.ItemCommandEvent     ] - Item 'Outlet_Power_Args_RF' received command 5330371
12:30:03.307 [INFO ] [smarthome.event.ItemStateChangedEvent] - Outlet_Power_Args_RF changed from 5330236 to 5330371
12:30:03.422 [INFO ] [smarthome.event.ItemStateChangedEvent] - Outlet_Power_RF changed from OFF to ON
12:30:03.482 [INFO ] [smarthome.event.ItemStateChangedEvent] - Outlet_Power_RF changed from ON to OFF
12:30:03.544 [INFO ] [smarthome.event.ItemStateChangedEvent] - Outlet_Power_Out_RF changed from Sending Code: 5330236. PIN: 0. Pulse Length: 189 to Sending Code: 5330371. PIN: 0. Pulse Length: 189

Here is the result from the OFF command being sent afterward as well:

12:30:33.688 [INFO ] [smarthome.event.ItemCommandEvent     ] - Item 'rf_plug_LR_lamp' received command OFF
12:30:33.741 [INFO ] [pse.smarthome.model.script.RF Outlets] - Result:Sending Code: 5330371. PIN: 0. Pulse Length: 189
12:30:33.779 [INFO ] [smarthome.event.ItemStateChangedEvent] - rf_plug_LR_lamp changed from ON to OFF
12:30:33.929 [INFO ] [smarthome.event.ItemCommandEvent     ] - Item 'Outlet_Power_Args_RF' received command 5330380
12:30:33.996 [INFO ] [smarthome.event.ItemStateChangedEvent] - Outlet_Power_Args_RF changed from 5330371 to 5330380
12:30:34.068 [INFO ] [smarthome.event.ItemStateChangedEvent] - Outlet_Power_RF changed from OFF to ON
12:30:34.128 [INFO ] [smarthome.event.ItemStateChangedEvent] - Outlet_Power_RF changed from ON to OFF
12:30:34.188 [INFO ] [smarthome.event.ItemStateChangedEvent] - Outlet_Power_Out_RF changed from Sending Code: 5330371. PIN: 0. Pulse Length: 189 to Sending Code: 5330380. PIN: 0. Pulse Length: 189

Here is the result on an ON command, still using the exec command, but invoking a different script (callbacks can be ignored, just feedback from the winkhub that don’t affect anything really)

12:32:37.655 [INFO ] [smarthome.event.ItemCommandEvent     ] - Item 'zigbee_bulb_hall_light' received command ON
12:32:37.661 [INFO ] [e.model.script.Zigbee Bulb Hall Light] - Result:Update device with master ID 7, setting value OFF for attribute 1
Waiting for 1 callbacks...
Received a myNodeDataCallback from Zigbee
                Source: aprontest
                Event:  RADIO_EVT_NODE_UPDATE
                Status: FLX_OK
                Node:   7
12:32:37.751 [INFO ] [smarthome.event.ItemCommandEvent     ] - Item 'Bulb_Power_Args_Zig' received command -m 6 -u -t 1 -v ON
12:32:38.124 [INFO ] [smarthome.event.ItemStateChangedEvent] - zigbee_bulb_hall_light changed from OFF to ON
12:32:38.189 [INFO ] [smarthome.event.ItemStateChangedEvent] - Bulb_Power_Args_Zig changed from -m 7 -u -t 1 -v OFF to -m 6 -u -t 1 -v ON
12:32:38.265 [INFO ] [smarthome.event.ItemStateChangedEvent] - Bulb_Power_Zig changed from OFF to ON
12:32:40.101 [INFO ] [smarthome.event.ItemStateChangedEvent] - Bulb_Power_Zig changed from ON to OFF
12:32:40.167 [INFO ] [smarthome.event.ItemStateChangedEvent] - Bulb_Power_Out_Zig changed from Update device with master ID 7, setting value OFF for attribute 1

rfoutlets.items

Switch rf_plug_LR_lamp <lightbulb>
Switch rf_plug_DR_lamp <lightbulb>
Switch rf_plug_BR_lamp <lightbulb>

Switch Outlet_Power_RF         { channel="exec:command:outlet-power:run"       }
String Outlet_Power_Args_RF    { channel="exec:command:outlet-power:input"     }
String Outlet_Power_Out_RF     { channel="exec:command:outlet-power:output"    }

zigbee_bulbs.items

Switch zigbee_bulb_Lydias_lamp      <lightbulb>
Switch zigbee_bulb_desk_lamp        <lightbulb>
Switch zigbee_bulb_front_porch      <lightbulb>
Switch zigbee_bulb_basement_door    <lightbulb>     
Switch zigbee_bulb_basement_cree_1  <lightbulb>     
Switch zigbee_bulb_basement_cree_2  <lightbulb>     
Switch zigbee_bulb_basement_cree_3  <lightbulb>     
Switch zigbee_bulb_hall_light       <lightbulb>
Switch zigbee_bulb_basement_all     <lightbulb>

Switch Bulb_Power_Zig         { channel="exec:command:zigbee-bulb-power:run"       }
String Bulb_Power_Args_Zig    { channel="exec:command:zigbee-bulb-power:input"     }
String Bulb_Power_Out_Zig     { channel="exec:command:zigbee-bulb-power:output"    }

exec.things

Thing exec:command:outlet-power [ 
           command="/home/pi/python_scripts/automation/v2/codesend %2$s",
           interval=0,
           autorun=true]

Thing exec:command:zigbee-bulb-power [ 
           command="/home/pi/oh_custom_scripts/wink-as-pi.sh %2$s",
           interval=0,
           autorun=true]

Thing exec:command:zigbee-outlet-power [ 
           command="/home/pi/oh_custom_scripts/wink-as-pi.sh %2$s",
           interval=0,
           autorun=true]  

home.rules

rule "Front Porch"
when
    Item zigbee_bulb_front_porch received command
then
    if(receivedCommand == ON){
        Bulb_Power_Args_Zig.sendCommand("-m 7 -u -t 1 -v ON")
    } else {
        Bulb_Power_Args_Zig.sendCommand("-m 7 -u -t 1 -v OFF")
    }

    logInfo("Zigbee Bulb Front Porch","Result:" + Bulb_Power_Out_Zig.state)
end

//****************************************************

rule "Living Room Lamp"
when
    Item rf_plug_LR_lamp received command
then
    if(receivedCommand == ON){
        Outlet_Power_Args_RF.sendCommand("5330371")
    } else {
        Outlet_Power_Args_RF.sendCommand("5330380")
    }
    
    logInfo("RF Outlets","Result:" + Outlet_Power_Out_RF.state)
end

//****************************************************

rule "Desk Lamp"
when
    Item zigbee_bulb_desk_lamp received command
then     
    if(receivedCommand == ON){
        Bulb_Power_Args_Zig.sendCommand("-m 9 -u -t 1 -v ON")
    } else {
        Bulb_Power_Args_Zig.sendCommand("-m 9 -u -t 1 -v OFF")
    }

    logInfo("Zigbee Bulb Desk Lamp","Result:" + Bulb_Power_Out_Zig.state)
end

//****************************************************

rule "Dining Room Lamp"
when
    Item rf_plug_DR_lamp received command
then    
    if(receivedCommand == ON){
        Outlet_Power_Args_RF.sendCommand("5332227")
    } else {
        Outlet_Power_Args_RF.sendCommand("5332236")
    }

    logInfo("Dining Room Outlet","Result:" + Outlet_Power_Out_RF.state)
end

//****************************************************

rule "Hall Light"
when
    Item zigbee_bulb_hall_light received command
then
    if(receivedCommand == ON){
        Bulb_Power_Args_Zig.sendCommand("-m 6 -u -t 1 -v ON")
    } else {
        Bulb_Power_Args_Zig.sendCommand("-m 6 -u -t 1 -v OFF")
    }

    logInfo("Zigbee Bulb Hall Light","Result:" + Bulb_Power_Out_Zig.state)
end

//****************************************************

rule "Lydias Lamp"
when
    Item zigbee_bulb_Lydias_lamp received command
then
    if(receivedCommand == ON){
        Bulb_Power_Args_Zig.sendCommand("-m 1 -u -t 1 -v ON")
    } else {
        Bulb_Power_Args_Zig.sendCommand("-m 1 -u -t 1 -v OFF")
    }

    logInfo("Zigbee Bulbs Lydias Lamp","Result:" + Bulb_Power_Out_Zig.state)
end

//****************************************************

rule "Bedroom Lamp"
when
    Item rf_plug_BR_lamp received command
then    
    if(receivedCommand == ON){
        Outlet_Power_Args_RF.sendCommand("5330227")
    } else {
        Outlet_Power_Args_RF.sendCommand("5330236")
    }

    logInfo("Bedroom Outlet","Result:" + Outlet_Power_Out_RF.state)
end

//****************************************************

rule "Basement Door Light"
when
    Item zigbee_bulb_basement_door received command
then
    if(receivedCommand == ON){
        Bulb_Power_Args_Zig.sendCommand("-m 5 -u -t 1 -v ON")
    } else {
        Bulb_Power_Args_Zig.sendCommand("-m 5 -u -t 1 -v OFF")
    }

    logInfo("Zigbee Bulb Basement Door","Result:" + Bulb_Power_Out_Zig.state)
end

//****************************************************

rule "Heater"
when
    Item zigbee_outlet_heater received command
then
    if(receivedCommand == ON){
        Outlet_Power_Args_Zig.sendCommand("-m 10 -u -t 1 -v ON")
    } else {
        Outlet_Power_Args_Zig.sendCommand("-m 10 -u -t 1 -v OFF")
    }

    logInfo("Zigbee Outlet Heater","Result:" + Outlet_Power_Out_Zig.state)
end

//****************************************************

rule "All Basement Lights"
when
    Item zigbee_bulb_basement_all received command
then
    if(receivedCommand == ON){
        Outlet_Power_Args_Zig.sendCommand("-m 5 -u -t 1 -v ON") //basement door
        zigbee_bulb_basement_door.postUpdate("ON")
        Thread::sleep(50)
        Outlet_Power_Args_Zig.sendCommand("-m 2 -u -t 1 -v ON") //cree overhead 1
        Thread::sleep(50)
        Outlet_Power_Args_Zig.sendCommand("-m 3 -u -t 1 -v ON") //cree overhead 2
        Thread::sleep(50)
        Outlet_Power_Args_Zig.sendCommand("-m 4 -u -t 1 -v ON") //cree overhead 3
    } else {
        Outlet_Power_Args_Zig.sendCommand("-m 5 -u -t 1 -v OFF") //basement door
        zigbee_bulb_basement_door.postUpdate("OFF")
        Thread::sleep(50)
        Outlet_Power_Args_Zig.sendCommand("-m 2 -u -t 1 -v OFF") //cree overhead 1
        Thread::sleep(50)
        Outlet_Power_Args_Zig.sendCommand("-m 3 -u -t 1 -v OFF") //cree overhead 2
        Thread::sleep(50)
        Outlet_Power_Args_Zig.sendCommand("-m 4 -u -t 1 -v OFF") //cree overhead 3
    }

    logInfo("Zigbee All Basement Lights","Result:" + Outlet_Power_Out_Zig.state)
end

I know it is a big long, but clean enough I hope to be able to understand what is going on.

Pinging @rlkoshak as well in case it is not necessarily related to exec…

It seems that it is just the item state that is changing, but it still doesn’t look right. Thanks!

@shelzmike you can reduce this to 2 rules one for the 433 devices and one for the zigbee devices. See my updated examples.

The item changes when the Skript Starts and when it ends. This is how it should be. What is your question here?

I’m on my phone and don’t have time to fully read your code but based on the behavior I think you are seeing the expected behavior of the run channel. The switch linked to the run channel will only be ON while they script is running. I suspect your script only stays running for a few milliseconds which is why it immediately goes back to off.

Without fully analyzing your code, I suspect what you will want to do is use a proxy item or the item linked to the output channel to represent the state of the light.

I own an apology. I have been trying to wrap my head around the new exec binding and OH2 for so many hours this past week that I think I overlooked a simple explanation here. What I notice now, it is not the actual device that is changing state from OFF to ON then from ON to OFF, instead it is the item that is a proxy? (Is this what an item proxy is, as reference by @rlkoshak in his response? In any event, whatever it is called, I now finally see the logic in it and am seeing that it wasn’t what I was thinking was happening (I thought the actual thing acted on was turning OFF to ON then ON to OFF).

I saw the reference your much more condensed rule, leveraging groups and plan on implementing that; however, as a learning exercise I did it the way I did so that I could clearly see what was going on.

Thanks again for the responses and the work you have done on this to help others. It is appreciated.