EXEC Binding issue

Hi there,

i have an issue with the exec binding. I was following this example here: https://tutorials-raspberrypi.de/raspberry-pi-openhab-relais-steuern-rollladen-lichter/
There’s a switch which should call a python script but in the log it just says relais1Switch changed from ON to OFF but the command to call the script does not show up here.
My assumption is, that the script isn’t called at all so that’s why it’s also not running.
I’m totally a beginner here but was trying to debug as far as i could but now i got stock since i don’t know how can i debug that this script is not called…

Can you post the data: items, rules, log…
So that we can see what you have done and what’s wrong with it.

everything covered in the link I’ve posted… and I checked several times now for any kind of typo…

I don’t read German.
Post it here

1 Like


#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import RPi.GPIO as GPIO
import sys,os
#os.system("sudo echo "+str(sys.argv)+" > /home/openhabian/test")
if len(sys.argv) > 2:
    RELAIS_GPIO = int(sys.argv[1])# + int(sys.argv[2])
    if sys.argv[2] == "ON":
        GPIO.output(RELAIS_GPIO, GPIO.LOW)
    elif sys.argv[2] == "OFF":
        GPIO.output(RELAIS_GPIO, GPIO.HIGH) # an

rights for relais.py:
sudo chmod +x /etc/openhab2/scripts/relais.py

–>Thing exec:command:relais1-control [ command="/etc/openhab2/scripts/relais.py 23 %2$s", interval=0, autorun=true ]


Group grp_relais "Relais Gruppe" <poweroutlet>
String relais1Switch "Relais 1" <poweroutlet> (grp_relais) [ "Switchable" ] { channel="exec:command:relais1-control:input", autoupdate="true" }


sitemap relais label="Relais" {
    Frame label="Relais Gruppe" {
        Switch item=relais1Switch //mappings=[ "ON"="ON", "OFF"="OFF" ]

Try moving the script to:

cp didn’t work.
mv led to the fact that i’m now no longer finding the file

create file new with
sudo nano /var/lib/openhab2/bin/relais.py leads to an error:

“Error writing /var/lib/openhab2/bin/relais.py: Not a directory!”

now tried to place it under /var/lib/openhab2 but w/o any effect…

events shows nothing…

Item ‘relais1Switch’ received command OFF
relais1Switch changed from ON to OFF

I apologize, maybe try in:
It could be because of permission issues and this folder has all the permissions for the openhab user.

What error codes do you get in your openhab.log?

"An exception occurred while executing ‘/etc/openhab2/scripts/relais.py 23 OFF’ : 'Cannot run pgoram “/etc/openhab2/scripts/relais.py”: error=13, Permission denied

Would this change automatically when moving the script to /usr/share/openhab2/runtime/bin$ ??
or do i have to set the new location somewhere?

btw cp relais.py to /usr/share/openhab2/runtime/bin$ does also not work for me.

“cp: cannot create regular file ‘…/…/’:Permission denied”


yes tried that as well. the error does not show up but also the file in the directory.
I really don’t know what these *bin directories are but whenever I copy sth into it, the file does not show up there…

Rich, can you help here, please?

btw. just managed to implement the same functionality with the GPIO binding successfully.
But would still be nice to find out why the python script isn’t working… :-/

I don’t have a lot of time to walk you though this today.

  1. https://www.digitalocean.com/community/tutorials/an-introduction-to-linux-basics

  2. https://www.digitalocean.com/community/tutorials/linux-permissions-basics-and-how-to-use-umask-on-a-vps

  3. Using those two articles you should have learned how to create the file and set its permissions so the openhab user can execute it. It doesn’t matter where you put the python script so long as you use the full path to it in your exec binding Thing.

  4. Test you can run it as root and it will work: sudo relais.py.

  5. Test you can run it as openhab and it will work: sudo -u openhab relais.py

  6. Test you can run it using the executeCommandLine in a Rule triggered by a proxy Item.

rule "Testing python script"
    Item TestItem received command
    val results = executeCommandLine("path to script and arguments")
    logInfo("Test", results)

If there are errors from the script you will see them in openhab.log.

  1. If you got everything to work up to this point, now configure the exec binding.

Thanks Rich, I’ll save that too. I just couldn’t get my thoughts in orders today… :exploding_head: