Skip to content

Commit b0f6a61

Browse files
dale3hfabaff
authored andcommitted
Add advanced usage examples (home-assistant#674)
1 parent 8827fe5 commit b0f6a61

File tree

1 file changed

+256
-1
lines changed

1 file changed

+256
-1
lines changed

source/_topics/splitting_configuration.markdown

Lines changed: 256 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ That about wraps it up.
179179

180180
If you have issues checkout `home-assistant.log` in the configuration directory as well as your indentations. If all else fails, head over to the [Gitter Chatroom](https://gitter.im/balloob/home-assistant) and ask away.
181181

182-
### {% linkable_title Advanced usage %}
182+
### {% linkable_title Advanced Usage %}
183183

184184
We offer four advanced options to include whole directories at once.
185185

@@ -190,3 +190,258 @@ We offer four advanced options to include whole directories at once.
190190
`!include_dir_merge_list` will return content of a directory as a list by merging all files (which should contain a list) into 1 big list.
191191

192192
`!include_dir_merge_named` will return content of a directory as a dictionary by loading each file and merging it into 1 big dictionary.
193+
194+
#### {% linkable_title Example: `!include_dir_list` %}
195+
196+
`configuration.yaml`
197+
198+
```yaml
199+
automation:
200+
- alias: Automation 1
201+
trigger:
202+
platform: state
203+
entity_id: device_tracker.iphone
204+
to: 'home'
205+
action:
206+
service: light.turn_on
207+
entity_id: light.entryway
208+
- alias: Automation 2
209+
trigger:
210+
platform: state
211+
entity_id: device_tracker.iphone
212+
from: 'home'
213+
action:
214+
service: light.turn_off
215+
entity_id: light.entryway
216+
```
217+
218+
can be turned into:
219+
220+
`configuration.yaml`
221+
222+
```yaml
223+
automation: !include_dir_list automation/presence/
224+
```
225+
226+
`automation/presence/automation1.yaml`
227+
228+
```yaml
229+
alias: Automation 1
230+
trigger:
231+
platform: state
232+
entity_id: device_tracker.iphone
233+
to: 'home'
234+
action:
235+
service: light.turn_on
236+
entity_id: light.entryway
237+
```
238+
239+
`automation/presence/automation2.yaml`
240+
241+
```yaml
242+
alias: Automation 2
243+
trigger:
244+
platform: state
245+
entity_id: device_tracker.iphone
246+
from: 'home'
247+
action:
248+
service: light.turn_off
249+
entity_id: light.entryway
250+
```
251+
252+
It is important to note that each file must contain only **one** entry when using `!include_dir_list`.
253+
254+
#### {% linkable_title Example: `!include_dir_named` %}
255+
256+
`configuration.yaml`
257+
258+
```yaml
259+
{% raw %}
260+
alexa:
261+
intents:
262+
LocateIntent:
263+
action:
264+
service: notify.pushover
265+
data:
266+
message: Your location has been queried via Alexa.
267+
speech:
268+
type: plaintext
269+
text: >
270+
{%- for state in states.device_tracker -%}
271+
{%- if state.name.lower() == User.lower() -%}
272+
{{ state.name }} is at {{ state.state }}
273+
{%- endif -%}
274+
{%- else -%}
275+
I am sorry. Pootie! I do not know where {{User}} is.
276+
{%- endfor -%}
277+
WhereAreWeIntent:
278+
speech:
279+
type: plaintext
280+
text: >
281+
{%- if is_state('device_tracker.iphone', 'home') -%}
282+
iPhone is home.
283+
{%- else -%}
284+
iPhone is not home.
285+
{% endif %}{% endraw %}
286+
```
287+
288+
can be turned into:
289+
290+
`configuration.yaml`
291+
292+
```yaml
293+
alexa:
294+
intents: !include_dir_named alexa/
295+
```
296+
297+
`alexa/LocateIntent.yaml`
298+
299+
```yaml
300+
{% raw %}
301+
action:
302+
service: notify.pushover
303+
data:
304+
message: Your location has been queried via Alexa.
305+
speech:
306+
type: plaintext
307+
text: >
308+
{%- for state in states.device_tracker -%}
309+
{%- if state.name.lower() == User.lower() -%}
310+
{{ state.name }} is at {{ state.state }}
311+
{%- endif -%}
312+
{%- else -%}
313+
I am sorry. Pootie! I do not know where {{User}} is.
314+
{%- endfor -%}{% endraw %}
315+
```
316+
317+
`alexa/WhereAreWeIntent.yaml`
318+
319+
```yaml
320+
{% raw %}
321+
speech:
322+
type: plaintext
323+
text: >
324+
{%- if is_state('device_tracker.iphone', 'home') -%}
325+
iPhone is home.
326+
{%- else -%}
327+
iPhone is not home.
328+
{% endif %}{% endraw %}
329+
```
330+
331+
#### {% linkable_title Example: `!include_dir_merge_list` %}
332+
333+
`configuration.yaml`
334+
335+
```yaml
336+
automation:
337+
- alias: Automation 1
338+
trigger:
339+
platform: state
340+
entity_id: device_tracker.iphone
341+
to: 'home'
342+
action:
343+
service: light.turn_on
344+
entity_id: light.entryway
345+
- alias: Automation 2
346+
trigger:
347+
platform: state
348+
entity_id: device_tracker.iphone
349+
from: 'home'
350+
action:
351+
service: light.turn_off
352+
entity_id: light.entryway
353+
```
354+
355+
can be turned into:
356+
357+
`configuration.yaml`
358+
359+
```yaml
360+
automation: !include_dir_merge_list automation/
361+
```
362+
363+
`automation/presence.yaml`
364+
365+
```yaml
366+
- alias: Automation 1
367+
trigger:
368+
platform: state
369+
entity_id: device_tracker.iphone
370+
to: 'home'
371+
action:
372+
service: light.turn_on
373+
entity_id: light.entryway
374+
375+
- alias: Automation 2
376+
trigger:
377+
platform: state
378+
entity_id: device_tracker.iphone
379+
from: 'home'
380+
action:
381+
service: light.turn_off
382+
entity_id: light.entryway
383+
```
384+
385+
It is important to note that when using `!include_dir_merge_list`, you must include a list in each file (each list item is denoted with a hyphen [-]). Each file may contain one or more entries.
386+
387+
#### {% linkable_title Example: `!include_dir_merge_named` %}
388+
389+
`configuration.yaml`
390+
391+
```yaml
392+
group:
393+
bedroom:
394+
name: Bedroom
395+
entities:
396+
- light.bedroom_lamp
397+
- light.bedroom_overhead
398+
hallway:
399+
name: Hallway
400+
entities:
401+
- light.hallway
402+
- thermostat.home
403+
front_yard:
404+
name: Front Yard
405+
entities:
406+
- light.front_porch
407+
- light.security
408+
- light.pathway
409+
- sensor.mailbox
410+
- camera.front_porch
411+
```
412+
413+
can be turned into:
414+
415+
`configuration.yaml`
416+
417+
```yaml
418+
group: !include_dir_merge_named group/
419+
```
420+
421+
`group/interior.yaml`
422+
423+
```yaml
424+
bedroom:
425+
name: Bedroom
426+
entities:
427+
- light.bedroom_lamp
428+
- light.bedroom_overhead
429+
hallway:
430+
name: Hallway
431+
entities:
432+
- light.hallway
433+
- thermostat.home
434+
```
435+
436+
`group/exterior.yaml`
437+
438+
```yaml
439+
front_yard:
440+
name: Front Yard
441+
entities:
442+
- light.front_porch
443+
- light.security
444+
- light.pathway
445+
- sensor.mailbox
446+
- camera.front_porch
447+
```

0 commit comments

Comments
 (0)