[SOLVED] Execute Python Script

Hello Hasbians,

I try to execute simple python script in openHabian to display return value in sitemap:

#!/usr/bin/python
print 100

I save the Test.py File in:

\\192.168.178.24\openhabian\PIGPIO\code\Test.py

and in PuTTY it is:

\home\openhabian\PIGPIO\code\Test.py

I try to execute in two different ways first I create a .items:

String DHT22_Temperature “Temperatur [%s °C]” {exec=“<[/usr/bin/python /home/openhabian/PIGPIO/code/Test.py:1000:REGEX((.*?))]”}

Second way I try is to install Exec Bindings and create .things:

exec:command:dht22 [command=“sudo python /home/openhabian/PIGPIO/code/Test.py”, interval=0, timeout=10, autorun=false]

and .items:

String DHT22_Test “Temperatur [%s °C]” {channel=“exec:command:dht22:exit”}

both ways don’t produce any return, not in log, sitemap or any way.

I really don’t know what I do wrong, thankful for any response.

What does you openhab.log show?

My

tail -F /var/log/openhab2/openhab.log /var/log/openhab2/events.log

give no feedback about python script. The only warning I have is:

2018-05-01 11:08:47.747 [WARN ] [sitemap.internal.SitemapProviderImpl] - Filename home.sitemap does not match the name Home of the sitemap - please fix this as you might see unexpected behavior otherwise.

Nothing else what could be interesting.

There are two versions on the binding, Your first try:

String DHT22_Temperature “Temperatur [%s °C]” {exec="<[/usr/bin/python /home/openhabian/PIGPIO/code/Test.py:1000:REGEX((.*?))]"}

Would work with the v1.x of the binding (I use that… I find it simpler that the new one)

Also, adding sudo to a command doesn’t always make it work :smile: Add openhab user to allow execution of python script (Examples on google)

I don’t have enough experience to help you with the new version of the exec binding

1 Like

Thanks vzorglub for your help.

I delete my bad ‘sudo’ try in command line.

Is it possible to install older version of exec?

It is a bit sad can’t handle such a basic thing, hope I find a solution.

In the paperUI you need to enable legacy bindings and the old exec binding should show up

Hey vzorglub,

epic progress. Like you say I install exec Bindings 1.X and become response from the first variant of Python Script call:

/usr/bin/python: can’t open file '/home/openhabian/PIGPIO/…

he cut off the rest of the path, but obviously something goes wrong.

The log get spammed with the following:

2018-05-02 06:18:22.837 [WARN ] [ab.binding.exec.internal.ExecBinding] - couldn’t transform response because transformationService of type ‘REGEX’ is unavailable
2018-05-02 06:18:23.943 [WARN ] [.core.transform.TransformationHelper] - Cannot get service reference for transformation service of type REGEX

Do you have an idea?

Ok, I install Exec Tranformation and RegEx Transformation in PaperUI under TRANSFORMATIONS.

The log is now free from the old Error-Message but the response from the python script keeps in the BasicUI:

/usr/bin/python: can’t open file '/home/openhabian/PIGPIO/…

And in the log I found:

2018-05-02 07:20:45.515 [vent.ItemStateChangedEvent] - DHT22_Temperature changed from NULL to /usr/bin/python: can’t open file ‘/home/openhabian/PIGPIO/code/Test.py’: [Errno 13] Permission denied

Your openhab user doesn’t have the permission to execute the script
Change the permission
sudo chmod 700 ‘/home/openhabian/PIGPIO/code/Test.py

I type:

sudo chmod 700 /home/openhabian/PIGPIO/code/Test.py

in PuTTY Console, ask for password, but no response.

After this, I refresh my openHab code, the result is the same:

2018-05-02 10:51:43.047 [vent.ItemStateChangedEvent] - DHT22_Temperature changed from NULL to /usr/bin/python: can’t open file ‘/home/openhabian/PIGPIO/code/Test.py’: [Errno 13] Permission denied

Try 755
Or move the script to /etc/openhab2/scripts

That was the advice I need:

I move Test.py Script to:

/etc/openhab2/scripts/Test.py

and in finaly I get my printed feedback by:

String DHT22_Temperature “[%s °C]” {exec=“<[/usr/bin/python /etc/openhab2/scripts/Test.py:1000:REGEX((.*?))]”}

Thanks a lot for your help vzorglub!

Good, well done. Can you mark the thread as solved, please?

1 Like