Hello! I have a problem. Openhab doesn’t run script in rules.
This is my rule.
Item mihome_sensor_magnet_158d0002e29d73_isOpen changed
to OPEN then
if (mihome_gateway_7c49eb88f15c_enableSound.state == ON){
sendTelegram("bot1", "test")
executeCommandLine("python3 /scripts/alarm.py")}
end
Is the space in the path behind python3 in all openHAB installations correct?
Edit: Of course the space is correct as /scripts/alarm.py is the parameter for the command python3. Note to myself: Don’t write a post before the first coffee!
Yes it full path. I use armbian for orange pi. also in rules i run bash script that send sms if alarm. it works)
Item mihome_sensor_magnet_158d0002e29d73_isOpen changed
to OPEN then
if (mihome_gateway_7c49eb88f15c_volume.state == 100){
sendTelegram("bot1", "Сработала сигнализация")
executeCommandLine("bash /home/orange/bot/sms.sh")}
end
No i made dir /scripts and gave permissions to script. I have to put script to this path? /etc/openhab2/scripts/alarm.py
But how it worked in another openhab and how work another script?) Thank you i will try
You shouldn’t add directories to the root of a linux system.
Add your scripts to the openHAB scripts directory or (better) add a scripts directory to your user home directory instead
in first time i created script in home directory) But it didn’t work and i tryed to create in root directory)
script that send sms I created in home directory. i created in /etc/openhab2/scripts It doesn’t work
Item mihome_sensor_magnet_158d0002e29d73_isOpen changed to OPEN
then
if (mihome_gateway_7c49eb88f15c_enableSound.state == ON) {
sendTelegram("bot1", "test")
var testString = executeCommandLine("python3 /scripts/alarm.py")
logInfo("TEST", testString)
}
end
Now i see log File "/home/orange/bot/alarm.py", line 2, in <module> import requests ModuleNotFoundError: No module named 'requests'
but I have this module. I run this script from shell and it works. But if openhab run it doesn’t work((
Thank you all. I solved the poblem. I installed requests by command pip3 install reauests. When I install by sudo apt install python3-requests it begin to work))
sorry for bumping again into this issue, but I’ve a slimiar problem obviously in the context of python and importing libraries in the context of user openhab.
I was reading a lot, but can’t find an good solution. I want to avoid using sudo pip to install the libraries for various good reasons. On the other hand side it seems python isn’t able to find the libraries once not installed system wide by sudo pip or apt.
My problem:
I would like to start a python script using python-openhab library and various others in a rule just once and I know how to do this thanks to the doco.
I’m perfectly able to run the script to execute with the normal USER (having a home directory where the libraries are located in */.local), but once I try to check whether the script executes as user openhab, by “sudo -u openhab” I get the following reply:
USER@Machine:~/.local/lib/python3.6/site-packages$ sudo -u openhab /usr/bin/python3.6 /etc/openhab2/scripts/optimizer_6.1.py http://127.0.0.1:8080/rest --logfile /var/log/openhab2/optimizer.log --cycletime 90
Traceback (most recent call last):
File "/etc/openhab2/scripts/optimizer_6.1.py", line 6, in <module>
from openhab import OpenHAB
ModuleNotFoundError: No module named 'openhab'
USER@Machine:~/.local/lib/python3.6/site-packages$
Is there any way to come around installing all libraries with sudo pip? Or using any elevated user rights for the user openhab?