My python script does not work with EXEC Binding

Hello dear forum!

I would like to use a Python script to read the adafruit ads1115 analog converter. that works well in the command line of the Pi. I get the current value with print (temp) at the end of the script.
But with the EXEC Binding in openhab2 I get only “NULL” as answer. So I assume that the script is not executed. Other bash scripts work well.

I’ve been here for 3 days reading everything in the forum about it, searched the whole Google and tried everything - I despair! And I’ll certainly fired soon because I’m not working anymore :slight_smile:

My Thing:
exec:command:ADC1115_Temp1 [command=“python /etc/openhab2/scripts/ads1115tempLM35.py 0”]

My Item:
String ADC1115_String_Temp1 “ADS1115 A0 [%s °C]” {channel=“exec:command:adc1115_Temp1:output”}

I have set:
/etc/openhab2/scripts$ chmod +x ads1115tempLM35.py
/etc/openhab2/scripts$ sudo chown openhab: ads1115tempLM35.py

In The log file after refreshing model ‘ads1115.things’:
[WARN ] [ore.common.registry.AbstractRegistry] - Could not remove element: null

i use openhabian image version mit openHAB 2.4.0~M4-1

What else I have to do? Please Help me!

You haven’t defined any interval the command is suppose to run? how often?

Thing exec:command:uniquename [command="/command/to/execute here", interval=15, timeout=5, autorun=false]

Ref https://www.openhab.org/addons/bindings/exec/#binding-configuration

Hi!

as with my onewire things over EXEC Binding, i do update the item in my rule (for test all 5 seconds)

I just wrote it directly to the thing

exec:command:ADC1115_Temp1 [command=“python /etc/openhab2/scripts/ads1115tempLM35.py 0”, interval=15, timeout=5, autorun=false]

but no change

What does openhab.log say when it runs and when it loads the thing file ?

I have just make an reboot to have an fresh load of the modul

there are no errors or warnings after loading!

but it dont work! So the problem must be in the script right?

####################################################
#!/usr/bin/env python

import Adafruit_ADS1x15
import time
import sys

adc = Adafruit_ADS1x15.ADS1115()
GAIN = 4
Ax = int(sys.argv[1]) #(0=A0;1=A1;2=A3;3=A4)
temp = 0

for i in range(10): #10 Werte messen und addieren
wert = int(adc.read_adc(Ax, gain=GAIN))
wert = wert1.024 #GAIN
wert = wert/32767 #Volt
temp = temp + wert
time.sleep(0.1)
else:
temp = temp
10 # *100 für Temperatur /10 weil 10 Werte
print(temp)
####################################################

OH runs as the openhab user. Therefore any script you execute using Exec binding or executeCommandLine must also run as the openhab user. Since your script is interacting with hardware, most likely the openhab user does not have permission to read/write to those hardware devices.

Often this can be corrected by adding the openhab user to the gpio or dialout groups.