Exec as an In-Binding?

1,940 views
Skip to first unread message

Guido Zockoll

unread,
Jan 3, 2013, 12:51:27 PM1/3/13
to ope...@googlegroups.com
Hi,

is it possible to use the exec binding to get numbers into the system? I want to read out the core temperature of my Raspi with this command:

cat /sys/class/thermal/thermal_zone0/temp | awk '{printf "%.1f\n",$1 / 1000.0}'

and would like to see a graph simalar to the graph for the outside temperature.

Regards,

Guido

Kai Kreuzer

unread,
Jan 3, 2013, 3:38:17 PM1/3/13
to ope...@googlegroups.com
Hi Guido,

No unfortunately, this is currently not possible.
As far as I remember, it was quite difficult to implement an os-independent way for reading output from the command line.
At the moment, the exec binding does a "fire&forget", so it does not even know, when the execution finishes.

Any contribution to make this possible is welcome :-)

Regards,
Kai

--
You received this message because you are subscribed to the Google Groups "openhab" group.
To view this discussion on the web visit https://groups.google.com/d/msg/openhab/-/FoRAKv1AFmcJ.
To post to this group, send email to ope...@googlegroups.com.
To unsubscribe from this group, send email to openhab+u...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/openhab?hl=en.

Thomas Eichstädt-Engelen

unread,
Jan 3, 2013, 4:33:51 PM1/3/13
to ope...@googlegroups.com
Guido,

fyi: there is somebody in the german user forum who starts developing an exec-in-binding (see http://knx-user-forum.de/openhab/24300-anfaenger-anbindung-von-einem-script-als-datasupplier.html).

Regards,

Thomas E.-E.

Kai Kreuzer

unread,
Jan 3, 2013, 4:39:57 PM1/3/13
to ope...@googlegroups.com
I am not really sure that he will implement an "exec-in" binding. I thought he is rather trying to implement a binding specific to his problem (retrieving and parsing data from his solar system).

Regards,
Kai

Thomas Eichstädt-Engelen

unread,
Jan 3, 2013, 4:43:14 PM1/3/13
to ope...@googlegroups.com
argh ... you are right! I mixed things up ... sorry for this confusion!

Pali

unread,
Apr 3, 2013, 11:07:01 AM4/3/13
to ope...@googlegroups.com, k...@openhab.org
Exec as in binding is also on my todo list. Apache commons exec should solve the OS dependent problems.

-Pali

Pali

unread,
Apr 5, 2013, 6:38:39 PM4/5/13
to ope...@googlegroups.com, k...@openhab.org
Just committed in binding support for exec binding to my clone. Out binding use still old execution code to minimise the risk to broke it.

Binding supports two different kind of configurations. 

Old format:
Number execLegacyOutFormat { exec="1:open /path/to/my/mp3/gong.mp3, 2:open /path/to/my/mp3/greeting.mp3, *:open /path/to/my/mp3/generic.mp3" }

New format:
Number execNewOutFormat { exec=">[1:open /path/to/my/mp3/gong.mp3] >[2:open /path/to/my/mp3/greeting.mp3] >[*:open /path/to/my/mp3/generic.mp3]" }
Number execIn15minLoadAverage { exec="<[/bin/sh@@-c@@uptime | awk '{ print $10 }':60000:REGEX((.*?))]" }

Br,
Pali

Thomas Eichstädt-Engelen

unread,
Apr 6, 2013, 3:00:06 AM4/6/13
to ope...@googlegroups.com
thanks a lot!

Will have a look into it ASAP.

Regards,

Thomas

- sent from a mobile device -
To unsubscribe from this group and stop receiving emails from it, send an email to openhab+u...@googlegroups.com.

To post to this group, send email to ope...@googlegroups.com.

Pali

unread,
Apr 6, 2013, 7:37:31 AM4/6/13
to ope...@googlegroups.com
I like to make small improvement to out binding as well. I like to introduce two special attributes to command line; %item and %value.

Number exectest { exec=">[*:/bin/sh@@-c@@dosomething.sh %item %value]" }

Exec binding will replace '%item' to item name and '%value' to command value.

So...

'openhab send exectest 100' will execute command line '/bin/sh -c dosomething.sh exectest 100

What do you thing? Do you see any side effect?

-Pali

Pali

unread,
Apr 8, 2013, 11:35:09 AM4/8/13
to ope...@googlegroups.com
It seems that I've gone blind. There was "dynamic URL enhancement" feature already implemented on http binding, so I added similar behaviour on exec binding as well.

-Pali

Kai Kreuzer

unread,
Apr 9, 2013, 3:39:49 PM4/9/13
to ope...@googlegroups.com
Is there any changeset to pull for us?

Regards,
Kai

Pali

unread,
Apr 10, 2013, 1:36:43 AM4/10/13
to ope...@googlegroups.com
From my point of view changes are complite and they can be found from my close.

Also temprorary solution for issue 42 (http "cache") could be pulled to main repo if you accepted that.

Regards,
Pali

Thomas Eichstädt-Engelen

unread,
Apr 10, 2013, 4:09:32 PM4/10/13
to ope...@googlegroups.com
Hi Pali,

From my point of view changes are complite and they can be found from my close. 

i am about to merge your enhancement to the main repo. Could you meanwhile please add some Unit-Tests which proofs the parsing of the new binding format?

Also temprorary solution for issue 42 (http "cache") could be pulled to main repo if you accepted that.

I am afraid the "http cache" enhancement won't make it into 1.2, sorry!

Thanks for your patience,

Thomas E.-E.

Tomaz

unread,
Apr 13, 2013, 1:54:48 PM4/13/13
to ope...@googlegroups.com, k...@openhab.org
I am getting an error ... Looks like Number item is not supported:

19:53:08.838 INFO  runtime.busevents[:46] - Health_GF_Shutter_Test state updated to 1
19:53:08.838 DEBUG o.o.c.i.items.ItemUpdater[:93] - Received update of a not accepted type (StringType) for item Health_GF_Shutter_Test

This is my configuration:

Number Health_GF_Shutter_Test      "GF [%d]"    <health> (Network, SysHealth) { exec="<[ping -c 1 192.168.1.201:5000:REGEX(.*transmitted, (.*?) received.*)]" }

Should I change anything? If I create a String item type, it works.

Pauli Anttila

unread,
Apr 13, 2013, 2:42:46 PM4/13/13
to ope...@googlegroups.com
Hi Tomaz,

I tested your item configuration and at least for me, regex rule seems to return '1 packets' which is not accepted by number item. 

21:36:31.546 DEBUG o.o.b.e.internal.ExecBinding[:135] - item 'Health_GF_Shutter_Test' is about to be refreshed now

21:36:31.547 INFO  o.o.b.e.internal.ExecBinding[:381] - executed commandLine 'ping -c 1 127.0.0.1'

21:36:31.599 INFO  o.o.b.e.internal.ExecBinding[:396] - exit code '0', result 'PING 127.0.0.1 (127.0.0.1): 56 data bytes

64 bytes from 127.0.0.1: icmp_seq=0 ttl=64 time=0.100 ms


--- 127.0.0.1 ping statistics ---

1 packets transmitted, 1 packets received, 0.0% packet loss

round-trip min/avg/max/stddev = 0.100/0.100/0.100/0.000 ms

'

21:36:31.600 DEBUG o.o.c.t.i.s.RegExTransformationService[:62] - about to transform 'PING 127.0.0.1 (127.0.0.1): 56 data bytes

64 bytes from 127.0.0.1: icmp_seq=0 ttl=64 time=0.100 ms


--- 127.0.0.1 ping statistics ---

1 packets transmitted, 1 packets received, 0.0% packet loss

round-trip min/avg/max/stddev = 0.100/0.100/0.100/0.000 ms

' by the function '.*transmitted, (.*?) received.*'

21:36:31.600 DEBUG o.o.b.e.internal.ExecBinding[:170] - transformed response is '1 packets'

21:36:31.601 INFO  runtime.busevents[:46] - Health_GF_Shutter_Test state updated to 1 packets

21:36:31.602 DEBUG o.o.c.i.items.ItemUpdater[:93] - Received update of a not accepted type (StringType) for item Health_GF_Shutter_Test

 
But on your debug, I don't see 'packets' suffix, which is weird.

Br,
Pali


2013/4/13 Tomaz <tomazh...@gmail.com>
To unsubscribe from this group and stop receiving emails from it, send an email to openhab+u...@googlegroups.com.
To post to this group, send email to ope...@googlegroups.com.

Tomaz

unread,
Apr 13, 2013, 2:59:09 PM4/13/13
to ope...@googlegroups.com
Forgot to mention, my OS is Linux, that would probably be the reason for the difference.

the string I get for ping is: 1 packets transmitted, 1 received

Tomaz

unread,
Apr 13, 2013, 5:15:10 PM4/13/13
to ope...@googlegroups.com
Seems to be a more general issue, since some of the bindings (http with xslt transformation) experience the same issue. This is the whole log:

23:05:17.752 DEBUG o.o.c.t.i.s.RegExTransformationService[:62] - about to transform 'PING 192.168.1.201 (192.168.1.201) 56(84) bytes of data.
64 bytes from 192.168.1.201: icmp_req=1 ttl=100 time=57.7 ms

--- 192.168.1.201 ping statistics ---
1 packets transmitted, 1 received, 0% packet loss, time 0ms
rtt min/avg/max/mdev = 57.797/57.797/57.797/0.000 ms' by the function '.*transmitted, (.*?) received.*'
23:05:17.752 DEBUG o.o.b.e.internal.ExecBinding[:171] - transformed response is '1'
23:05:17.753 DEBUG o.o.c.i.items.ItemUpdater[:93] - Received update of a not accepted type (StringType) for item Health_GF_Shutter_Test
23:05:17.753 INFO  runtime.busevents[:46] - Health_GF_Shutter_Test state updated to 1

But the item Health_GF_Shutter_Test value is still Uninitialized!

Pali

unread,
Apr 13, 2013, 5:20:07 PM4/13/13
to ope...@googlegroups.com
There is a bug in the code. 

private State createState(Class<? extends Item> itemType, String transformedResponse) {

try {

if (itemType.isAssignableFrom(DecimalType.class)) {

return DecimalType.valueOf(transformedResponse);

else if (itemType.isAssignableFrom(OpenClosedType.class)) {

return OpenClosedType.valueOf(transformedResponse);

else if (itemType.isAssignableFrom(OnOffType.class)) {

return OnOffType.valueOf(transformedResponse);

else {

return StringType.valueOf(transformedResponse);

}

catch (Exception e) {

logger.debug("Couldn't create state of type '{}' for value '{}'", itemType, transformedResponse);

return StringType.valueOf(transformedResponse);

}

}


should be 

private State createState(Class<? extends Item> itemType, String transformedResponse) {
                try {
                        if (itemType.isAssignableFrom(NumberItem.class)) {
                                return DecimalType.valueOf(transformedResponse);
                        } else if (itemType.isAssignableFrom(ContactItem.class)) {
                                return OpenClosedType.valueOf(transformedResponse);
                        } else if (itemType.isAssignableFrom(SwitchItem.class)) {
                                return OnOffType.valueOf(transformedResponse);
                        } else {
                                return StringType.valueOf(transformedResponse);
                        }
                } catch (Exception e) {
                        logger.debug("Couldn't create state of type '{}' for value '{}'", itemType, transformedResponse);
                        return StringType.valueOf(transformedResponse);
                }
        }

createState code was copied from http binding. Bug was recently fixed on http binding :(

Br,
Pali 

Kai Kreuzer

unread,
Apr 13, 2013, 5:22:36 PM4/13/13
to ope...@googlegroups.com
Hi Pali,

createState code was copied from http binding. Bug was recently fixed on http binding :(

Good point, I only reviewed the http binding and fixed it in there. This is a good example how code duplication causes problems.
For release 1.3, we actually plan to move this to an abstract class, so that this logic is available to all bindings.
Will fix it for the exec binding right now, so it'll still go into 1.2.

Regards,
Kai

Pali

unread,
Apr 13, 2013, 5:39:44 PM4/13/13
to ope...@googlegroups.com
I fixed this createState bug on my clone, but it's probably easier for you to fixed it directly than pull from clone.

-Pali

Kai Kreuzer

unread,
Apr 13, 2013, 5:41:19 PM4/13/13
to ope...@googlegroups.com

Pali

unread,
Apr 13, 2013, 6:02:22 PM4/13/13
to ope...@googlegroups.com
Great. To make you life easier and prevent last minute changes on future, you probably should specify code freeze date e.g. one week before release and do just bug fixing during that week. 

Regards,
Pali

Tomaz

unread,
Apr 14, 2013, 2:04:59 AM4/14/13
to ope...@googlegroups.com
Hi both, thanks for support, I can confirm, the exec binding now behaves appropriatelly. However, I still receive errors with the http binding:

07:56:49.277 DEBUG o.o.b.h.internal.HttpBinding[:156] - item 'Shutter_GF_Kitchen' is about to be refreshed now
07:56:49.395 DEBUG o.o.c.t.i.s.XsltTransformationService[:94] - about to transform '<?xml version="1.0"?>
<Channel number="1">
  <BlindsChannel>
    <LastCommand status="OK" name="up"/> 
    <PinDefinitions upButton="20" downButton="18" upCommand="21" downCommand="19" />
    <CalibrationStatus maxOpenStatus="CAL" maxOpenPosition="5361" partOpenStatus="CAL" partOpenPosition="85" />
    <Status currentPosition="99" currentPosition100th="5276" calibratingPosition="300" targetPosition="5276" state="STOPPED">
      <UpButton state="OFF" duration="0" />
      <DownButton state="OFF" duration="0" />
    </Status>
  </BlindsChannel>
</Channel>' by the function 'javax.xml.transform.stream.StreamSource@61bcab75'
07:56:49.407 DEBUG o.o.c.t.i.s.XsltTransformationService[:109] - transformation resulted in '99'
07:56:49.408 DEBUG o.o.b.h.internal.HttpBinding[:188] - transformed response is '99'
07:56:49.408 DEBUG o.o.c.i.items.ItemUpdater[:93] - Received update of a not accepted type (StringType) for item Shutter_GF_Kitchen
07:56:49.409 INFO  runtime.busevents[:46] - Shutter_GF_Kitchen state updated to 99

Since another item works ok, I am wondering if this could be related to the fact, that the file is not UTF-8?

Tomaz

unread,
Apr 14, 2013, 5:13:30 AM4/14/13
to ope...@googlegroups.com
Found the cause. Probably the http binding fix broke the Rolershutter item operation
I created a bug report with details: http://code.google.com/p/openhab/issues/detail?id=238

Tomaz

unread,
Apr 15, 2013, 3:47:44 PM4/15/13
to ope...@googlegroups.com
Pali,

this is great! I even solved the networkhealth binding "ping issue".

Switch Health_GF_Shutter_Board  "GF Shutter Board"            <health> (Network, SysHealth) { exec="<[/bin/sh@@-c@@ping -c 1 192.168.1.201 | grep \"packets transmitted\" | sed -e \"s/.*1 received.*/ON/\" -e \"s/.*0 received.*/OFF/\":30000:REGEX((.*))]" }

Works only on Linux, though.

Thomas Eichstädt-Engelen

unread,
Apr 16, 2013, 5:02:03 AM4/16/13
to ope...@googlegroups.com
Hi Pali,

may i ask you to enhance the http://code.google.com/p/openhab/wiki/ExecBinding Wikipage with the binding configuration formats?

Thanks in advance,

Thomas E.-E.


Begin forwarded message:

Kai Kreuzer

unread,
Apr 16, 2013, 4:51:49 PM4/16/13
to ope...@googlegroups.com
Cool, so could we close https://code.google.com/p/openhab/issues/detail?id=134 and provide your exec configuration as the suggested solution to the problem (at least for Linux/Mac)?

Regards,
Kai

Tomaz

unread,
Apr 16, 2013, 5:01:17 PM4/16/13
to ope...@googlegroups.com
Hi Kai,

I agree that would be the best option. And may I suggest to put up a part of the wiki for short recipes like this? Besides "the ping", I have just added monitoring CPU and SYSTEM temperature, which was quite easy and could interest someone else.

Regards,
Tomaz

Kai Kreuzer

unread,
Apr 17, 2013, 5:16:50 PM4/17/13
to ope...@googlegroups.com
Hi Tomaz,

Ok, thanks, I have closed the issue. What place would you suggest to add such tips and how should it be structured so that it is easy to find?

Regards,
Kai

Tomaz

unread,
Apr 18, 2013, 5:19:47 AM4/18/13
to ope...@googlegroups.com
I would say people would be coming to Wiki -> Installation when configuring OpenHAB.

I would just add an additional node under that with Tips & Trick.

Regards,
Tomaz

Kai Kreuzer

unread,
Apr 26, 2013, 5:05:05 PM4/26/13
to ope...@googlegroups.com
I have added this tip to https://code.google.com/p/openhab-samples/wiki/Tricks

Regards,
Kai

Tomaz

unread,
Apr 27, 2013, 4:37:30 AM4/27/13
to ope...@googlegroups.com
Cool! I'm glad I could contribute. 

Could you add me to the contributors? I'll be glad to add anything new when I figure out something meaningful?

Kai Kreuzer

unread,
Apr 27, 2013, 5:13:14 AM4/27/13
to ope...@googlegroups.com
Could you add me to the contributors?

Certainly, you are added now!
Message has been deleted

Björn

unread,
Jul 21, 2013, 5:30:14 AM7/21/13
to ope...@googlegroups.com
I have tried the below described binding in xxx.items but nothing seams to happen.

If i run the following line in exec.persist I get some response, but with errors.
Line in exec.persist inside the Items list:
 PingedItem -> "/bin/ping -c 1 \"192.168.1.65\"| grep \"packets transmitted\"| /bin/sed -e \"s/.*1 received.*/ON/\" -e \"s/.*0 received.*/OFF/\" " : strategy = everyTenSec

Error in openhab.log when running in debug mode:
11:29:10.004 DEBUG o.o.p.e.internal.ExecService[:71]- Executing command [/bin/ping -c 1 "192.168.1.65"| grep "packets transmitted"| /bin/sed -e "s/.*1 received.*/ON/" -e "s/.*0 received.*/OFF/" ]
11:29:10.017 DEBUG o.o.p.e.internal.ExecService[:76]- Stored item 'PingedItem' as 'Uninitialized' using Exec at Sun Jul 21 11:29:10 CEST 2013.
11:29:10.034 DEBUG o.o.p.e.internal.ExecService[:98]- Error from exec command is: /bin/ping: invalid option -- 'e'Usage: ping [-LRUbdfnqrvVaAD] [-c count] [-i interval] [-w deadline]            [-p pattern] [-s packetsize] [-t ttl] [-I interface]            [-M pmtudisc-hint] [-m mark] [-S sndbuf]            [-T tstamp-options] [-Q tos] [hop1 ...] destination
11:29:10.042 TRACE o.o.c.p.i.PersistItemsJob[:76]- Storing item 'PingedItem' with persistence service 'exec' took 38ms
^
Any Idéas what is wrong?

I run Openhab 1.2.0 with exec version 1.2.0 on a Raspberry Pi

Regards Björn

Kjetil Asdal

unread,
Mar 3, 2015, 6:30:09 AM3/3/15
to ope...@googlegroups.com
Hi, 

I realize I am a bit late into this thread, but i just stumbled upon it while searching for examples on how to use the Exec binding. I am setting up a "network health"-monitor in my openHAB system using the ping command below. It works very well, however, I have one very silly question: What are those double at-symbols (@@) in the command line?

I have been searching the web for any references to using this as some kind of escaping or the like, but have not been able to find any information. 

Anyone?

BR
Kjetil

Tomaz

unread,
Mar 3, 2015, 6:52:00 AM3/3/15
to ope...@googlegroups.com
Hi Kjetil,

It's not a Linux feature, which is why you were unable to find your reply:


private static final String CMD_LINE_DELIMITER = "@@";

BR,
Tomaz

Kjetil Asdal

unread,
Mar 3, 2015, 9:19:40 AM3/3/15
to ope...@googlegroups.com
Ah! Thanks for saving my day, Tomaz! 
I just hate those small "quirks" that I don't understand, :-)
/Kjetil

Pauli Anttila

unread,
Mar 3, 2015, 10:55:34 AM3/3/15
to ope...@googlegroups.com
@@ special meaning is also described on the exec binding wiki page.

-Pali


--
You received this message because you are subscribed to the Google Groups "openhab" group.
To unsubscribe from this group and stop receiving emails from it, send an email to openhab+u...@googlegroups.com.
To post to this group, send email to ope...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages