Permission error when executing python or shell script reading the I2C/smbus via EXEC (OH2.5.4 on Pi4 Buster)

Tags: #<Tag:0x00007f617c2eec00> #<Tag:0x00007f617c2ee8e0> #<Tag:0x00007f617c2ee7c8>

Hi all,

I’m totally new with openHab and surely not a Linux guru… so I run into some trouble getting sensor data from a BME280, where I hope you can help me with.

Please excuse my English, it’s not my native tongue.

Info’s on my problem:

  • Pi4 with Buster

  • self installed openHab 2.5.4. with Zulu8

  • i would like to read out a BME 280 via a script (because i can then implement other things similar)

  • i tried to read the sensor via python script or this python script run via a shell script

  • both the *.sh or the *.py scripts are running and reading data if I (user pi) execute them

  • I found i need to whitelist EXEC commands -> done, i think it is working in principle

  • the script is owned by openhub and has -u rwx -g rx -o rx permissions

  • the user openhab is in the groups i2c, gpio, spi, input, tty

  • the script is executed every 60s

My problem is:

Instead of the string (i later want to read data out of it, but this is a task to be done in the future) i expect with the python script output (which is exactly the same as the output the shell script generates by executing the phython script), i get the following:

“Traceback (most recent call last): File “/var/lib/openhab2/bme280.py”, line 30, in bus = smbus.SMBus(1) # Rev 2 Pi, Pi 2 & Pi 3 uses bus 1 IOError: [Errno 13] Permission denied Traceback (most recent call last): File “/var/lib/openhab2/bme280.py”, line 30, in bus = smbus.SMBus(1) # Rev 2 Pi, Pi 2 & Pi 3 uses bus 1 IOError: [Errno 13] Permission denied”

So there seems to be a problem with the permissions… do you have an idea how i can resolve this? I tried to google it but fail to search for the fitting keywords.

Best wishes

Tobias

If you have a working python script it will probably be easier just to use the rest api to send data openHab items directly from python

import requests

requests.post('http://[openHab address]/rest/items/[itemname]', data = '[new value for openHab item]')
2 Likes

Hello Justin,
your tip is much appreciated, and it is a nice workaround even if it did not solve my problem directly. Nevertheless, after tinkering a lot which should not have changed any execution or owner rights it now works… So currently I have two working options ;).

Best wishes
Tobias