Skip to content

Commit 7d65a4d

Browse files
jsr233: Describe parameter of SimpleRule.execute(Map inputs) based on trigger
1 parent dc45e0c commit 7d65a4d

File tree

1 file changed

+50
-5
lines changed

1 file changed

+50
-5
lines changed

configuration/jsr223.md

Lines changed: 50 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -538,13 +538,48 @@ 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+
```groovy
545+
import org.openhab.core.config.core.Configuration
546+
import org.openhab.core.automation.module.script.rulesupport.shared.simple.SimpleRule
547+
import org.openhab.core.automation.*
548+
scriptExtension.importPreset("RuleSupport")
549+
550+
automationManager.addRule(new SimpleRule() {
551+
@Override
552+
Object execute(Action module, Map<String, ?> inputs) {
553+
// inputs is ... described below
554+
}
555+
556+
List<Trigger> triggers = [
557+
TriggerBuilder.create().withId("trig1").withTypeUID("core.ItemStateChangeTrigger")
558+
.withConfiguration(new Configuration([itemName: "r"])).build(),
559+
TriggerBuilder.create().withId("cr2").withTypeUID("timer.GenericCronTrigger")
560+
.withConfiguration(new Configuration([cronExpression: "* * * 25 * *"])).build()
561+
]
562+
})
563+
```
564+
565+
When `trig1` fires, inputs.get("module") is `"trig1"`.
566+
The table below `core.ItemStateChangeTrigger` shows that five keys and values will be inserted into `inputs`.
567+
The values are inserted twice: once with the trigger id prefix followed by dot in the key, once without.
568+
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")`.
569+
541570
::: details timer.DateTimeTrigger
542571

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 |
572+
| Parameter | Description |
573+
|------------|-------------------------------------------------------------------------------------------------|
574+
| `itemName` | The name of the `Item` |
575+
| `timeOnly` | Whether only the time of the item should be compared or the date and time. Default is `false`. |
576+
| `offset` | The offset in seconds to add to the time of the item |
577+
578+
Data provided by the trigger:
579+
580+
| Key | Description |
581+
| ------- | --------------------------------------------------------------------------------------------------------------------------------------- |
582+
| `event` | [`org.openhab.core.automation.events.TimerEvent`](https://www.openhab.org/javadoc/latest/org/openhab/core/automation/events/timerevent) |
548583

549584
:::
550585

@@ -590,6 +625,16 @@ Read the JSR223 language specific documentation for examples of using these `Tri
590625
| `previousState` | The previous `State` (optional) |
591626
| `state` | The `State` (optional) |
592627

628+
Data provided by the trigger:
629+
630+
| Key | Description |
631+
| ----------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------ |
632+
| `oldState` | Old [`org.openhab.core.types.State`](https://www.openhab.org/javadoc/latest/org/openhab/core/types/state) |
633+
| `newState` | The new item [`org.openhab.core.types.State`](https://www.openhab.org/javadoc/latest/org/openhab/core/types/state) |
634+
| `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) |
635+
| `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) |
636+
| `event` | [`org.openhab.core.items.events.ItemStateChangedEvent`](https://www.openhab.org/javadoc/latest/org/openhab/core/items/events/itemstatechangedevent) |
637+
593638
:::
594639

595640
::: details core.GroupCommandTrigger

0 commit comments

Comments
 (0)