openhab-docs/_addons_bindings/exec1
Thomas Dietrich 826ef4abb4 Distinguish collections, improve update process (#514)
* Rename collection folders

Signed-off-by: Thomas Dietrich <Thomas.Dietrich@tu-ilmenau.de>

* Change all occurences of addons and repos

Signed-off-by: Thomas Dietrich <Thomas.Dietrich@tu-ilmenau.de>

* Add further corrections

Signed-off-by: Thomas Dietrich <Thomas.Dietrich@tu-ilmenau.de>

* Remove temporary directories after processing

Signed-off-by: Thomas Dietrich <Thomas.Dietrich@tu-ilmenau.de>

* Reduce addons menus, show current uncond.

Signed-off-by: Thomas Dietrich <Thomas.Dietrich@tu-ilmenau.de>

* Fix typo

Signed-off-by: Thomas Dietrich <Thomas.Dietrich@tu-ilmenau.de>

* Remove redundant addons from permalinks

Signed-off-by: Thomas Dietrich <Thomas.Dietrich@tu-ilmenau.de>

* Sort UI menu entries correctly

Signed-off-by: Thomas Dietrich <Thomas.Dietrich@tu-ilmenau.de>

* Split maven command

Signed-off-by: Thomas Dietrich <Thomas.Dietrich@tu-ilmenau.de>
2017-09-22 21:05:09 +02:00
..
readme.md Distinguish collections, improve update process (#514) 2017-09-22 21:05:09 +02:00

readme.md

id label title type description source since install
exec Exec Exec - Bindings binding Execute commands as you would enter on the command line, returning the output (possibly transformed) as the bound item's state. Also, execute command lines in response to commands sent to bound items. https://github.com/openhab/openhab1-addons/blob/master/bundles/binding/org.openhab.binding.exec/README.md 1x legacy

{% include base.html %}

Exec Binding

Execute commands as you would enter on the command line, returning the output (possibly transformed) as the bound item's state. Also, execute command lines in response to commands sent to bound items.

See examples below.

Considerations

  • The user under which you are running openHAB should have the necessary permissions in order to execute your command lines.
  • When using the ssh command, you should use private key authorization, since the password cannot be read from the command line.
  • There is also a binding specifically for openHAB 2 here.

Binding Configuration

This binding does not have a configuration.

Item Configuration

Update item states

When updating the states of items based on executing a command line (an "in" binding):

exec="<[<commandLine to execute>:<refreshintervalinmilliseconds>:(<transformationrule>)]"

where:

  • <commandLine to execute> is the command line to execute. See Formatting and Splitting sections below.
  • <refreshintervalinmilliseconds> is the frequency at which to repeatedly execute the command line.
  • <transformationrule> is optional, and can be used to transform the string returned from the command before updating the state of the item.

Example item:

Number Temperature "Ext. Temp. [%.1f°C]" { exec="<[curl -s http://weather.yahooapis.com/forecastrss?w=566473&u=c:60000:XSLT(demo_yahoo_weather.xsl)]" }

Sending commands

When executing a command line in response to the item receiving a command (an "out" binding):

exec=">[<openHAB-command>:<commandLine to execute>] (>[<openHAB-command>:<commandLine to execute>]) (>[...])"

where:

  • <openHAB-command> is the openHAB command that will trigger the execution of the command line. Can be ON, OFF, INCREASE, etc., or the special wildcard command '*' which is called in cases where no direct match could be found
  • <commandLine to execute> is the command to execute. See Formatting and Splitting sections below.

Example item:

Number SoundEffect "Play Sound [%d]" { exec=">[1:open /mp3/gong.mp3] >[2:open /mp3/greeting.mp3] >[*:open /mp3/generic.mp3]" }

Old Format

Deprecated format (do not use; retained for backward compatibility only):

exec="<openHAB-command>:<commandLine to execute>[,<openHAB-command>:<commandLine to execute>][,...]"

Formatting

You can substitute formatted values into the command using the syntax described here.

  1. the current date, like %1$tY-%1$tm-%1$td.
  2. the current command or state, like %2$s (out bindings only)
  3. the current item name (like %3$s).

Splitting

Sometimes the <commandLine to execute> isn't executed properly. In that case, another exec-method can be used. To accomplish this please use the special delimiter @@ to split command line parameters.

Examples

Turn a Computer ON and OFF

On possible useage is to turn a computer on or off. The Wake-on-LAN binding could be bound to a Switch item, so that when the switch receives an ON command, A Wake-on-LAN message is sent to wake up the computer. When the switch item receives an OFF command, it will call the Exec binding to connect via ssh and issue the shutdown command. Here is the example item:

Switch MyLinuxPC "My Linux PC" { wol="192.168.1.255#00-1f-d0-93-f8-b7", exec=">[OFF:ssh user@host shutdown -p now]" }

KNX Bus to Exec Command

The example below combines three bindings to incorporate the following behavior: query the current state of the NAS with the given IP address. When receiving an OFF command over KNX or the user switches to OFF manually then send the given command line via the exec binding.

Switch Network_NAS	"NAS"	(Network, Status)	{ nh="192.168.1.100", knx="<2/0/0", exec=">[OFF:ssh user@host shutdown -p now]" }

More Examples

exec=">[ON:/bin/sh@@-c@@echo on >> /tmp/sw_log] >[OFF:/bin/sh@@-c@@echo off >> /tmp/sw_log]"
exec=">[1:open /mp3/gong.mp3] >[2:open /mp3/greeting.mp3] >[*:open /mp3/generic.mp3]"
exec="<[curl -s http://weather.yahooapis.com/forecastrss?w=566473&u=c:60000:XSLT(demo_yahoo_weather.xsl)]"
exec="<[/bin/sh@@-c@@uptime | awk '{ print $10 }':60000:REGEX((.*?))]"
exec="<[execute.bat %1$tY-%1$tm-%1$td %2$s %3$s:60000:REGEX((.*?))]"
exec="<[php ./configurations/scripts/script.php:60000:REGEX((.*?))]"
exec="<[/bin/sh@@-c@@uptime | awk '{ print $10 }':]"

// deprecated format
exec="OFF:ssh user@host shutdown -p now"
exec="OFF:some command, ON:'some other\, more \'complex\' \\command\\ to execute', *:fallback command"
exec="1:open /path/to/my/mp3/gong.mp3, 2:open /path/to/my/mp3/greeting.mp3, *:open /path/to/my/mp3/generic.mp3"