[SOLVED] Problem running python script from OpenHab

Hi there

I trying to switch my Avea bulb by a pythin script, but if I run the script from a rule I always get this error:

Logging from rule:

01-Feb-2019 23:24:24.727 [INFO ] [org.eclipse.smarthome.model.script.avea.rules ] - Command: /usr/bin/python3 /etc/openhab2/scripts/control_avea.py -l 4095 -r 4095 -g 2744 -b 1843

Failure:

01-Feb-2019 23:24:25.361 [INFO ] [g.eclipse.smarthome.model.script.Your command exec] - Result:Traceback (most recent call last):

File “/etc/openhab2/scripts/control_avea.py”, line 45, in

theColor = myBulb.get_color() # Query the current color

File “/usr/local/lib/python3.5/dist-packages/avea-1.0.6-py3.5.egg/avea/avea.py”, line 115, in get_color

File “/usr/local/lib/python3.5/dist-packages/avea-1.0.6-py3.5.egg/avea/avea.py”, line 50, in connect

File “/usr/local/lib/python3.5/dist-packages/bluepy-1.3.0-py3.5.egg/bluepy/btle.py”, line 445, in connect

self._connect(addr, addrType, iface)

File “/usr/local/lib/python3.5/dist-packages/bluepy-1.3.0-py3.5.egg/bluepy/btle.py”, line 426, in _connect

self._startHelper(iface)

File “/usr/local/lib/python3.5/dist-packages/bluepy-1.3.0-py3.5.egg/bluepy/btle.py”, line 284, in _startHelper

preexec_fn = preexec_function)

File “/usr/lib/python3.5/subprocess.py”, line 676, in init

restore_signals, start_new_session)

File “/usr/lib/python3.5/subprocess.py”, line 1282, in _execute_child

raise child_exception_type(errno_num, err_msg)

FileNotFoundError: [Errno 2] No such file or directory: '/usr/local/lib/python3.5/dist-packages/bluepy-1.3.0-py3.5.egg/bluepy/bluepy-helper’

01-Feb-2019 23:24:33.451 [INFO ] [org.openhab.io.openhabcloud.internal.CloudClient ] - Connected to the openHAB Cloud service (UUID = db110844-cb8d-41aa-871a-5b4d1bfabfb9, base URL = http://localhost:8080)

Running via ssh, everything is fine:

[23:21:32] openhabian@openHABianPi3b:~$ /usr/bin/python3 /etc/openhab2/scripts/control_avea.py -l 4095 -r 4095 -g 2744 -b 1843
2744
bedroom
(2048, 4095, 2744, 1843)
[23:24:44] openhabian@openHABianPi3b:~$

Any ideas why ?

Well, given it can’t find bluepy I’m going to guess you haven’t installed the necessary Python libraries this Python script requires. This error is not coming from openHAB and it really has nothing to do with openHAB. You might need to post this to a Python forum or where ever you got this Python script.

but it’s only when running by rule…

this works fine:

[23:43:22] openhabian@openHABianPi3b:~$ /usr/bin/python3 /etc/openhab2/scripts/control_avea.py -l 0 -w 0 -r 0 -g 0 -b 0
yes we can
[23:44:47] openhabian@openHABianPi3b:~$

What’s the exact command used from the rule? And what are the file acces rights of the python libraries?

resp = executeCommandLine("/usr/bin/python3 /etc/openhab2/scripts/control_avea.py"+" -l 0 -g 0 -b 0 -r 0", 10000)

drwxrwsr-x 3 root staff 4096 Mar 13 2018 python3.5

drwxr-sr-x 3 root staff 4096 Jan 30 21:40 bluepy

When you installed the bluez library, did you install it as root or your main login? If as you main login then it is only installed for that user. openHAB runs as the openHAB user and the library needs to be installed in a way that it’s available to that user too.

I installed bluepy with

[10:23:30] openhabian@openHABianPi3b:~$ pip3 -v install bluepy

That only instants it for the openhabian user. you with need to run it again as the openhab user or run it as root to make the library available to all users.

Okay got it

sudo pip3 uninstall bluepy
sudo pip3 install bluepy

now it’s running :slight_smile:

thx

next time just upgrade

pip3 install --upgrade XXX

1 Like