Updated external 2.5.x content (Jenkins build 456)
parent
3f0f39497c
commit
4712a4e228
|
@ -42,12 +42,12 @@ The "command" Thing requires the command to execute on the shell.
|
|||
Optionally one can specify:
|
||||
|
||||
|
||||
- `transform` - A [transformation](https://www.openhab.org/docs/configuration/transformations.html) to apply on the execution result,
|
||||
- `interval` - An interval, in seconds, the command will be repeatedly executed. Default is 60 seconds, set to 0 to avoid repetition.
|
||||
- `transform` - A [transformation](https://www.openhab.org/docs/configuration/transformations.html) to apply on the execution result string.
|
||||
- `interval` - An interval, in seconds, the command will be repeatedly executed. Default is 60 seconds, set to 0 to avoid automatic repetition.
|
||||
- `timeout` - A time-out, in seconds, the execution of the command will time out, and lastly,
|
||||
- `autorun` - A boolean parameter to make the command execute immediately every time the input channel is sent a command.
|
||||
- `autorun` - A boolean parameter to make the command execute immediately every time the input channel is sent a different openHAB command. If choosing autorun, you may wish to also set `interval=0`. Note that sending the same command a second time will not trigger execution.
|
||||
|
||||
For each command a separate Thing has to be defined.
|
||||
For each shell command, a separate Thing has to be defined.
|
||||
|
||||
```java
|
||||
Thing exec:command:uniquename [command="/command/to/execute here", interval=15, timeout=5, autorun=false]
|
||||
|
@ -60,7 +60,7 @@ The following parameters are automatically added:
|
|||
- the current date (as java.util.Date, example: `%1$tY-%1$tm-%1$td`)
|
||||
- the current (or last) command to the input channel (see below, example: `%2$s`)
|
||||
|
||||
note - if you trigger execution using autorun or the run channel, the %2 substitution will use the most recent command sent to the input channel.
|
||||
note - if you trigger execution using interval or the run channel, the `%2` substitution will use the most recent command (if there has been one) sent to the input channel. The state of the Item linked to input channel is ignored.
|
||||
|
||||
## Channels
|
||||
|
||||
|
@ -101,14 +101,14 @@ Following is an example how to set up an exec command thing, pass it a parameter
|
|||
|
||||
```java
|
||||
// "%2$s" will be replace by the input channel command, this makes it possible to use one command line with different arguments.
|
||||
// e.g: "ls" as <YOUR COMMAND> and "-a" or "-l" as additional argument set to the input channel in the rule.
|
||||
// e.g: "ls" as <YOUR COMMAND> and "-a" or "-l" as additional argument sent to the input channel in the rule.
|
||||
Thing exec:command:yourcommand [ command="<YOUR COMMAND> %2$s", interval=0, autorun=false ]
|
||||
```
|
||||
|
||||
**demo.items**
|
||||
|
||||
```java
|
||||
Switch YourTrigger
|
||||
Switch YourTrigger "External trigger [%s]"
|
||||
Number YourNumber "Your Number [%.1f °C]"
|
||||
|
||||
// state of the execution, is running or finished
|
||||
|
@ -135,7 +135,7 @@ sitemap demo label="Your Value"
|
|||
**demo.rules**
|
||||
|
||||
```java
|
||||
rule "begin your execution"
|
||||
rule "Set up your parameters"
|
||||
when
|
||||
Item YourTrigger changed
|
||||
then
|
||||
|
@ -143,23 +143,44 @@ then
|
|||
if(YourTrigger.state == ON){
|
||||
yourcommand_Args.sendCommand("Additional Argument to command line for ON")
|
||||
}else{
|
||||
yourcommand_Args.sendCommand("Additional Argument to command line for OFF")
|
||||
yourcommand_Args.sendCommand("Different Argument to command line for OFF")
|
||||
}
|
||||
|
||||
// Trigger execution (if autorun false)
|
||||
yourcommand_Run.sendCommand(ON)
|
||||
// the Run indicator state will go ON shortly, and return OFF when script finished
|
||||
// Caution : openHAB bus is asynchronous
|
||||
// we must let the command work before triggering execution (if autorun false)
|
||||
end
|
||||
|
||||
rule "begin your execution"
|
||||
when
|
||||
Item yourcommand_Args received command
|
||||
then
|
||||
// Separately triggering RUN allows subsequent executions with unchanged parameter %2
|
||||
// which autorun does not.
|
||||
if (yourcommand_Run.state != ON) {
|
||||
yourcommand_Run.sendCommand(ON)
|
||||
// the Run indicator state will go ON shortly, and return OFF when script finished
|
||||
}else{
|
||||
logInfo("Your command exec", "Script already in use, skipping execution.")
|
||||
}
|
||||
end
|
||||
|
||||
rule "process your results"
|
||||
rule "script complete"
|
||||
when
|
||||
Item yourcommand_Run changed from ON to OFF
|
||||
then
|
||||
// Logging of ending
|
||||
logInfo("Your command exec", "Script has completed.")
|
||||
// Caution : openHAB bus is asynchronous
|
||||
// there is no guarantee the output Item will get updated before the run channel triggers rules
|
||||
end
|
||||
|
||||
rule "process your results"
|
||||
when
|
||||
Item yourcommand_Out received update
|
||||
then
|
||||
// Logging of raw command line result
|
||||
logInfo("Your command exec", "Result:" + yourcommand_Out.state )
|
||||
logInfo("Your command exec", "Raw result:" + yourcommand_Out.state )
|
||||
// If the returned string is just a number it can be parsed
|
||||
// If not a regex or another transformation can be used
|
||||
// If not, a regex or another transformation could be used
|
||||
YourNumber.postUpdate(Integer::parseInt(yourcommand_Out.state.toString) as Number)
|
||||
end
|
||||
|
||||
|
|
|
@ -47,6 +47,7 @@ The *pjLinkDevice* thing type has the following parameters:
|
|||
| refreshPower | enables polling of the power status. *Optional, the default value is false* |
|
||||
| refreshMute | enables polling of the mute status. *Optional, the default value is false* |
|
||||
| refreshInputChannel | enables polling of the selected input channel. *Optional, the default value is false* |
|
||||
| refreshLampState | enables polling of the lamp usage hours and activity. *Optional, the default value is false* |
|
||||
| autoReconnectInterval | seconds between connection retries when connection to the PJLink device has been lost, 0 means never retry, minimum 30s *Optional, the default value is 60* |
|
||||
|
||||
|
||||
|
@ -58,6 +59,8 @@ The *pjLinkDevice* thing type has the following parameters:
|
|||
| input | Switches the input channel of the device |
|
||||
| audioMute | Mutes the device audio |
|
||||
| videoMute | Mutes the device video |
|
||||
| lamp1Hours | The hours lamp 1 has been in use |
|
||||
| lamp1Active | Shows if lamp 1 is in use |
|
||||
|
||||
## Full Example
|
||||
|
||||
|
@ -74,6 +77,8 @@ Switch Projector_Power "Projector Power" { channel="pjLinkDevice:pjLink
|
|||
String Projector_Input "Projector Input" { channel="pjLinkDevice:pjLinkDevice:MyProjector:input" }
|
||||
Switch Projector_AudioMute "Projector Audio Mute" { channel="pjLinkDevice:pjLinkDevice:MyProjector:audioMute" }
|
||||
Switch Projector_VideoMute "Projector Video Mute" { channel="pjLinkDevice:pjLinkDevice:MyProjector:videoMute" }
|
||||
Number Projector_Lamp1Hours "Projector lamp 1 used hours" { channel="pjLinkDevice:pjLinkDevice:MyProjector:lamp1Hours" }
|
||||
Switch Projector_Lamp1Active "Projector lamp 1 active" { channel="pjLinkDevice:pjLinkDevice:MyProjector:lamp1Active" }
|
||||
```
|
||||
|
||||
sample.sitemap:
|
||||
|
@ -85,6 +90,45 @@ sitemap sample label="Main Menu" {
|
|||
Selection item=Projector_Input
|
||||
Switch item=Projector_AudioMute
|
||||
Switch item=Projector_VideoMute
|
||||
Switch item=Projector_Lamp1Active
|
||||
Text item=Projector_Lamp1Hours
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### Multiple lamps
|
||||
|
||||
Most of the time, there's just one lamp. In case a projector has more than one lamp, additional channels for those lamps can be configured.
|
||||
|
||||
sample-lamp-2.things:
|
||||
|
||||
```
|
||||
pjLinkDevice:pjLinkDevice:MyProjector [ ipAddress="192.168.178.10" ]
|
||||
{
|
||||
Channels:
|
||||
Type lampHours : lamp2Hours "Lamp 2 Hours" [
|
||||
lampNumber=2
|
||||
]
|
||||
Type lampActive : lamp2Active "Lamp 2 Active" [
|
||||
lampNumber=2
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
sample-lamp-2.items:
|
||||
|
||||
```
|
||||
Number Projector_Lamp2Hours "Projector lamp 2 used hours" { channel="pjLinkDevice:pjLinkDevice:MyProjector:lamp2Hours" }
|
||||
Switch Projector_Lamp2Active "Projector lamp 2 active" { channel="pjLinkDevice:pjLinkDevice:MyProjector:lamp2Active" }
|
||||
```
|
||||
|
||||
sample-lamp-2.sitemap:
|
||||
|
||||
```
|
||||
sitemap sample label="Main Menu" {
|
||||
Frame {
|
||||
Switch item=Projector_Lamp2Active
|
||||
Text item=Projector_Lamp2Hours
|
||||
}
|
||||
}
|
||||
```
|
||||
|
|
|
@ -33,6 +33,21 @@ transform/getValue.js:
|
|||
})(input)
|
||||
```
|
||||
|
||||
## Test JavaScript
|
||||
You can use online JavaScript testers to validate your script.
|
||||
E.g. https://www.webtoolkitonline.com/javascript-tester.html
|
||||
|
||||
`Input` variable need to be replaced by the test string, e.g. earlier test string `foo bar baz`
|
||||
|
||||
```
|
||||
(function(i) {
|
||||
var array = i.split(" ");
|
||||
return array[array.length - 1].length;
|
||||
})("foo bar baz")
|
||||
```
|
||||
|
||||
When you press execute button, tester will show the result returned by the script or error if script contains any.
|
||||
|
||||
## Usage as a Profile
|
||||
|
||||
The functionality of this `TransformationService` can be used in a `Profile` on an `ItemChannelLink` too.
|
||||
|
|
Loading…
Reference in New Issue