Nussert
(...)
April 30, 2018, 8:34pm
1
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.
vzorglub
(Vincent Regaud)
May 1, 2018, 11:19am
2
What does you openhab.log show?
Nussert
(...)
May 1, 2018, 1:28pm
3
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.
vzorglub
(Vincent Regaud)
May 1, 2018, 3:43pm
4
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 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
Nussert
(...)
May 1, 2018, 7:07pm
5
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.
vzorglub
(Vincent Regaud)
May 1, 2018, 7:13pm
6
In the paperUI you need to enable legacy bindings and the old exec binding should show up
Nussert
(...)
May 2, 2018, 4:20am
7
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?
Nussert
(...)
May 2, 2018, 4:35am
8
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
vzorglub
(Vincent Regaud)
May 2, 2018, 6:02am
9
Your openhab user doesn’t have the permission to execute the script
Change the permission
sudo chmod 700 ‘/home/openhabian/PIGPIO/code/Test.py
Nussert
(...)
May 2, 2018, 8:54am
10
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
vzorglub
(Vincent Regaud)
May 2, 2018, 9:02am
11
Try 755
Or move the script to /etc/openhab2/scripts
Nussert
(...)
May 2, 2018, 4:16pm
12
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!
vzorglub
(Vincent Regaud)
May 2, 2018, 4:22pm
13
Good, well done. Can you mark the thread as solved, please?
1 Like