Which user and rights for executeCommandLine?

I am using OH2 and want to call a python script that controls my WS2801 led strip. I set the header, gave chmod +x permissions (tried even 777 and chown openhab), but when calling the executeCommandLine from a rule, it doesn’t work:

executeCommandLine("/etc/openhab2/scripts/ws2801.py 1 2 3")

THis does nothing. However, when I try to run it as openhab user, it works!

sudo runuser openhab -c '/etc/openhab2/scripts/ws2801.py 1 2 3'  -s /bin/bash

Do I use the wrong user (I added the openhab user to the spi group, which is needed).

The user whcih executes the commandline is openhab. So your user seems to be right. Try a simpler commandline, maybe just echo some text to a file.

I always use simple shell scripts (#!/bin/sh), which do the work. These scripts then call other stuff (in your case a python script.). Maybe you could call the python engine with your script as parameter?


Here is a thread where the exec binding is explained and also how to test if the command you want to execute can be executed. Also how you can display the return value of the execution to find errors.

So what does the log says? Try to execute it as follows

sudo -u openhab /etc/openhab2/scripts/ws2801.py 1 2 3

Another thing is that the user openhab has no bash enabled. Which you can find explained here.

without the -s /bin/bash parameter, it does nothing. However, when I run it from openhabian user, it works. Is there another way to solve it?

sudo -u openhab /usr/bin/python /etc/openhab2/scripts/ws2801.py 1 2 3

@vtni or add the Shebang to your script. Explained here.

And please answer in full commands. When you state

i am not 100% sure what you typed. And please also be a little more specific nothing happend, means stripe does not change, but what is the return value from the command line?

Do you use openhabian? Then you have to change everythink you did to openhabian not user openhab. The user listet when you type this is the user you have to configure everything.
When openhab is listet use openhab when openhabian is listet use this user.

sudo cat /etc/passwd |grep open
openhab:x:111:116:openhab2 runtime user,,,:/var/lib/openhab2:/bin/false

No. Even openhabian uses the user openhab.

My fault never used openhabian and somehow thought the whole time the user has an other name which i found strange. Somehow other said so.

ok, found out that that this works from executeCommandLine:

executeCommandLine("/usr/bin/python3 /etc/openhab2/scripts/ws2801.py 1 2 3")

Thanks to all of you!