Skip to content

Commit 347b3fa

Browse files
jsr223: Describe parameter of SimpleRule.execute(Map inputs) based on trigger
1 parent b199256 commit 347b3fa

File tree

1 file changed

+87
-5
lines changed

1 file changed

+87
-5
lines changed

configuration/jsr223.md

Lines changed: 87 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -538,13 +538,77 @@ The following trigger types are defined by openHAB (custom triggers can also be
538538
All parameters are Strings.
539539
Read the JSR223 language specific documentation for examples of using these `TriggerType` objects.
540540

541+
When a trigger is fired, it produces data, which is passed to the ActionHandler.
542+
Below the `inputs` parameter contains the data from the fired trigger:
543+
544+
:::: tabs
545+
546+
::: tab Groovy
547+
548+
```groovy
549+
import org.openhab.core.config.core.Configuration
550+
import org.openhab.core.automation.module.script.rulesupport.shared.simple.SimpleRule
551+
import org.openhab.core.automation.*
552+
scriptExtension.importPreset("RuleSupport")
553+
554+
automationManager.addRule(new SimpleRule() {
555+
@Override
556+
Object execute(Action module, Map<String, ?> inputs) {
557+
// inputs is ... described below
558+
}
559+
560+
List<Trigger> triggers = [
561+
TriggerBuilder.create().withId("trig1").withTypeUID("core.ItemStateChangeTrigger")
562+
.withConfiguration(new Configuration([itemName: "r"])).build(),
563+
TriggerBuilder.create().withId("cr2").withTypeUID("timer.GenericCronTrigger")
564+
.withConfiguration(new Configuration([cronExpression: "* * * 25 * *"])).build()
565+
]
566+
})
567+
```
568+
569+
:::
570+
571+
::: tab JS&nbsp;Nashorn
572+
573+
```js
574+
se.importPreset("RuleSupport")
575+
se.importPreset("RuleSimple")
576+
577+
automationManager.addRule(new SimpleRule() {
578+
execute: function(module, inputs) {
579+
// inputs is ... described below
580+
},
581+
getTriggers: function() { return [
582+
TriggerBuilder.create().withId("trig1").withTypeUID("core.ItemStateChangeTrigger")
583+
.withConfiguration(new Configuration({itemName: "r"})).build(),
584+
TriggerBuilder.create().withId("cr2").withTypeUID("timer.GenericCronTrigger")
585+
.withConfiguration(new Configuration({cronExpression: "* * * 25 * *"})).build()
586+
] }
587+
})
588+
```
589+
590+
:::
591+
592+
::::
593+
594+
When `trig1` fires, inputs.get("module") is `"trig1"`.
595+
The table below `core.ItemStateChangeTrigger` shows that five keys and values will be inserted into `inputs`.
596+
The values are inserted twice: once with the trigger id prefix followed by dot in the key, once without.
597+
That is, `inputs` will have eleven keys and six values: `inputs.get("module")`, `inputs.get("oldState") == inputs.get("trig1.oldState")`, `inputs.get("newState") == inputs.get("trig1.newState")`, `inputs.get("lastStateUpdate") == inputs.get("trig1.lastStateUpdate")`, `inputs.get("lastStateChange") == inputs.get("trig1.lastStateChange")` and `inputs.get("event") == inputs.get("trig1.event")`.
598+
541599
::: details timer.DateTimeTrigger
542600

543-
| Parameter | Description |
544-
|------------|---------------------------------------------------------------------------|
545-
| `itemName` | The name of the `Item` |
546-
| `timeOnly` | Whether only the time of the item should be compared or the date and time |
547-
| `offset` | The offset in seconds to add to the time of the item |
601+
| Parameter | Description |
602+
|------------|-------------------------------------------------------------------------------------------------|
603+
| `itemName` | The name of the `Item` |
604+
| `timeOnly` | Whether only the time of the item should be compared or the date and time. Default is `false`. |
605+
| `offset` | The offset in seconds to add to the time of the item |
606+
607+
Data provided by the trigger:
608+
609+
| Key | Description |
610+
| ------- | --------------------------------------------------------------------------------------------------------------------------------------- |
611+
| `event` | [`org.openhab.core.automation.events.TimerEvent`](https://www.openhab.org/javadoc/latest/org/openhab/core/automation/events/timerevent) |
548612

549613
:::
550614

@@ -580,6 +644,14 @@ Read the JSR223 language specific documentation for examples of using these `Tri
580644
| `itemName` | The name of the `Item` |
581645
| `state` | The `State` (optional) |
582646

647+
Data provided by the trigger:
648+
649+
| Key | Description |
650+
| ----------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
651+
| `state` | The item [`org.openhab.core.types.State`](https://www.openhab.org/javadoc/latest/org/openhab/core/types/state) |
652+
| `event` | [`org.openhab.core.items.events.ItemStateUpdatedEvent`](https://www.openhab.org/javadoc/latest/org/openhab/core/items/events/itemstateupdatedevent) |
653+
| `lastStateUpdate` | The time of the previous state update [`java.time.ZonedDateTime`](https://docs.oracle.com/en/java/javase/21/docs/api/java.base/java/time/ZonedDateTime.html) - since openHAB 5.0. The value is `null` when the item was just initialized. |
654+
583655
:::
584656

585657
::: details core.ItemStateChangeTrigger
@@ -590,6 +662,16 @@ Read the JSR223 language specific documentation for examples of using these `Tri
590662
| `previousState` | The previous `State` (optional) |
591663
| `state` | The `State` (optional) |
592664

665+
Data provided by the trigger:
666+
667+
| Key | Description |
668+
| ----------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
669+
| `oldState` | The old item [`org.openhab.core.types.State`](https://www.openhab.org/javadoc/latest/org/openhab/core/types/state). The value is `null` when the item was just initialized. |
670+
| `newState` | The new item [`org.openhab.core.types.State`](https://www.openhab.org/javadoc/latest/org/openhab/core/types/state) |
671+
| `lastStateUpdate` | The time of the previous state update [`java.time.ZonedDateTime`](https://docs.oracle.com/en/java/javase/21/docs/api/java.base/java/time/ZonedDateTime.html) - since openHAB 5.0. The value is `null` when the item was just initialized. |
672+
| `lastStateChange` | The time of the previous state change [`java.time.ZonedDateTime`](https://docs.oracle.com/en/java/javase/21/docs/api/java.base/java/time/ZonedDateTime.html) - since openHAB 5.0. The value is `null` when the item was just initialized. |
673+
| `event` | [`org.openhab.core.items.events.ItemStateChangedEvent`](https://www.openhab.org/javadoc/latest/org/openhab/core/items/events/itemstatechangedevent) |
674+
593675
:::
594676

595677
::: details core.GroupCommandTrigger

0 commit comments

Comments
 (0)