- openHABian 3.3.0 on rPi4 with 4GB
[Post updated]
I thought I give the exec binding a go, and used the full example in the documentation
The example seems to make sense.
I have whitelisted the command.
# For security reasons all commands that are used by the exec binding or
# transformation need to be whitelisted.
# Every command needs to be listed on a separate line below.
/home/openhabian/VirtualEnvironments/myenergi/set_zappi_mode.py eco
/home/openhabian/VirtualEnvironments/myenergi/set_zappi_mode.py %2$s
Running the command manually works.
(myenergi) # [2023-03-20 16:45] openhabian@openhabian ~/VirtualEnvironments/myenergi $
./set_zappi_mode.py eco
Selected mode is eco.
Zappi is in Eco mode.
(myenergi) # [2023-03-20 16:45] openhabian@openhabian ~/VirtualEnvironments/myenergi $
I am logged in as openhabian:
whoami
openhabian
pwd
/home/openhabian/VirtualEnvironments/myenergi
The Thing is configured as follows:
The error message I am getting is:
2023-03-20 18:04:12.090 [INFO ] [penhab.core.model.script.Zappi.01.01] - zap_test_switch........: OFF
2023-03-20 18:04:15.796 [INFO ] [penhab.core.model.script.Zappi.03.01] - Script has completed.
2023-03-20 18:04:24.177 [INFO ] [penhab.core.model.script.Zappi.01.01] - zap_CommandParameter...: eco
2023-03-20 18:04:24.379 [INFO ] [penhab.core.model.script.Zappi.03.01] - Script has completed.
2023-03-20 18:04:24.381 [INFO ] [penhab.core.model.script.Zappi.04.01] - Raw return result......: Traceback (most recent call last):
ModuleNotFoundError: No module named 'daemon'
Traceback (most recent call last):
ModuleNotFoundError: No module named 'daemon'
What might be worthwhile pointing out is that the python script runs in a virtual environment⦠ans suspect since the virtenv is not activated by the OH command line, the script does not find its related modules.
Maybe I need to create a bash script containing the virtenv activation?!
Any hints appreciated.
[edit]
I have created a bash script:
#!/usr/bin/env bash
set -e
cd /home/openhabian/VirtualEnvironments/myenergi
source "./bin/activate"
python set_zappi_mode.py $1
resulting in this error
2023-03-20 21:42:25.272 [INFO ] [penhab.core.model.script.Zappi.01.01] - zap_CommandParameter...: eco
2023-03-20 21:42:25.490 [INFO ] [penhab.core.model.script.Zappi.03.01] - Script has completed.
2023-03-20 21:42:25.491 [INFO ] [penhab.core.model.script.Zappi.04.01] - Raw return result......: Traceback (most recent call last):
File "/home/openhabian/VirtualEnvironments/myenergi/set_zappi_mode.py", line 7, in <module>
import run_zappi
File "/home/openhabian/VirtualEnvironments/myenergi/run_zappi.py", line 13, in <module>
import daemon
ModuleNotFoundError: No module named 'daemon'
Traceback (most recent call last):
File "/home/openhabian/VirtualEnvironments/myenergi/set_zappi_mode.py", line 7, in <module>
import run_zappi
File "/home/openhabian/VirtualEnvironments/myenergi/run_zappi.py", line 13, in <module>
import daemon
ModuleNotFoundError: No module named 'daemon'
==> /var/log/openhab/events.log <==
2023-03-20 21:42:25.262 [INFO ] [openhab.event.ItemCommandEvent ] - Item 'zap_test_switch' received command ON
2023-03-20 21:42:25.268 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'zap_test_switch' changed from OFF to ON
2023-03-20 21:42:25.273 [INFO ] [openhab.event.ItemCommandEvent ] - Item 'zap_CommandParameter' received command eco
2023-03-20 21:42:25.289 [INFO ] [penhab.event.ItemStatePredictedEvent] - Item 'zap_CommandParameter' predicted to become eco
2023-03-20 21:42:25.297 [INFO ] [openhab.event.ItemCommandEvent ] - Item 'zap_CommandRunning' received command ON
2023-03-20 21:42:25.300 [INFO ] [penhab.event.ItemStatePredictedEvent] - Item 'zap_CommandRunning' predicted to become ON
2023-03-20 21:42:25.304 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'zap_CommandRunning' changed from OFF to ON
2023-03-20 21:42:25.488 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'zap_CommandRunning' changed from ON to OFF
2023-03-20 21:42:25.491 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'zap_LastExecution' changed from 2023-03-20T21:28:20.825387+1000 to 2023-03-20T21:42:25.487209+1000
Calling the bash file directly works.
This must have something to do with the virtual environment.
I canβt figure out where the problem is.
It seems OH opens a very limited shell??
I also tried executeCommandLine
instead of using the binding; same problem.
executeCommandLine(Duration.ofSeconds(10), "/bin/sh", "/home/openhabian/VirtualEnvironments/myenergi/zap.sh", "eco")