Skip to content

Commit adf508a

Browse files
authored
Merge pull request home-assistant#4515 from home-assistant/skalavala-patch-1
added custom event documentation.
2 parents 970acbb + 6901bdc commit adf508a

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

source/_docs/scripts.markdown

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,36 @@ event_data:
125125
domain: light
126126
```
127127

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."
155+
```
156+
157+
128158
[Script component]: /components/script/
129159
[automations]: /getting-started/automation-action/
130160
[Alexa/Amazon Echo]: /components/alexa/

0 commit comments

Comments
 (0)