Have you installed the exec binding?
Is the line you want to execute included in the exec.whitelist file?
You may find interesting informations in this thread
The Exec binding is not needed here. The Exec binding is to create Things that get their values from executing external programs.
The Exec action is part of the core. In this case the Exec action allows you to execute an external program from your scripts, which is what the OP is trying to do.
First, make sure that python is in the path that the openhab process can see.
Secondly, the executeCommandLine takes each argument as one piece of string, so it literally looks for a file called python<literal space>C:\openhab........ It doesn’t split them up for you like a normal shell / command prompt would.
Here take a look at the documentation, it specifically addressed this topic:
while the PATH environment variable is set. When I directly run the python script than it works. This means I do not have to give the full python path. But, how do I find out if openhab knows the path as well?
Does OH know it needs to start python or do I need to mention it like: executeCommandLine(python "C:.…) ?
And do I need “\” or "" or “//” or “/” if I am using everything in windows?
One small addition to what @jimtng wrote. Use the version of executeCommandLine that returns a message in case of a problem:
var Response = executeCommandLine(Duration.ofSeconds(5),"full path to python executable", "C:\\openhab\\conf\\scripts\\test.py", "arg1", "arg2")
Write the content of Response to logoutput.
As long as the extension .py is registered with the OS I would expect the OS to take care about executing the script by running the python interpreter. To be on safe side and have everything under control the approach of @jimtng should be perfect.
Just one question more: What you mean with “arg1 and arg2” in detail? Are this the arguments used for the python script or are this the arguments used for OpenHab?
Let’s say I have a python sript “test.py” with following definition inside:
set_gpio(self, chn, state)
What you use for the openhab call now?
executeCommandLine(“full path to python executable”, “C:\openhab\conf\scripts\test.py”,…
Ok thank you that works but in my case only for scripts which do only one task. With my python script I do have one big issue.
class Russ_GPIO(object):
def __init__(self):
self.com4 = serial.Serial(port="COM4", baudrate=115200, rtscts=False, dsrdtr=False, timeout=0.1, parity=serial.PARITY_NONE)
self.com4.setRTS(True)
self.com4.break_condition = True
def set_gpio(self, chn, state): #Set channel (0,1) and state (0,1)
if chn == 0:
if state == 0:
self.com5.setRTS(True)
else:
self.com5.setRTS(False)
In this case everything works when using the IDLE of pyhton. I can instantiate the class and run afterwards the method. But how it looks when I use OH? Here I can not find a solution how I instantiate the class in order the comport remains open. The comport opens but will close right again. This also happens when I run the script dircectly from the command line.