Can't execute a python script with - exec

Hi there,

I’ve got a problem with my python temperaturescript.
I wrote a python script to read out the temperature with a dht22 sensor.
Manually I can sucessfully read out the temperatur, but if I try to execute the python script in openhab2, it show this error report in the Paper UI:

Traceback (most recent call last): File “/home/pi/Temperaturscripte/TemperaturPi.py”, line 8, in humidity, temperature = Adafruit_DHT.read_retry(sensor, pin) File “/usr/local/lib/python2.7/dist-packages/Adafruit_DHT-1.3.2-py2.7-linux-armv7l.egg/Adafruit_DHT/common.py”, line 94, in read_retry humidity, temperature = read(sensor, pin, platform) File “/usr/local/lib/python2.7/dist-packages/Adafruit_DHT-1.3.2-py2.7-linux-armv7l.egg/Adafruit_DHT/common.py”, line 81, in read return platform.read(sensor, pin) File “/usr/local/lib/python2.7/dist-packages/Adafruit_DHT-1.3.2-py2.7-linux-armv7l.egg/Adafruit_DHT/Raspberry_Pi_2.py”, line 34, in read raise RuntimeError(‘Error accessing GPIO.’) RuntimeError: Error accessing GPIO. Traceback (most recent call last): File “/home/pi/Temperaturscripte/TemperaturPi.py”, line 8, in humidity, temperature = Adafruit_DHT.read_retry(sensor, pin) File “/usr/local/lib/python2.7/dist-packages/Adafruit_DHT-1.3.2-py2.7-linux-armv7l.egg/Adafruit_DHT/common.py”, line 94, in read_retry humidity, temperature = read(sensor, pin, platform) File “/usr/local/lib/python2.7/dist-packages/Adafruit_DHT-1.3.2-py2.7-linux-armv7l.egg/Adafruit_DHT/common.py”, line 81, in read return platform.read(sensor, pin) File “/usr/local/lib/python2.7/dist-packages/Adafruit_DHT-1.3.2-py2.7-linux-armv7l.egg/Adafruit_DHT/Raspberry_Pi_2.py”, line 34, in read raise RuntimeError(‘Error accessing GPIO.’) RuntimeError: Error accessing GPIO.

My .things file looks like this:


Thing exec:command:Pi_temperature "Pi Temperatur" [command="python2 /home/pi/Temperaturscripte/TemperaturPi.py", interval=5, timeout=15, autorun=true]

Does anybody know how I make a python script successfully run in openhab2?
Thanks!

Best regards
Dominik :slightly_smiling_face:

You probably need to add the openhab user to the gpio group.

And how can I add the openhab user to gpio?

Regards
Dominik :slightly_smiling_face:

https://docs.openhab.org/installation/linux.html#recommended-additional-setup-steps

Google is also your friend.

1 Like

Hi,

I added the gpio user but no success. The same error message as before :neutral_face:

Ok thanks,

I solved it. I added dialout and tty and it worked fine.
sudo adduser openhab dialout
sudo adduser openhab tty

Thanks for help! :slightly_smiling_face:

1 Like