Switch 433 Mhz sockets with the exec binding

Hi,

I installed openHAB 2 a few days ago to control my 433 Mhz sockets.
Before that i switched them using wiringPi and raspberry-remote, which worked pretty well. So my plan was to execute

/home/piremote/raspberry-remote/send 01011 30 1 -b

using the binding-exec - 1.9.0.SNAPSHOT.
Running the command in Putty it works, but when the exec binding - installed via PaperUI - should do this for me nothing happens. The openHAB 2 log says

2016-11-26 09:49:51.469 [INFO ] [ab.binding.exec.internal.ExecBinding] - executed commandLine '/home/piremote/raspberry-remote/send 01011 30 1 -b'

but at all it seems doing nothing. I assume exec outputs these as soon as I touch the switch.
I tried some other things like putting the command in a sh file, or just let exec create some file - nothing.

What did I do wrong?

Samuel

The Exec binding is one of the most difficult ones to get correct and working.

I assume you installed using apt-get?

If so then remember that OH is running under the OH user. Consequently you need to set up this user to have permission to run this command and use any and all resources this script uses.

Sometimes the Exec binding also requires one to replace spaces with @@.

Finally, you never get to see what the script you ran returned in the log. If you want to see what your script is actually returning, in this case the error messages, you need to stop using the Exec binding and instead use a Rule with:

val results = executeCommandLine("/home/piremote/raspberry-remote/send 01011 30 1 -b", 5000)
logInfo("Exec", results)

Personally, I will go out of my way to avoid using this binding wherever possible because of all the problems I and others have had with it.

Thank you, your advice helped me a lot!
Yes, I installed using apt-get, the offline edition.

I created a rule with your content - now the openhab.log looks like this:

2016-11-28 11:59:18.163 [INFO ] [.eclipse.smarthome.model.script.Exec] - wiringPiSetup: Must be root. (Did you forget sudo?)
operating in binary mode
using pin 0

just added a sudo in front of the command

2016-11-28 11:59:54.705 [INFO ] [.eclipse.smarthome.model.script.Exec] - sudo: no tty present and no askpass program specified

I added the openhab user to sudo group, but when I try this again the same message appears.

EDIT: I forgot to mention the openhab user should have permissions to run the command.

That error looks like you haven’t configured openhab in sudoers to not require a password for the command. You either need to pass the password as part of the command or configure sudoers to not require the password.

Okay, I the OH user should now be allowed to run the command.
So I tried again and this happened in the log:

2016-11-28 19:22:01.030 [ERROR] [ore.internal.events.OSGiEventManager] - Dispatching/filtering event for subscriber 'org.eclipse.smarthome.core.events.EventSubscriber' failed: unable to create new native thread
java.lang.OutOfMemoryError: unable to create new native thread
	at java.lang.Thread.start0(Native Method)[:1.8.0_65]
	at java.lang.Thread.start(Thread.java:714)[:1.8.0_65]
	at java.util.concurrent.ThreadPoolExecutor.addWorker(ThreadPoolExecutor.java:950)[:1.8.0_65]
	at java.util.concurrent.ThreadPoolExecutor.execute(ThreadPoolExecutor.java:1368)[:1.8.0_65]
	at org.eclipse.smarthome.core.common.QueueingThreadPoolExecutor.execute(QueueingThreadPoolExecutor.java:148)
	at java.util.concurrent.AbstractExecutorService.submit(AbstractExecutorService.java:134)[:1.8.0_65]
	at org.eclipse.smarthome.core.common.SafeMethodCaller.callAsynchronous(SafeMethodCaller.java:185)[96:org.eclipse.smarthome.core:0.9.0.201611272028]
	at org.eclipse.smarthome.core.common.SafeMethodCaller.call(SafeMethodCaller.java:79)[96:org.eclipse.smarthome.core:0.9.0.201611272028]
	at org.eclipse.smarthome.core.common.SafeMethodCaller.call(SafeMethodCaller.java:63)[96:org.eclipse.smarthome.core:0.9.0.201611272028]
	at org.eclipse.smarthome.core.internal.events.OSGiEventManager.dispatchESHEvent(OSGiEventManager.java:188)[96:org.eclipse.smarthome.core:0.9.0.201611272028]
	at org.eclipse.smarthome.core.internal.events.OSGiEventManager.handleEvent(OSGiEventManager.java:163)[96:org.eclipse.smarthome.core:0.9.0.201611272028]
	at org.eclipse.smarthome.core.internal.events.OSGiEventManager.handleEvent(OSGiEventManager.java:146)[96:org.eclipse.smarthome.core:0.9.0.201611272028]
	at org.apache.felix.eventadmin.impl.handler.EventHandlerProxy.sendEvent(EventHandlerProxy.java:415)[3:org.apache.karaf.services.eventadmin:4.0.4]
	at org.apache.felix.eventadmin.impl.tasks.HandlerTask.run(HandlerTask.java:90)[3:org.apache.karaf.services.eventadmin:4.0.4]
	at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)[:1.8.0_65]
	at java.util.concurrent.FutureTask.run(FutureTask.java:266)[:1.8.0_65]
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)[:1.8.0_65]
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)[:1.8.0_65]
	at java.lang.Thread.run(Thread.java:745)[:1.8.0_65]
2016-11-28 19:22:01.033 [ERROR] [ore.internal.events.OSGiEventManager] - Dispatching/filtering event for subscriber 'org.eclipse.smarthome.core.events.EventSubscriber' failed: unable to create new native thread
java.lang.OutOfMemoryError: unable to create new native thread
	at java.lang.Thread.start0(Native Method)[:1.8.0_65]
	at java.lang.Thread.start(Thread.java:714)[:1.8.0_65]
	at java.util.concurrent.ThreadPoolExecutor.addWorker(ThreadPoolExecutor.java:950)[:1.8.0_65]
	at java.util.concurrent.ThreadPoolExecutor.execute(ThreadPoolExecutor.java:1368)[:1.8.0_65]
	at org.eclipse.smarthome.core.common.QueueingThreadPoolExecutor.execute(QueueingThreadPoolExecutor.java:148)
	at java.util.concurrent.AbstractExecutorService.submit(AbstractExecutorService.java:134)[:1.8.0_65]
	at org.eclipse.smarthome.core.common.SafeMethodCaller.callAsynchronous(SafeMethodCaller.java:185)[96:org.eclipse.smarthome.core:0.9.0.201611272028]
	at org.eclipse.smarthome.core.common.SafeMethodCaller.call(SafeMethodCaller.java:79)[96:org.eclipse.smarthome.core:0.9.0.201611272028]
	at org.eclipse.smarthome.core.common.SafeMethodCaller.call(SafeMethodCaller.java:63)[96:org.eclipse.smarthome.core:0.9.0.201611272028]
	at org.eclipse.smarthome.core.internal.events.OSGiEventManager.dispatchESHEvent(OSGiEventManager.java:188)[96:org.eclipse.smarthome.core:0.9.0.201611272028]
	at org.eclipse.smarthome.core.internal.events.OSGiEventManager.handleEvent(OSGiEventManager.java:163)[96:org.eclipse.smarthome.core:0.9.0.201611272028]
	at org.eclipse.smarthome.core.internal.events.OSGiEventManager.handleEvent(OSGiEventManager.java:146)[96:org.eclipse.smarthome.core:0.9.0.201611272028]
	at org.apache.felix.eventadmin.impl.handler.EventHandlerProxy.sendEvent(EventHandlerProxy.java:415)[3:org.apache.karaf.services.eventadmin:4.0.4]
	at org.apache.felix.eventadmin.impl.tasks.HandlerTask.run(HandlerTask.java:90)[3:org.apache.karaf.services.eventadmin:4.0.4]
	at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)[:1.8.0_65]
	at java.util.concurrent.FutureTask.run(FutureTask.java:266)[:1.8.0_65]
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)[:1.8.0_65]
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)[:1.8.0_65]
	at java.lang.Thread.run(Thread.java:745)[:1.8.0_65]

When is the last time OH has been restarted. You shouldn’t be getting out of memory errors regardless, but if there is a memory leak somewhere that would explain the problem and a reboot of OH will clear up the problem, at least temporarily.

Once you confirm that your script works, you should start monitoring your OH to see if it continues to grow in its memory use and create an issue on github.

I restarted 10 hours ago - so far no out of memory.
One last question about the syntax of the exec binding.
Until binding-exec - 2.0.0.SNAPSHOT this

Switch dg_sa_li_kommode "Kommode" <light> (gDGSamiZimmer, gDGLicht) { exec="ON:/home/piremote/raspberry-remote/send@01011@30@1@-b, OFF:/home/piremote/raspberry-remote/send 01011 30 0 -b" }

worked, but since the 2.0 update nothing happens, no error, warning or information in the log.

The 2.0 binding requires a thing definition. Do some searches in the forum for more info. There’s a wiki for the 2.0 binding.

I’m still having difficulties understanding the 2.0 syntax, I’ll be using1.9 for some time still.

The new 2.0 version of the Exec binding requires you to create Things.

http://docs.openhab.org/addons/bindings/exec/readme.html

One has to be very careful to see and understand which version of a binding one is using. All 2.0 version bindings are configured using Things and Channels on those things are mapped to the Items. All 1.9 bindings have no Things and have their configuration defined on the Item as you do above.

So you either need to convert your exec= from above to a Thing as described in the link above or switch to using the 1.9 version of the binding.

I converted my exec(1.9)= to a Thing

Thing exec:command:on [command="/home/piremote/raspberry-remote/send 01011 30 1 -b"]

As I understood the “on” is my identifier for this Thing.

According to the description my channel has to look like this

{ channel="exec:command:on:run" }

I’m not sure what is the right Channel type, is it run, execute or something else?

I think you will have to experiment to figure this out. The docs for this binding are not yet very detailed. It is a very new 2.0 binding so I’m not surprised.

As a workaround you can try to exec ssh pi@localhost “your command” But you should enable passwordless ssh access to localhost before. In that case you can write sudo without problems. That code is from my configuration:

Switch Restart1 "Reboot openHAB"      (Administration) { exec="ON:ssh localhost sudo systemctl restart openhab.service" }
Switch Restart2 "Reboot Raspberry Pi" (Administration) { exec="ON:ssh localhost sudo reboot" }

I’m not sure if this works with exec 2.0, as far as I understood you have to create a Thing with the ssh command.