I was just wondering if anyone has any experience with calling external scripts from openHAB’s rules and scripting language. For example possibly having a rule which uses the openHAB timers to call a python script every X seconds. If not is there anyway to execute shell commands from openHAB’s scripting language. I am currently running openHAB on the raspberry pi with the latest version of openhabian.
executeCommandLine is not affected by the whitelist issue… no worries
yes, sounds like a great use for a rule triggered by cron, see here
getting an external script running from a rule can be a little tricky
first make sure it runs as the openhab user from the command line
make sure openhab user owns script and script is executable ect
If you just freshly installed, you are running openHAB 2.5.2. the openHABian image itself does not contain openHAB but downloads the current stable version.
I have seen things about Jython on the openHAB website but haven’t looked too much into it. The scripts I am currently running now are in python 3 but I would like to try to integrate them into openHAB so it can handle more of the scheduling of scripts so I don’t have to implement it myself in the python scripts.
Thanks for the resources Scott. I have been messing around with the executeCommandLine Action and have got it running external scripts that I have in python3. The code looks something like this in case anyone else was interested and is located in the rules/ directory of openHAB. The permissions on the python files also had to be changed to give openHAB access to them.
rule Test_Volts
when
System started
then
var result1 = executeCommandLine("python3 /home/openhabian/Environments/env_1/openHAB_Proj/bin/main.py")
logInfo("Test_Volts", result1)
end
I am going to see how this works out with just calling them as I have my own python packages that I created so might be a bit of work in it, thanks for the offer though. If i do end up having to convert them I’ll probably ask you for few pointers if thats ok?