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/automation/templating.markdown
+10-12Lines changed: 10 additions & 12 deletions
Original file line number
Diff line number
Diff line change
@@ -34,27 +34,19 @@ automation 2:
34
34
35
35
automation 3:
36
36
trigger:
37
-
# Multiple Entities for which you want to perform the same action.
37
+
# Multiple entities for which you want to perform the same action.
38
38
- platform: state
39
39
entity_id:
40
40
- light.bedroom_closet
41
-
to: 'on'
42
-
# Trigger when someone leaves the closet light on for 10 minutes.
43
-
for: '00:10:00'
44
-
- platform: state
45
-
entity_id:
46
41
- light.kiddos_closet
47
-
to: 'on'
48
-
for: '00:10:00'
49
-
- platform: state
50
-
entity_id:
51
42
- light.linen_closet
52
43
to: 'on'
44
+
# Trigger when someone leaves one of those lights on for 10 minutes.
53
45
for: '00:10:00'
54
46
action:
55
47
- service: light.turn_off
56
48
data_template:
57
-
#Whichever entity triggers the automation we want to turn off THAT entity, not the others.
49
+
#Turn off whichever entity triggered the automation.
58
50
entity_id: "{{ trigger.entity_id }}"
59
51
```
60
52
{% endraw %}
@@ -76,12 +68,18 @@ It is possible to use `data` and `data_template` concurrently but be aware that
76
68
77
69
## Trigger State Object
78
70
79
-
Knowing how to access the [state object](/docs/configuration/state_object/) of a trigger entity could be one of the more common questions. Here are a few ways for the [`state`](#state), [`numeric_state`](#numeric_state) and [`template`](#template) triggers:
71
+
Knowing how to access the [state object](/docs/configuration/state_object/) of a trigger entity can be useful in automations. Here are a few ways to access the [`state`](#state), [`numeric_state`](#numeric_state) and [`template`](#template) triggers:
80
72
81
73
* `trigger.from_state` will return the **previous** [state object](/docs/configuration/state_object/) of the entity.
82
74
* `trigger.to_state` will return the **new** [state object](/docs/configuration/state_object/) that triggered trigger.
83
75
* `states[trigger.to_state.domain][trigger.to_state.object_id]` will return the **current** [state object](/docs/configuration/state_object/) of the entity.
84
76
77
+
<div class='note'>
78
+
79
+
Be aware that if you reference a trigger state object in an automation action, attempting to test that automation by calling the `automation.trigger` service or by clicking EXECUTE in the More Info box for the automation will not work. This is because the trigger state object doesn't exist in those contexts. One way to test automations like these is to manually change the state of the trigger entity at Developer Tools > States.
80
+
81
+
</div>
82
+
85
83
## Available Trigger Data
86
84
87
85
The following tables show the available trigger data per platform.
0 commit comments