Exec Binding: Run endless script and get updated output

Hello everybody,

I’ve started with openHAB one week ago and have the following running:
Exec Binding that calls a python script which checks the status of a magnetic door sensor. The python script runs with an interval of 2 seconds and prints the status of the door sensor which is “garage door is open” and “garage door is closed” and this is shown as “Output” of the Exec Binding.

But what I’d like to have is the following:
The Exec Binding runs a python script, which checks the status of the magnetic door sensor in an endless loop. The python script just prints the status “garage door is open/closed” if it changes and that printing is recognized as Output in the Exec Binding. I’ve written a python script which does exactly what I want, but in openHAB the Output of the Exec Binding doesn’t change and is “NULL”.

Does anyone know whether it is possible what I want?

This is my pythonscript with the endless loop:

import RPi.GPIO as GPIO
from time import sleep

GPIO.setmode(GPIO.BCM) # GPIO Nummern statt Board Nummern
Magnetschalter_GPIO = 27
GPIO.setup(Magnetschalter_GPIO, GPIO.IN, pull_up_down=GPIO.PUD_UP) # GPIO Modus zuweisen

def Ausloesefunktion(GPIO_NR_Funktion):
    if GPIO.input(GPIO_NR_Funktion):
        print "Magnetschalter ist high, also offen"

        print "Magnetschalter ist low, also geschlossen"

GPIO.add_event_detect(Magnetschalter_GPIO, GPIO.BOTH, callback = Ausloesefunktion)

    while True:
        sleep (1)

    print "Fehler aufgetreten"

  • Platform information:
    • Hardware: Raspberry Pi 4
    • OS: openhabian
    • openHAB version: 3.0.1

Not possible. Neither the Exec binding nor openHAB work like that. You can configure the Exec binding to call your script every two seconds. You can change your Python script to run on it’s own outside of openHAB and push the sensor readings using openHAB’s REST API or MQTT. You cannot run a script that never exits from openHAB. After a few seconds, openHAB will time out the script and kill it. Furthermore, you won’t get the output from the script until after the script exits.

1 Like

ok, thank you very much. I was not sure whether I missed something.

I think I will have a look at the REST API and MQTT then.