Running a python script by the exec binding

I have very limited knowledge in linux and home automation.

I have found a phyton script that I have located in the folder etc/openhab2/scripts/watermeter

I want to execute:
python dialEye.py -u meter “http://192.168.2.135:88/cgi-bin/CGIProxy.fcgi?cmd=snapPicture2&usr=xxxx&pwd=yyyy

when I execute this in PuTTY it generates a number

I have installed the Exec binding and made a thing in Paper with the command:
python /etc/openhab2/scripts/watermeter/dialEye.py -u meter “http://192.168.2.135:88/cgi-bin/CGIProxy.fcgi?cmd=snapPicture2&usr=xxxx&pwd=yyyy

In the control of paper it sends the output:
ERROR: Cannot read configuration file: dialEye.conf
dialEye.conf is a conf file located in the same folder as dialEye.py

How shall I configure the thing such that it can execute the phyton scrpt?

What are the permissions on both files?

-rw-rw-r-- 1 openhabian openhabian 7341 Jun 5 23:25 dialEye.conf
-rw-rw-r-- 1 openhabian openhabian 38853 May 31 21:44 dialEye.py

OH permissions feels like a dark art to me. It resets the file permissions every time it starts so I am in the process of moving all my scripts out of the conf directories so I can control this a bit better. Your files don’t appear to be executable. Perhaps that might be the issue.

Try putting the files in another folder (away from the OH installation) and allow them to executable with chmod +x location/of/dialEye.py && chmod +x location/of/dialEye.conf

This is a good place to start on setting file permissions in linux. It’s what I have been reading while i figure them out myself, heh.

I put the files to /home/openhabian and made the chmod, and changed the command in the thing. Still no change.
It seems to be able to execute the dialEye.pp (as if change the path in the thing it writes "python: can’t open file ‘home/openhabian/watermeter/dialEye.py’: [Errno 2] No such file or directory python: "; with the correct path it writes “ERROR: Cannot read configuration file: dialEye.conf”).

The conf/scripts folder is not and never was intended as a place to put shell scripts. That folder is intended for openHAB Scripts. The start scripts do change the permissions on all the conf folders so a better place to store your shell scripts is ~openhab which maps to /var/lib/openhab2 in a standard apt-get installed deployment.

I am sorry, but my knowledge is unfortunately a bit too limited to follow all details.
What I did was to copy the files (https://zil.olammi.iki.fi/sw/dialEye/download.php) into /var/lib/openhab2/watermeter, and changed the command in the thing in Paper to python /var/lib/openhab2/watermeter/dialEye.py -u meter “http://192.168.2.135:88/cgi-bin/CGIProxy.fcgi?cmd=snapPicture2&usr=xxxx&pwd=yyyy” -> was the same result as before "ERROR: Cannot read configuration file: dialEye.conf"
If I executed the command
dialEye.py -u meter "http://192.168.2.135:88/cgi-bin/CGIProxy.fcgi?cmd=snapPicture2&usr=xxxx&pwd=yyyy"
when i was in the folder /var/lib/openhab2/watermeter it worked and returned a number

The python script is expecting there to be a dialEye.conf in the folder ./. You probably need to figure out if there is a way to pass the path to the dailEye.conf file in the call to the script.

Thanks, it is solved. Correct command line is:
python /var/lib/openhab2/watermeter/dialEye.py -f /var/lib/openhab2/watermeter/dialEye.conf -c /var/lib/openhab2/watermeter/docs/watercal.jpg -u meter http://192.168.2.135:88/cgi-bin/CGIProxy.fcgi?cmd=snapPicture2&usr=xxxx&pwd=yyyy

Is this dialeye.py script working well on your installation?

You have a webcam which makes photos of the watermeter and the script reads out the current values?

Was ist a big deal to configure this all to get it running or is it very simple?

hello,

need some help while stuck in displaying the temperature using dht11 sensor
got this error
2020-03-21 23:33:12.205 [WARN ] [ng.exec.internal.handler.ExecHandler] - Tried to execute ‘python /etc/openhab2/DHT11_Python/dht11_example.py’, but it is not contained in whitelist.

but when I ran the code python /etc/openhab2/DHT11_Python/dht11_example.py from ssh it will return a correct value
please find attached all config done

your code goes here
items

String Weather_Temperature "Temperature [%.2f C]" { channel="exec:command:dht11:exit" }

things

Thing exec:command:dht11 [ command="python /etc/openhab2/DHT11_Python/dht11_example.py", interval=5, autorun=true ]

sitemap

 Frame label="HTemperature"{

 Text item=Weather_Temperature label="Home Temperature" icon="temperature"

python code

import RPi.GPIO as GPIO
import dht11
import time
import datetime

# initialize GPIO
GPIO.setwarnings(True)
GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)

# read data using pin 14
instance = dht11.DHT11(pin=17)

try:
        while True:
            result = instance.read()
            if result.is_valid():
                print("%-3.1f C" % result.temperature)
	          
            exit()

except KeyboardInterrupt:
    print("Cleanup")
    GPIO.cleanup()

You could search this forum for recent postings about this message.

hey rossko57
yes it is contained but I don’t know if it is done in the right way.
created a misc folder (cd /etc/openhab2/misc/ ) and inside it exec.whitelist
inside the exec.whitelist : python /etc/openhab2/DHT11_Python/dht11_example.py

but also didn’t worked