Openhab 2 exec binding 2.0 configuration

Hi,

can someone tell me how to use the new 2.0 exec binding?

Had a script running:
String st_copyLogs {exec="<[/etc/openhab2/scripts/openhablogs.sh:30000:REGEX((.*?))]"} // every 30000=30sec

Deleted it and made a thing:
Thing exec:command:openhablogs [command="bash /etc/openhab2/scripts/openhablogs.sh", interval=30]

but now nothing happens:
2016-12-04 10:55:08.617 [WARN ] [.thing.internal.GenericThingProvider] - Could not create channel ‘run’ for thing ‘exec:command:openhablogs’, because channel type ‘exec:running’ could not be found.
2016-12-04 10:55:08.611 [WARN ] [home.core.thing.binding.ThingFactory] - Could not create channel ‘run’ for thing type ‘exec:command:openhablogs’, because channel type ‘exec:running’ could not be found.
2016-12-04 10:55:08.517 [INFO ] [el.core.internal.ModelRepositoryImpl] - Refreshing model 'standard.things

I want the script running every x sec.

no idea what happend, but now the script is working…?

but i still get this errors after an openhab apt-upgrade:

2016-12-04 12:07:39.857 [INFO ] [core.karaf.internal.FeatureInstaller] - Installed 'openhab-binding-exec'
2016-12-04 12:07:40.797 [WARN ] [home.core.thing.binding.ThingFactory] - Could not create channel 'run' for thing type 'exec:command:openhablogs', because channel type 'exec:running' could not be found.
2016-12-04 12:07:41.174 [ERROR] [hab.binding.exec.handler.ExecHandler] - An exception occured while waiting for the process ('bash /etc/openhab2/scripts/openhablogs.sh') to finish : 'null'
2016-12-04 12:07:41.175 [WARN ] [hab.binding.exec.handler.ExecHandler] - Forcibly termininating the process ('bash /etc/openhab2/scripts/openhablogs.sh') after a timeout of 15000 ms
2016-12-04 12:13:05.110 [WARN ] [io.rest.core.thing.ThingTypeResource] - Cannot find channel type: exec:running

I have the same type of error, no idea what is wrong:
.things
exec:command:slog [ command="/bin/sh -c /etc/openhab2/scripts/solarget.sh", interval=60, timeout=5, autorun=true]

.items
String SLog_Raw "JSON Query" { channel="exec:command:slog:output" }

error

20:31:11.786 [WARN ] [home.core.thing.binding.ThingFactory] - Could not create channel ‘run’ for thing type ‘exec:command:slog’, because channel type ‘exec:running’ could not be found.
20:31:11.789 [WARN ] [.thing.internal.GenericThingProvider] - Could not create channel ‘run’ for thing ‘exec:command:slog’, because channel type ‘exec:running’ could not be found.

Same Problem.

things/exec.things

Thing exec:command:schwippbogen [command="ssh pi@192.168.xxx.xxx -i /etc/ssh/ssh_host_rsa_key pilight-send -p clarus_switch -i A2 -u 32 --%2$s", interval=0, timeout=5, autorun=false]

items/lampen_433mhz.items

String schwippbogen { channel="exec:command:schwippbogen:input" }

sites/home.sitemap

Switch          item=schwippbogen               label="Schwippbogen" mappings=[on="An", off="Aus"]

logs/openhab.log

[WARN ] [ome.core.thing.internal.ThingManager] - Cannot delegate command 'off' for item 'schwippbogen' to handler for channel 'exec:command:schwippbogen:input', because no thing with the UID 'exec:command:schwippbogen' could be found.

Same in my topic:
https://community.openhab.org/t/strange-behaviour-when-using-exec-binding/18052

1 Like

I believe your .things line needs to start with Thing i.e. Thing exec:command:slog …
And can I suggest you try replacing

with
String SLog_Raw “JSON Query [%s]” { channel=“exec:command:slog:output” }
This is the format I found I needed to use.

Thanks!
I did the changes, but no help.
The values recovered via the exec command and JSOn parsing (JS transform) are not updated in my sitemap.
In 1.8 with the exec 1.0 binding all went well

I had a bit of a struggle as well. Just tried things until it worked.
My items line looks like:
String LivingTemp “Living Room Temp [%s °C]” (Temperature,HouseTemps,GF_Living) {channel=“exec:command:tempLivRm:output”}
and the corresponding things line looks like:
Thing exec:command:tempLivRm [command=“bash /home/pi/TempLivingRm.sh”]
and another like:
Thing exec:command:tempGarag [command=“bash /usr/share/openhab/tempGarag.sh”, interval=120, transform=“REGEX((.*?))”]
Have you tried a system restart?

my thing is now
Thing exec:command:slog_Update [ command="bash /etc/openhab2/scripts/sl.sh", transform="JS(getSL100.js)", interval=60, timeout=60, autorun=true]

and item:
Number Slog_Update "Total [%.3f kWh]" (gDashboard) { channel="exec:command:slog_Update:output" }

I really do not see what is wrong. rebooted already several times

Some update…
The exec command and JS transform seems to work, I wonder whether I have discovered a bug?

In paperUI under control, all values are correct. However in my sitemap under basicui or classicui, the values do not update.
I also use a graph and the values same to be correctly persisted and graphed

I agree that there is a bug. I have not been able to convert any “Number” items across from exec 1.9 to 2.0 without making them into “String” type. From my experience if you change Number to String, add the [%s] and retain …:output" } it should work.
All my attempts using “Number” type failed to produce an output - tried Exit, Run, Output. String type was the only option that produced a result.

1 Like

Thanks!
I’ll make the change. However I assume that RRD4J persistence possibility will be gone then?

Update:
Confirmed, making everything string does work. Question remains, can those string values be persisted through RRD4J for having nice graphs?

Hi,

I just tried to do a similar thing, but my script invokes communication with a TPlink switch.
In my system it appears that openhab2 tries to ‘initialize’ the ‘thing’ you create on some intervals and as a side effect it executes this script you have in the thing. I just noticed that as i crafted a thing first, with a script, and as i did not make an ‘item’ yet to hook that script to - i have heard my switch to click-clack, as openhab quickly ran all 3 scripts on all 3 things i made - to turn it on, off, and get status.

Is that an expected behavior from the openhab? is it supposed to ‘initialize’ those things and run scripts in those things by its own initiative?

This is a bug, I prepared a pull request in order to fix it.

Another one I have problems with involves mqtt.
The thing:
Thing exec:command:tempESP2 [mqtt="<localbrokerrb:/DeviceESP12E/Room1/Temperature:state:default"]
and the item:
Number DS18B20ESP “Temperature ESP2 [%s °C]” (Temperature,HouseTemps) {channel=“exec:mqtt:tempESP2:exit”}
I have tried the item as a String also but since the thing is not going online:
exec:command:tempESP2 (Type=Thing, Status=INITIALIZING, Label=Command, Bridge=null)
I figure the problem lies with how I have setup the Thing.
This was the Item under Exec 1.9:
Number DS18B20ESP “Temperature ESP2 [%.2f °C]” (Temperature,HouseTemps) {mqtt="<[localbrokerrb:/DeviceESP12E/Room1/Temperature:state:default]"}
Any thoughts?

@robb01Your Thing definition of tempESP2 is not a valid thing definition of the Exec Binding’s “command” thing. The mqtt="…" string should not be part of that definition at all.

If you would like to link an mqtt feed and an Exec thing, the you have to do that through the Item definition.

so, your item “DS18B20ESP” needs a channel="…" declaration referring to the tempESP2 Thing

Best is to read up on openHAB2 on openhab.org for the configuration part

Under the OH1 version of the exec binding I had :
Number DS18B20ESP “Temperature ESP2 [%.2f °C]” (Temperature,HouseTemps) {mqtt="<[localbrokerrb:/DeviceESP12E/Room1/Temperature:state:default]"}
and the world was a happy place.
Under the Exec 2.0 binding I have tried setting the Item :
String DS18B20ESP “Temperature ESP2 [%d °C]” (Temperature,HouseTemps) {channel=“exec:command:tempESP2:output”}
and the Thing :
Thing exec:command:tempESP2 [command=“bash mqtt<localbrokerrb:/DeviceESP12E/Room1/Temperature:state:default”]
This got the Thing ONLINE but had ExecHandler errors. So I tried :
Thing exec:command:tempESP2 [command=“bash ‘mosquitto_sub -h localhost -t /DeviceESP12E/Room1/Temperature’”] to use a valid bash syntax but I get a duplicate item:
DS18B20ESP (Type=StringItem, State=bash: 'mosquitto_sub: No such file or directory
DS18B20ESP (Type=StringItem, State=0, Label=Temperature ESP2, Category=temperature, Groups=[Temperature, HouseTemps])
The github wiki only refers to OH1 configurations.
I have not found any documentation that clarifies mqtt under Exec 2.0.

Even in a bash script it does not produce a result:
Thing exec:command:tempESP2 [command=“bash /home/pi/TempESP.sh”, autorun=false]
where the script just contains the line mosquitto_sub -h localhost -t /DeviceESP12E/Room1/Temperature.
i know this is not consistent with the mqtt binding definition but thought it worth a try.

Hi,

I am struggling eith a similar issue using the new OH2b5.

I want to switch relays on a NodeMCU with the command:
curl http://192.168.178.49/?REL1=ON … or …OFF

My Thing definition:

Thing exec:command:Node1Rel1th [command="curl http://192.168.178.49/?REL1=%2$s"]

and the Item:

Switch Node1REL1 "REL1 [%s]" (EG_Wohnzimmer) {channel="exec:command:Node1Rel1th:run"}
        	Frame label="NodeMCU 1" {	
        		Switch item=Node1REL1 label="REL1"
....}

but this did not work. I already get the error:

[ERROR] [hab.binding.exec.handler.ExecHandler] - An exception occurred while formatting the command line with the current time and input values : 'Format specifier '%2$s''

but why? I think I did the implementation as described in the Exex-Binding doc ???

Holger.

Hello all,
I have the same issue. I used a String instead Number and it works, but unfortunately with String datatype the Chart Item no more works.
There is a work around for this issue?
thanks
Ivan