Using !include in an automation possible?

Hi,

I have a couple of automations to control my heating schedule throughout the day.
The basic structure is identical for each automation file, they mostly differ in the variable names being used (e.g. “day”, “evening”, “night”…).
I would like to “offload” parts of the automation yaml file into a (reusable) separate file, for instance most or all of the triggers.
However, something like:

alias: '[Heating] Day settings'
trigger: !include trigger-include.yaml
conditions:
[...]

does not seem to work:

  General Errors:
    - Error loading /config/configuration.yaml: while scanning a simple key
  in "/config/automation/...", line 3, column 1
could not find expected ':'
  in "/config/automation/...", line 4, column 1

I’m already including all my automations through an “automation: !include_dir_list automations” statement in configuration.yaml in case that is relevant.

If it is possible to use an included file at this point, I’m probably messing up the correct syntax.
In this case I would appreciate an example from someone who got this working.

Thanks!

Sebastian

You can use includes anywhere, just not through the UI. Also, you need to make sure you properly format your included file’s yaml, which you did not share.

Thanks a lot for confirming, that there should be a way to make this work :slight_smile:
The included file just contains a list of triggers:

- platform: state
  entity_id: input_boolean.heating
  to: 'on'
- platform: state
  entity_id: input_boolean.venting
  to: 'off'
[...]

I think I’m on the right path now - I got the config validation to pass. It probably helped not to add a .yaml extension to the file when it’s placed in a directory that is fed to an !include_dir_list statement :smiley:

Sebastian

One more thing…
I have triggers that fire when the value of an input_number control is changed, eg:

trigger:
[...]
  - platform: state
    entity_id: input_number.heating_livingroom_day

I was hoping that I could use a variable at this point, converting it to something like:

automation:
  alias: ...
  variables:
    daytime: "day"
  trigger:
    - platform: state
      entity_id: input_number.heating_livingroom_{{daytime}}

This way I would be able to use a common trigger-include file for all the heating automations.
Apparently variables are not evaluated for the entity_id parameter, though.

So I thought I would at least be able to divide the list of triggers into a common, included part and a automation-specific part, e.g.

trigger: !include trigger-include.inc
  - platform: state
    entity_id: input_number.heating_livingroom_day

But unfortunately, it does not look like it’s working that way.

Can anyone confirm this?

Sebastian

Sorry to resurrect an old topic, but I’m struggling with the use of an !include in a script as part of a morning briefing. I’m following SlackerLabs video on using macros to create a comprehensive briefing. If you haven’t seen it, it’s here:

In his video he creates a daily_briefing.yaml file which he calls from a script via an automation in his packages folder. The daily_briefing.yaml file is in a folder called templates, which is in the same directory level as his packages folder. I should add that this templates folder is not for template sensors, but where he keeps all his briefing templates. So his !include looks like this:

 - service: script.speech_engine
        data:
          who: kitchen
          message: !include ../templates/speech/daily_briefing.yaml

He states that the ../ at the start of the !include file path is to back him out of his packages folder, where the automation and script are, and send him to the templates/speech folder, where the daily_briefing.yaml file is.

So, my automations and scripts are not in packages (although I do use packages for other things). My automations are in the automations.yaml file and my scripts are in the scripts.yaml file. I used the services tab in developer tools to test my version of the above and keep getting a null response no matter what i try.

I created a speech folder in the same directory level as the automations.yaml and scripts.yaml files and then created a morning_briefing.yaml file in the speech folder. In the developer tools services tab I enter:

service: script.speech_engine_for_tts
data:
  voice: Brian
  where: Kitchen
  message: !include /speech/morning_briefing.yaml

which calls my own tts speech engine script and passes it the voice I want to use and the location of the Amazon Echo I want the speech to play from. It’s the !include path in the message that is stumping me. I’ve tried various iterations but can’t seem to get it.

Some help with this would be gratefully received. Thanks.

Have you tried adding ```
!include_dir_named … or dir_list

In Your config.yaml

No I haven’t. Will try that and report back :+1:

UPDATE

I tried adding

speech !include_dir_named speech

to my configuration.yaml and all I got was an error saying speech not a valid integration or property speech is not allowed.

any other suggestions?

You either have to include the full path /config/speech/ or navigate to that path with …/ like …/speech or wherever that path is