Skip to content

Commit cdda3de

Browse files
DubhAddale3h
authored andcommitted
Template corrections (home-assistant#4990)
* Template corrections Updated the templates to be standards compliant. * Fixes ;) * More changes to comply with standards
1 parent a71cd0b commit cdda3de

File tree

1 file changed

+53
-45
lines changed

1 file changed

+53
-45
lines changed

source/_docs/scripts.markdown

Lines changed: 53 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ script:
2121
sequence:
2222
# This is written using the Script Syntax
2323
- service: light.turn_on
24-
entity_id: light.ceiling
24+
data:
25+
entity_id: light.ceiling
2526
- service: notify.notify
2627
data:
2728
message: 'Turned on the ceiling light!'
@@ -32,21 +33,21 @@ script:
3233
The most important one is the action to call a service. This can be done in various ways. For all the different possibilities, have a look at the [service calls page].
3334
3435
```yaml
35-
alias: Bedroom lights on
36-
service: light.turn_on
37-
data:
38-
entity_id: group.bedroom
39-
brightness: 100
36+
- alias: Bedroom lights on
37+
service: light.turn_on
38+
data:
39+
entity_id: group.bedroom
40+
brightness: 100
4041
```
4142
4243
### {% linkable_title Test a Condition %}
4344
4445
While executing a script you can add a condition to stop further execution. When a condition does not return `true`, the script will finish. There are many different conditions which are documented at the [conditions page].
4546

4647
```yaml
47-
condition: state
48-
entity_id: device_tracker.paulus
49-
state: 'home'
48+
- condition: state
49+
entity_id: device_tracker.paulus
50+
state: 'home'
5051
```
5152

5253
### {% linkable_title Delay %}
@@ -55,46 +56,53 @@ Delays are useful for temporarily suspending your script and start it at a later
5556

5657
```yaml
5758
# Waits 1 hour
58-
delay: 01:00
59+
- delay: '01:00'
5960
```
6061

6162
```yaml
6263
# Waits 1 minute, 30 seconds
63-
delay: 00:01:30
64+
- delay: '00:01:30'
6465
```
6566

6667
```yaml
6768
# Waits 1 minute
68-
delay:
69-
# supports milliseconds, seconds, minutes, hours, days
70-
minutes: 1
69+
- delay:
70+
# supports milliseconds, seconds, minutes, hours, days
71+
minutes: 1
7172
```
7273

74+
{% raw %}
7375
```yaml
7476
# Waits however many minutes input_number.minute_delay is set to
7577
# Valid formats include HH:MM and HH:MM:SS
76-
delay: {% raw %}'00:{{ states.input_number.minute_delay.state | int }}:00'{% endraw %}
78+
- delay: "00:{{ states('input_number.minute_delay')|int }}:00"
7779
```
80+
{% endraw %}
81+
7882
### {% linkable_title Wait %}
7983

8084
Wait until some things are complete. We support at the moment `wait_template` for waiting until a condition is `true`, see also on [Template-Trigger](/docs/automation/trigger/#template-trigger). It is possible to set a timeout after which the script will abort its execution if the condition is not satisfied. Timeout has the same syntax as `delay`.
8185

86+
{% raw %}
8287
```yaml
8388
# wait until media player have stop the playing
84-
wait_template: {% raw %}"{{ states.media_player.floor.state == 'stop' }}"{% endraw %}
89+
- wait_template: "{{ is_state('media_player.floor', 'stop') }}"
8590
```
91+
{% endraw %}
8692

93+
{% raw %}
8794
```yaml
88-
# wait until a valve is < 10 or abort after 1 minutes.
89-
wait_template: {% raw %}"{{ states.climate.kitchen.attributes.valve < 10 }}"{% endraw %}
90-
timeout: 00:01:00
95+
# wait until a valve is < 10 or abort after 1 minute.
96+
- wait_template: "{{ states.climate.kitchen.attributes.valve|int < 10 }}"
97+
timeout: '00:01:00'
9198
```
99+
{% endraw %}
92100

93101
When using `wait_template` within an automation `trigger.entity_id` is supported for `state`, `numeric_state` and `template` triggers, see also [Available-Trigger-Data](/docs/automation/templating/#available-trigger-data).
94102

95103
{% raw %}
96104
```yaml
97-
wait_template: "{{ is_state(trigger.entity_id, 'on') }}"
105+
- wait_template: "{{ is_state(trigger.entity_id, 'on') }}"
98106
```
99107
{% endraw %}
100108

@@ -103,12 +111,12 @@ It is also possible to use dummy variables, e.g., in scripts, when using `wait_t
103111
{% raw %}
104112
```yaml
105113
# Service call, e.g., from an automation.
106-
service: script.do_something
107-
data_template:
108-
dummy: "{{ input_boolean.switch }}"
114+
- service: script.do_something
115+
data_template:
116+
dummy: input_boolean.switch
109117
110118
# Inside the script
111-
wait_template: "{{ is_state(dummy, 'off') }}"
119+
- wait_template: "{{ is_state(dummy, 'off') }}"
112120
```
113121
{% endraw %}
114122

@@ -117,23 +125,23 @@ wait_template: "{{ is_state(dummy, 'off') }}"
117125
This action allows you to fire an event. Events can be used for many things. It could trigger an automation or indicate to another component that something is happening. For instance, in the below example it is used to create an entry in the logbook.
118126

119127
```yaml
120-
event: LOGBOOK_ENTRY
121-
event_data:
122-
name: Paulus
123-
message: is waking up
124-
entity_id: device_tracker.paulus
125-
domain: light
128+
- event: LOGBOOK_ENTRY
129+
event_data:
130+
name: Paulus
131+
message: is waking up
132+
entity_id: device_tracker.paulus
133+
domain: light
126134
```
127135

128136
You can also use event_data_template to fire an event with custom data. This could be used to pass data to another script awaiting
129137
an event trigger.
130138

131139
{% raw %}
132140
```yaml
133-
event: MY_EVENT
134-
event_data_template:
135-
name: myEvent
136-
customData: "{{ myCustomVariable }}"
141+
- event: MY_EVENT
142+
event_data_template:
143+
name: myEvent
144+
customData: "{{ myCustomVariable }}"
137145
```
138146
{% endraw %}
139147

@@ -145,13 +153,13 @@ The following automation shows how to raise a custom event called `event_light_s
145153
```yaml
146154
- alias: Fire Event
147155
trigger:
148-
platform: state
149-
entity_id: switch.kitchen
150-
to: 'on'
156+
- platform: state
157+
entity_id: switch.kitchen
158+
to: 'on'
151159
action:
152-
event: event_light_state_changed
153-
event_data:
154-
state: "on"
160+
- event: event_light_state_changed
161+
event_data:
162+
state: 'on'
155163
```
156164
{% endraw %}
157165

@@ -161,12 +169,12 @@ The following automation shows how to capture the custom event `event_light_stat
161169
```yaml
162170
- alias: Capture Event
163171
trigger:
164-
platform: event
165-
event_type: event_light_state_changed
172+
- platform: event
173+
event_type: event_light_state_changed
166174
action:
167-
service: notify.notify
168-
data_template:
169-
message: "kitchen light is turned {{ trigger.event.data.state }}"
175+
- service: notify.notify
176+
data_template:
177+
message: "kitchen light is turned {{ trigger.event.data.state }}"
170178
```
171179
{% endraw %}
172180

0 commit comments

Comments
 (0)