Oh yes sorry for not formatting the correct way, it was my first post.
It looks better now
Ok so if i only have:
var testmotion = executeCommandLine(Duration.ofSeconds(30), “python3”, “/etc/openhab/scripts/motionsensor.py”)
then I don’t see any output in logs.
And output of the
executeCommandLine(testmotion)
returns error from the first post.
I think that there is something wrong with the way that python3 is executed or maybe with permissions.
Because if i try:
val testmotion = executeCommandLine(Duration.ofSeconds(19), "python3", "/etc/openhab/scripts/motionsensor.py")
logInfo("test", testmotion)
I get this in the logs everytime script is executed.
==> /var/log/openhab/openhab.log <==
2021-10-29 18:43:16.306 [INFO ] [org.openhab.core.model.script.test ] - Looking in indexes: https://pypi.org/simple, https://www.piwheels.org/simple
Requirement already satisfied: picamera in ./.local/lib/python3.7/site-packages (1.13)
and if i change try and except for loading module to just
from picamera import PiCamera
then everytime script is executed i get:
==> /var/log/openhab/openhab.log <==
2021-10-29 18:45:26.063 [INFO ] [org.openhab.core.model.script.test ] - Traceback (most recent call last):
File "/etc/openhab/scripts/motionsensor.py", line 10, in <module>
from picamera import PiCamera
ModuleNotFoundError: No module named 'picamera'
picamera module is installed with pip3
root@openhab:/etc/openhab/scripts# sudo -u openhab pip3 install picamera
Looking in indexes: https://pypi.org/simple, https://www.piwheels.org/simple
Requirement already satisfied: picamera in /var/lib/openhab/.local/lib/python3.7/site-packages (1.13)
This is a very strange thing, because it seems like that picamera module is already installed for openhab user (which it is since it works ok if i run it as openhab user from shell). But on the other hand it cannot get loaded because there is no picamera module installed ?!?!?!’
So ok, I made a shell script that executes:
#!/bin/bash
whoami
/usr/bin/python3 /etc/openhab/scripts/motionsensor.py
and every time a get the same error in logs:
==> /var/log/openhab/openhab.log <==
2021-10-29 19:14:45.102 [WARN ] [rg.openhab.core.io.net.exec.ExecUtil] - Error occurred when executing commandLine '[+ whoami
openhab
+ /usr/bin/python3 /etc/openhab/scripts/motionsensor.py
* failed to open vchiq instance
]'
java.io.IOException: Cannot run program "+ whoami
openhab
+ /usr/bin/python3 /etc/openhab/scripts/motionsensor.py
* failed to open vchiq instance
": error=2, No such file or directory
at java.lang.ProcessBuilder.start(ProcessBuilder.java:1128) ~[?:?]
at java.lang.ProcessBuilder.start(ProcessBuilder.java:1071) ~[?:?]
at org.openhab.core.io.net.exec.ExecUtil.executeCommandLine(ExecUtil.java:59) ~[?:?]
at org.openhab.core.model.script.actions.Exec.executeCommandLine(Exec.java:40) ~[?:?]
at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:?]
at jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:?]
at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:?]
at java.lang.reflect.Method.invoke(Method.java:566) ~[?:?]
at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter.invokeOperation(XbaseInterpreter.java:1192) ~[?:?]
at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter.invokeOperation(XbaseInterpreter.java:1167) ~[?:?]
at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter._invokeFeature(XbaseInterpreter.java:1153) ~[?:?]
at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter.invokeFeature(XbaseInterpreter.java:1098) ~[?:?]
at org.openhab.core.model.script.interpreter.ScriptInterpreter.invokeFeature(ScriptInterpreter.java:151) ~[?:?]
at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter._doEvaluate(XbaseInterpreter.java:1008) ~[?:?]
at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter._doEvaluate(XbaseInterpreter.java:971) ~[?:?]
at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter.doEvaluate(XbaseInterpreter.java:247) ~[?:?]
at org.openhab.core.model.script.interpreter.ScriptInterpreter.doEvaluate(ScriptInterpreter.java:226) ~[?:?]
at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter.internalEvaluate(XbaseInterpreter.java:227) ~[?:?]
at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter._doEvaluate(XbaseInterpreter.java:475) ~[?:?]
at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter.doEvaluate(XbaseInterpreter.java:251) ~[?:?]
at org.openhab.core.model.script.interpreter.ScriptInterpreter.doEvaluate(ScriptInterpreter.java:226) ~[?:?]
at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter.internalEvaluate(XbaseInterpreter.java:227) ~[?:?]
at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter.evaluate(XbaseInterpreter.java:213) ~[?:?]
at org.openhab.core.model.script.runtime.internal.engine.ScriptImpl.execute(ScriptImpl.java:80) ~[?:?]
at org.openhab.core.model.script.runtime.internal.engine.DSLScriptEngine.eval(DSLScriptEngine.java:131) ~[?:?]
at org.openhab.core.automation.module.script.internal.handler.ScriptActionHandler.lambda$0(ScriptActionHandler.java:62) ~[?:?]
at java.util.Optional.ifPresent(Optional.java:183) [?:?]
at org.openhab.core.automation.module.script.internal.handler.ScriptActionHandler.execute(ScriptActionHandler.java:59) [bundleFile:?]
at org.openhab.core.automation.internal.RuleEngineImpl.executeActions(RuleEngineImpl.java:1183) [bundleFile:?]
at org.openhab.core.automation.internal.RuleEngineImpl.runRule(RuleEngineImpl.java:991) [bundleFile:?]
at org.openhab.core.automation.internal.TriggerHandlerCallbackImpl$TriggerData.run(TriggerHandlerCallbackImpl.java:90) [bundleFile:?]
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515) [?:?]
at java.util.concurrent.FutureTask.run(FutureTask.java:264) [?:?]
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:304) [?:?]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128) [?:?]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628) [?:?]
at java.lang.Thread.run(Thread.java:829) [?:?]
Caused by: java.io.IOException: error=2, No such file or directory
at java.lang.ProcessImpl.forkAndExec(Native Method) ~[?:?]
at java.lang.ProcessImpl.<init>(ProcessImpl.java:340) ~[?:?]
at java.lang.ProcessImpl.start(ProcessImpl.java:271) ~[?:?]
at java.lang.ProcessBuilder.start(ProcessBuilder.java:1107) ~[?:?]
... 36 more
First i get * failed to open vchiq instance error which means openhab user is not in video group, but it is, because from shell it works ok and i have checked.
video:x:44:openhabian,openhab
And this error is also strange because it tells me that “rg.openhab.core.io.net.exec.ExecUtil” and java cannot run program “whoami” but then returns openhab, which is correct how it should be.
java.io.IOException: Cannot run program "+ whoami
I bet there is something wring with permissions or with my installation of openhab.
Openhab is installed on RPI 3 with image file openhabian-pi-raspios32-v1.6.6.img.xz.
No docker container or anything.