Skip to content

Add examples for advanced usage #674

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 26, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
257 changes: 256 additions & 1 deletion source/_topics/splitting_configuration.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ That about wraps it up.

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.

### {% linkable_title Advanced usage %}
### {% linkable_title Advanced Usage %}

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

Expand All @@ -190,3 +190,258 @@ We offer four advanced options to include whole directories at once.
`!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.

`!include_dir_merge_named` will return content of a directory as a dictionary by loading each file and merging it into 1 big dictionary.

#### {% linkable_title Example: `!include_dir_list` %}

`configuration.yaml`

```yaml
automation:
- alias: Automation 1
trigger:
platform: state
entity_id: device_tracker.iphone
to: 'home'
action:
service: light.turn_on
entity_id: light.entryway
- alias: Automation 2
trigger:
platform: state
entity_id: device_tracker.iphone
from: 'home'
action:
service: light.turn_off
entity_id: light.entryway
```

can be turned into:

`configuration.yaml`

```yaml
automation: !include_dir_list automation/presence/
```

`automation/presence/automation1.yaml`

```yaml
alias: Automation 1
trigger:
platform: state
entity_id: device_tracker.iphone
to: 'home'
action:
service: light.turn_on
entity_id: light.entryway
```

`automation/presence/automation2.yaml`

```yaml
alias: Automation 2
trigger:
platform: state
entity_id: device_tracker.iphone
from: 'home'
action:
service: light.turn_off
entity_id: light.entryway
```

It is important to note that each file must contain only **one** entry when using `!include_dir_list`.

#### {% linkable_title Example: `!include_dir_named` %}

`configuration.yaml`

```yaml
{% raw %}
alexa:
intents:
LocateIntent:
action:
service: notify.pushover
data:
message: Your location has been queried via Alexa.
speech:
type: plaintext
text: >
{%- for state in states.device_tracker -%}
Copy link
Member

@fabaff fabaff Jul 25, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You need to mark template part as raw ({% raw %}..{% endraw %}) otherwise they will be rendered.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Raw is opened on line 259 and closed on line 285 :)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ohh, sorry, my bad.

{%- if state.name.lower() == User.lower() -%}
{{ state.name }} is at {{ state.state }}
{%- endif -%}
{%- else -%}
I am sorry. Pootie! I do not know where {{User}} is.
{%- endfor -%}
WhereAreWeIntent:
speech:
type: plaintext
text: >
{%- if is_state('device_tracker.iphone', 'home') -%}
iPhone is home.
{%- else -%}
iPhone is not home.
{% endif %}{% endraw %}
```

can be turned into:

`configuration.yaml`

```yaml
alexa:
intents: !include_dir_named alexa/
```

`alexa/LocateIntent.yaml`

```yaml
{% raw %}
action:
service: notify.pushover
data:
message: Your location has been queried via Alexa.
speech:
type: plaintext
text: >
{%- for state in states.device_tracker -%}
{%- if state.name.lower() == User.lower() -%}
{{ state.name }} is at {{ state.state }}
{%- endif -%}
{%- else -%}
I am sorry. Pootie! I do not know where {{User}} is.
{%- endfor -%}{% endraw %}
```

`alexa/WhereAreWeIntent.yaml`

```yaml
{% raw %}
speech:
type: plaintext
text: >
{%- if is_state('device_tracker.iphone', 'home') -%}
iPhone is home.
{%- else -%}
iPhone is not home.
{% endif %}{% endraw %}
```

#### {% linkable_title Example: `!include_dir_merge_list` %}

`configuration.yaml`

```yaml
automation:
- alias: Automation 1
trigger:
platform: state
entity_id: device_tracker.iphone
to: 'home'
action:
service: light.turn_on
entity_id: light.entryway
- alias: Automation 2
trigger:
platform: state
entity_id: device_tracker.iphone
from: 'home'
action:
service: light.turn_off
entity_id: light.entryway
```

can be turned into:

`configuration.yaml`

```yaml
automation: !include_dir_merge_list automation/
```

`automation/presence.yaml`

```yaml
- alias: Automation 1
trigger:
platform: state
entity_id: device_tracker.iphone
to: 'home'
action:
service: light.turn_on
entity_id: light.entryway

- alias: Automation 2
trigger:
platform: state
entity_id: device_tracker.iphone
from: 'home'
action:
service: light.turn_off
entity_id: light.entryway
```

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.

#### {% linkable_title Example: `!include_dir_merge_named` %}

`configuration.yaml`

```yaml
group:
bedroom:
name: Bedroom
entities:
- light.bedroom_lamp
- light.bedroom_overhead
hallway:
name: Hallway
entities:
- light.hallway
- thermostat.home
front_yard:
name: Front Yard
entities:
- light.front_porch
- light.security
- light.pathway
- sensor.mailbox
- camera.front_porch
```

can be turned into:

`configuration.yaml`

```yaml
group: !include_dir_merge_named group/
```

`group/interior.yaml`

```yaml
bedroom:
name: Bedroom
entities:
- light.bedroom_lamp
- light.bedroom_overhead
hallway:
name: Hallway
entities:
- light.hallway
- thermostat.home
```

`group/exterior.yaml`

```yaml
front_yard:
name: Front Yard
entities:
- light.front_porch
- light.security
- light.pathway
- sensor.mailbox
- camera.front_porch
```