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
Copy file name to clipboardExpand all lines: source/_docs/scripts.markdown
+30Lines changed: 30 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -125,6 +125,36 @@ event_data:
125
125
domain: light
126
126
```
127
127
128
+
### {% linkable_title Raise and Consume Custom Events %}
129
+
130
+
The following automation shows how to raise a custom event called `event_light_turned_on` with `entity_id` as the event data. The action part could be inside a script or an automation.
131
+
132
+
```
133
+
- alias: Fire Event
134
+
trigger:
135
+
platform: state
136
+
entity_id: light.kitchen
137
+
to: 'on'
138
+
action:
139
+
event: event_light_turned_on
140
+
event_data:
141
+
entity_id: "{{ trigger.entity_id }}"
142
+
```
143
+
144
+
The following automation shows how to capture the custom event `event_light_turned_on`, and retrieve corresponsing `entity_id` that was passed as the event data.
145
+
146
+
```
147
+
- alias: Capture Event
148
+
trigger:
149
+
platform: event
150
+
event_type: light_turned_on
151
+
action:
152
+
- service: notify.notify
153
+
data_template:
154
+
message: "{{ trigger.event.data.entity_id }} is turned on."
0 commit comments