You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
See [openhab-js](https://openhab.github.io/openhab-js) for a complete list of functionality.
73
73
74
-
### UI Event Object
74
+
### Event Object
75
+
76
+
When a rule is triggered, the script is provided the event instance that triggered it.
77
+
The specific data depends on the event type.
78
+
The `event` object provides some information about that trigger.
75
79
76
-
**NOTE**: Note that `event` object is different in UI based rules and file based rules! This section is only valid for UI based rules. If you use file based rules, refer to [file based rules event object documentation](#event-object).
77
-
Note that `event` object is only available when the UI based rule was triggered by an event and is not called from another rule!
78
-
Trying to access `event` in this case does not work and will lead to an error. Use `this.event` instead (will be `undefined` when it does not exist).
80
+
This table gives an overview over the `event` object:
79
81
80
-
When you use "Item event" as trigger (i.e. "[item] received a command", "[item] was updated", "[item] changed"), there is additional context available for the action in a variable called `event`.
81
-
When a rule is triggered, there is additional context available for the action in a variable called `event`.
|`oldState`|`ItemStateChangeTrigger`, `GroupStateChangeTrigger`| Previous state of Item or Group that triggered event |`previousState`|
85
+
|`newState`|`ItemStateChangeTrigger`, `GroupStateChangeTrigger`| New state of Item or Group that triggered event | N/A |
86
+
|`receivedState`|`ItemStateUpdateTrigger`, `GroupStateUpdateTrigger`| State of Item that triggered event |`triggeringItem.state`|
87
+
|`receivedCommand`|`ItemCommandTrigger`, `GroupCommandTrigger`| Command that triggered event |`receivedCommand`|
88
+
|`itemName`|`Item****Trigger`, `Group****Trigger`| Name of Item that triggered event |`triggeringItem.name`|
89
+
|`groupName`|`Group****Trigger`| Name of the group whose member triggered event | N/A |
90
+
|`receivedEvent`|`ChannelEventTrigger`| Channel event that triggered event | N/A |
91
+
|`channelUID`|`ChannelEventTrigger`| UID of channel that triggered event | N/A |
92
+
|`oldStatus`|`ThingStatusChangeTrigger`| Previous state of Thing that triggered event | N/A |
93
+
|`newStatus`|`ThingStatusChangeTrigger`| New state of Thing that triggered event | N/A |
94
+
|`status`|`ThingStatusUpdateTrigger`| State of Thing that triggered event | N/A |
95
+
|`thingUID`|`Thing****Trigger`| UID of Thing that triggered event | N/A |
96
+
|`cronExpression`|`GenericCronTrigger`| Cron expression of the trigger | N/A |
97
+
|`time`|`TimeOfDayTrigger`| Time of day value of the trigger | N/A |
98
+
|`timeOnly`|`DateTimeTrigger`| Whether the trigger only considers the time part of the DateTime Item | N/A |
99
+
|`offset`|`DateTimeTrigger`| Offset in seconds added to the time of the DateTime Item | N/A |
100
+
|`eventType`| all except `PWMTrigger`, `PIDTrigger`| Type of event that triggered event (change, command, triggered, update, time) | N/A |
101
+
|`triggerType`| all except `PWMTrigger`, `PIDTrigger`| Type of trigger that triggered event | N/A |
102
+
|`eventName`| all | simple Java class name of the triggering event, e.g. `ExecutionEvent`| N/A |
103
+
|`eventClass`| all | full Java class name of the triggering event, e.g. `org.openhab.core.automation.events.ExecutionEvent`| N/A |
104
+
|`module`| all | (user-defined or auto-generated) name of trigger | N/A |
105
+
|`raw`| all | Original contents of the event including data passed from a calling rule | N/A |
82
106
83
-
This table gives an overview over the `event` object for most common trigger types:
107
+
All properties are typeof `string` except for properties contained by `raw` which are unmodified from the original types.
108
+
109
+
Please note that when using `GenericEventTrigger`, the available properties depend on the chosen event types.
110
+
It is not possible for the openhab-js library to provide type conversions for all properties of all openHAB events, as those are too many.
111
+
In case the event object does not provide type-conversed properties for your chosen event type, use the `payload` property to gain access to the event's (Java data type) payload.
112
+
113
+
**NOTE:**
114
+
`Group****Trigger`s use the equivalent `Item****Trigger` as trigger for each member.
115
+
116
+
See [openhab-js : EventObject](https://openhab.github.io/openhab-js/rules.html#.EventObject) for full API documentation.
117
+
118
+
When disabling the option _Convert Event from Java to JavaScript type in UI-based scripts_, you will receive a raw Java event object instead of the `event` object described above.
119
+
See the expandable section below for more details.
120
+
121
+
<details>
122
+
<summary>Raw UI Event Object</summary>
123
+
124
+
This table gives an overview over the raw Java `event` object for UI-based scripts for most common trigger types:
84
125
85
126
| Property Name | Type | Trigger Types | Description | Rules DSL Equivalent |
- .metadata ⇒ [`items.metadata` namespace](https://openhab.github.io/openhab-js/items.metadata.html): Manage metadata directly without the need of going "through" the Item
| `channelUID` | `ChannelEventTrigger` | UID of channel that triggered event | N/A |
1435
-
| `oldStatus` | `ThingStatusChangeTrigger` | Previous state of Thing that triggered event | N/A |
1436
-
| `newStatus` | `ThingStatusChangeTrigger` | New state of Thing that triggered event | N/A |
1437
-
| `status` | `ThingStatusUpdateTrigger` | State of Thing that triggered event | N/A |
1438
-
| `thingUID` | `Thing****Trigger` | UID of Thing that triggered event | N/A |
1439
-
| `cronExpression` | `GenericCronTrigger` | Cron expression of the trigger | N/A |
1440
-
| `time` | `TimeOfDayTrigger` | Time of day value of the trigger | N/A |
1441
-
| `timeOnly` | `DateTimeTrigger` | Whether the trigger only considers the time part of the DateTime Item | N/A |
1442
-
| `offset` | `DateTimeTrigger` | Offset in seconds added to the time of the DateTime Item | N/A |
1443
-
| `eventType` | all except `PWMTrigger`, `PIDTrigger` | Type of event that triggered event (change, command, triggered, update, time) | N/A |
1444
-
| `triggerType` | all except `PWMTrigger`, `PIDTrigger` | Type of trigger that triggered event | N/A |
1445
-
| `eventClass` | all | Java class name of the triggering event | N/A |
1446
-
| `module` | all | (user-defined or auto-generated) name of trigger | N/A |
1447
-
| `raw` | all | Original contents of the event including data passed from a calling rule | N/A |
1448
-
1449
-
All properties are typeof `string` except for properties contained by `raw` which are unmodified from the original types.
1450
-
1451
-
Please note that when using `GenericEventTrigger`, the available properties depend on the chosen event types.
1452
-
It is not possible for the openhab-js library to provide type conversions for all properties of all openHAB events, as those are too many.
1453
-
In case the event object does not provide type-conversed properties for your chosen event type, use the `payload` property to gain access to the event's (Java data type) payload.
1454
-
1455
-
**NOTE:**
1456
-
`Group****Trigger`s use the equivalent `Item****Trigger` as trigger for each member.
1457
-
Time triggers do not provide any event instance, therefore no property is populated.
1458
-
1459
-
See [openhab-js : EventObject](https://openhab.github.io/openhab-js/rules.html#.EventObject) for full API documentation.
0 commit comments