Skip to content

Commit 96bf45c

Browse files
authored
Add advanced examples
1 parent 76024d4 commit 96bf45c

File tree

1 file changed

+253
-1
lines changed

1 file changed

+253
-1
lines changed

source/_topics/splitting_configuration.markdown

Lines changed: 253 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,255 @@ 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 `!include_dir_list` Example %}
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 `!include_dir_named` Example %}
255+
256+
`configuration.yaml`
257+
258+
```yaml
259+
alexa:
260+
intents:
261+
LocateIntent:
262+
action:
263+
service: notify.pushover
264+
data:
265+
message: Your location has been queried via Alexa.
266+
speech:
267+
type: plaintext
268+
text: >
269+
{%- for state in states.device_tracker -%}
270+
{%- if state.name.lower() == User.lower() -%}
271+
{{ state.name }} is at {{ state.state }}
272+
{%- endif -%}
273+
{%- else -%}
274+
I am sorry. Pootie! I do not know where {{User}} is.
275+
{%- endfor -%}
276+
WhereAreWeIntent:
277+
speech:
278+
type: plaintext
279+
text: >
280+
{%- if is_state('device_tracker.iphone', 'home') -%}
281+
iPhone is home.
282+
{%- else -%}
283+
iPhone is not home.
284+
{% endif %}
285+
```
286+
287+
can be turned into:
288+
289+
`configuration.yaml`
290+
291+
```yaml
292+
alexa:
293+
intents: !include_dir_named alexa/
294+
```
295+
296+
`alexa/LocateIntent.yaml`
297+
298+
```yaml
299+
action:
300+
service: notify.pushover
301+
data:
302+
message: Your location has been queried via Alexa.
303+
speech:
304+
type: plaintext
305+
text: >
306+
{%- for state in states.device_tracker -%}
307+
{%- if state.name.lower() == User.lower() -%}
308+
{{ state.name }} is at {{ state.state }}
309+
{%- endif -%}
310+
{%- else -%}
311+
I am sorry. Pootie! I do not know where {{User}} is.
312+
{%- endfor -%}
313+
```
314+
315+
`alexa/WhereAreWeIntent.yaml`
316+
317+
```yaml
318+
speech:
319+
type: plaintext
320+
text: >
321+
{%- if is_state('device_tracker.iphone', 'home') -%}
322+
iPhone is home.
323+
{%- else -%}
324+
iPhone is not home.
325+
{% endif %}
326+
```
327+
328+
#### {% linkable_title `!include_dir_merge_list` Example %}
329+
330+
`configuration.yaml`
331+
332+
```yaml
333+
automation:
334+
- alias: Automation 1
335+
trigger:
336+
platform: state
337+
entity_id: device_tracker.iphone
338+
to: 'home'
339+
action:
340+
service: light.turn_on
341+
entity_id: light.entryway
342+
- alias: Automation 2
343+
trigger:
344+
platform: state
345+
entity_id: device_tracker.iphone
346+
from: 'home'
347+
action:
348+
service: light.turn_off
349+
entity_id: light.entryway
350+
```
351+
352+
can be turned into:
353+
354+
`configuration.yaml`
355+
356+
```yaml
357+
automation: !include_dir_merge_list automation/
358+
```
359+
360+
`automation/presence.yaml`
361+
362+
```yaml
363+
- alias: Automation 1
364+
trigger:
365+
platform: state
366+
entity_id: device_tracker.iphone
367+
to: 'home'
368+
action:
369+
service: light.turn_on
370+
entity_id: light.entryway
371+
372+
- alias: Automation 2
373+
trigger:
374+
platform: state
375+
entity_id: device_tracker.iphone
376+
from: 'home'
377+
action:
378+
service: light.turn_off
379+
entity_id: light.entryway
380+
```
381+
382+
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.
383+
384+
#### {% linkable_title `!include_dir_merge_named` Example %}
385+
386+
`configuration.yaml`
387+
388+
```yaml
389+
group:
390+
bedroom:
391+
name: Bedroom
392+
entities:
393+
- light.bedroom_lamp
394+
- light.bedroom_overhead
395+
hallway:
396+
name: Hallway
397+
entities:
398+
- light.hallway
399+
- thermostat.home
400+
front_yard:
401+
name: Front Yard
402+
entities:
403+
- light.front_porch
404+
- light.security
405+
- light.pathway
406+
- sensor.mailbox
407+
- camera.front_porch
408+
```
409+
410+
can be turned into:
411+
412+
`configuration.yaml`
413+
414+
```yaml
415+
group: !include_dir_merge_named group/
416+
```
417+
418+
`group/interior.yaml`
419+
420+
```yaml
421+
bedroom:
422+
name: Bedroom
423+
entities:
424+
- light.bedroom_lamp
425+
- light.bedroom_overhead
426+
hallway:
427+
name: Hallway
428+
entities:
429+
- light.hallway
430+
- thermostat.home
431+
```
432+
433+
`group/exterior.yaml`
434+
435+
```yaml
436+
front_yard:
437+
name: Front Yard
438+
entities:
439+
- light.front_porch
440+
- light.security
441+
- light.pathway
442+
- sensor.mailbox
443+
- camera.front_porch
444+
```

0 commit comments

Comments
 (0)