Skip to content

Commit b9e7248

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

File tree

1 file changed

+46
-5
lines changed

1 file changed

+46
-5
lines changed

configuration/jsr223.md

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

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

549581
:::
550582

@@ -590,6 +622,15 @@ Read the JSR223 language specific documentation for examples of using these `Tri
590622
| `previousState` | The previous `State` (optional) |
591623
| `state` | The `State` (optional) |
592624

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

595636
::: details core.GroupCommandTrigger

0 commit comments

Comments
 (0)