EXEC python script

  • Platform information:
    • Hardware: RPI4
    • openHAB version:3.2

I want to execute a python script via the EXEC binding:

Thing exec:command:sunnyboy [command="/etc/openhab/scripts/sma3.py", interval=61, timeout=5, autorun=true]

But I get the message:

2022-02-24 12:06:30.699 [ERROR] [internal.handler.ScriptActionHandler] - Script execution of rule with UID 'power-1' failed: For input string: "sh: 1: /etc/openhab/scripts/sma3.py: not found

If I try this in command line, I got the same result. Only when I call it with user openhabian & python I got the expected result.

openhabian@openhabian:/etc/openhab/scripts $ sudo -u openhab "/etc/openhab/scripts/sma3.py"
sudo: unable to execute /etc/openhab/scripts/sma3.py: No such file or directory
openhabian@openhabian:/etc/openhab/scripts $ sudo -u openhabian python "/etc/openhab/scripts/sma3.py"
{"total": 16698301, "today": 2802, "spotacpower": 449}

What am I doing wrong?

The message is about a rule; not related to your Thing.

There’s your clue. openHAB does not run under user openhabian, it runs under user openhab, so you’ll have to grant user openhab permissions to the script file and any other resources it needs…

Similar posts

Thanks for your response rossko57.
When I changed the permissions and execute it via the openhab user I got errors on the import functions I use within the script. Could it be that those functions aren’t available for the openenhab user?
What is the correct syntax that I need to use for my Thing configuration?

Maybe this helps

Ok thanks
First reinstallated the function via sudo
Next I changed the thing configuration to:

Thing exec:command:sunnyboy [command="python /etc/openhab/scripts/sma3.py", interval=61, timeout=5, autorun=true]

This did solved it.
What I wondering is why I had to mention python? (In previous installation with OH2 this was not necessary)

There shouldn’t be any difference between OH2 and OH3.
In your call the leading python in front of the script can be left out in case:
a) shebang ( #!/path/to/python ) is used in the script’s first row ( this defines the script interpreter )
b) the script is readable and executable