Hey there,
I’m trying to dim a simple LED using openHab. However, I’m not getting anywhere. So my idea is to use “switch” with different mappings to control the brightness of the LED (Off, low, middle, high) with the exec binding.
If I use the command “sudo python slider.py 18 HELL” everything works fine but with the buttons on openHAB nothing happens…
I’m quite new to programming and openHAB. Hope anyone could help me with my problem.
There is no response to the String led1exec line at all. I also added the line
/etc/openhab2/scripts/slider.py 18 %2$s
to my misc folder in the exec.whitelist File to give the exec binding the permissions. The log tells me what I want to hear but nothing happens to my LED:
“led1 changed from AUS to DUNKEL”
Also note what it says in exec docs - when using autorun, the exec only runs if the command to input is different from the last command. It’s an unexpected quirk. The binding docs show how to workaround that with the run switch if needing to send the same command twice.
Test your file permissions out with a rule
rule "exec diagnostic"
when
Item led1 received command
then
Thread::sleep(1500)
val result=executeCommandLine("/etc/openhab2/scripts/slider.py 18 DUNKEL", 1000)
logInfo(“exectest”, “Command line result: {}”, result)
end
No whitelist action is needed here
EDIT - Fix the quotemarks
logInfo("exectest", "Command line result: {}", result)
Ok, I implemented the rule like above. My log shows this:
2020-04-30 14:40:14.126 [WARN ] [el.core.internal.ModelRepositoryImpl] - Configuration model ‘exectest.rules’ has errors, therefore ignoring it: [7,17]: no viable alternative at input ‘"’
[7,18]: no viable alternative at input ‘exectest’
[7,49]: mismatched input ‘:’ expecting ‘end’
Sry, I don’t know what that means, I very new to programming.
Ah ok, thanks for that!
Now the log shows this (The XXX are from me because I think the Code is a kind of safety key):
==> /var/log/openhab2/openhab.log <==
at okhttp3.RealCall.getResponseWithInterceptorChain(RealCall.java:185) ~[?:?]
at okhttp3.RealCall$AsyncCall.execute(RealCall.java:135) ~[?:?]
at okhttp3.internal.NamedRunnable.run(NamedRunnable.java:32) ~[?:?]
… 3 more
2020-04-30 16:24:27.070 [INFO ] [io.openhabcloud.internal.CloudClient] - Disconnected from the openHAB Cloud service (UUID = XXXXXXXXXXXXXXXXX, base URL = http://localhost:8080)
2020-04-30 16:24:28.675 [INFO ] [io.openhabcloud.internal.CloudClient] - Connected to the openHAB Cloud service (UUID = XXXXXXXXXXXXXXX, base URL = http://localhost:8080)
2020-04-30 16:25:53.565 [INFO ] [el.core.internal.ModelRepositoryImpl] - Loading model ‘exectest.rules’
2020-04-30 16:26:14.656 [WARN ] [lipse.smarthome.io.net.exec.ExecUtil] - Execution failed (Exit value: -559038737. Caused by java.io.IOException: Cannot run program “/etc/openhab2/scripts/slider.py” (in directory “.”): error=13, Permission denied)
2020-04-30 16:26:14.691 [INFO ] [ipse.smarthome.model.script.exectest] - Command line result:
2020-04-30 16:29:29.007 [WARN ] [okhttp3.OkHttpClient ] - A connection to https://myopenhab.org/ was leaked. Did you forget to close a response body? To see where this was allocated, set the OkHttpClient logger level to FINE: Logger.getLogger(OkHttpClient.class.getName()).setLevel(Level.FINE);
That seems clear enough, but I cannot advise how to fix your file permissions as I know little of *nix
There don’t seem to be any x for executable in your ls
==> /var/log/openhab2/openhab.log <==
2020-04-30 18:04:22.490 [INFO ] [ipse.smarthome.model.script.exectest] - Command line result: /etc/openhab2/scripts/slider.py: 1: /etc/openhab2/scripts/slider.py: import: not found
/etc/openhab2/scripts/slider.py: 2: /etc/openhab2/scripts/slider.py: import: not found
/etc/openhab2/scripts/slider.py: 3: /etc/openhab2/scripts/slider.py: import: not found
/etc/openhab2/scripts/slider.py: 5: /etc/openhab2/scripts/slider.py: Syntax error: word unexpected (expecting “)”)
Those are all errors coming from your python script. There is something wrong with the script or that script depends on packages that are not available to the openhab user.
Now you’ve fixed it to run from the rule, you can go back to using exec binding. It works fine, but can just be harder to diagnose external problems like that.
Now I have a problem with the brightness buttons. When I press a button for the first time everything is fine and the LED shines in the right brightness. However, when I tap a different brightness afterwards, the LED begins to flicker. I think the problem is that the script is stuck in my while loop and then just executing the next command at the same time, right? Is there a rule for this or is my script simply wrong? What can I do to fix this?
If you wanted to run your script forever, you would want it (one copy!) running independently like a service, and somehow modify it to listen out for a parameter sent by openHAB. Using the parameter to modify the PWM.
But can’t you just send settings to this GPIO utility, and it sustains the last setting by itself?
This seems to work with no script -