Waveshare UPS hat at OH4

Hi Guys
can you please help me to bring my waveshare UPS hat data to OH4?

I have OH4.0.0.M4 running on rpi4 4GB
(just moving from OH2.5 @rpi3b)

I followed the instruction from @Jeff_Smart (Thnaks it was a great help) post here:https://community.openhab.org/t/waveshare-ups-hat-b-python-script-values-display-in-openhab/137886/7

I can run the py script from consol and all items updating in OH4 but I cannot get the exec commund run.
This is the command of the Thing:

sudo -u openhab python3 /etc/openhab/INA219.py

I add this to the whitelist:

#WaveShare UPS Hat
sudo -u openhabian python3 /etc/openhab/INA219.py
sudo -u openhab python3 /etc/openhab/INA219.py
sudo -u openhab /usr/bin/python3  /etc/openhab/INA219.py
sudo -u openhabian /usr/bin/python3  /etc/openhab/INA219.py

and this to my file in sudoers.d :

openhabian ALL = NOPASSWD: /etc/python3, /usr/bin/python3
openhab ALL = NOPASSWD: /etc/python3, /usr/bin/python3

Running the exec command i get this output:

Sorry, user openhab is not allowed to execute '/usr/bin/python3 /etc/openhab/INA219.py' as openhab on openhabian.

As you can see I tried many things but non of them working.

Thanks a lot

openHAB is already running as user openhab. This part is redundant at best but if you’ve never run sudo as the openhab user before, the first time it requires you to acknowledge a message before it will execute a command.

Forget about all the sudo stuff and just run the script directly. You may need to use the full path and you may need to install any libraries that the script depends upon for user openhab or globally.

Thanks Rich,
I tried the command w/o sudo and got this error:

Traceback (most recent call last):
File “/etc/openhab/INA219.py”, line 203, in
ina219 = INA219(addr=0x42)
File “/etc/openhab/INA219.py”, line 70, in init
self.bus = smbus.SMBus(i2c_bus);
PermissionError: [Errno 13] Permission denied

I am not a linux prof but seems it miss the library smbus installed as openhab.

Btw what is the password of user openhab ?

Thnaks

User openhab is not created as a user with full shell access thus there is no password set for that user.
User openhab can only be used in the karaf console. There the password is habopen.

Add user openhab to group i2c. This should/may solve the permission problem.

I add openhab to i2c group but helped. Still the same error.

However if i run in the terminal sudo -u openhab python3 /etc/openhab/INA219.py than it runs without problem

under which conditions ? What is the user that is currently being logged in ?

then its being executed as user openhab.
That means when its being executed from within openhab it also should work as all processes run with openhab user permissions.
In case it does not work use the executeCommandLine version that stores returned values in a variable and write that variable as debug output to openhab.log file it should give more information about the root cause then.