Use of !include of additional .yaml configuration files

Have been using include for a long time in below format on the sensor files. It has worked perfectly and help a lot to structure where I do the different configurations.

sensor: !include sensor.yaml
sensor power: !include sensor-power.yaml
sensor power-totals: !include sensor-power-totals.yaml
sensor light: !include sensor-light.yaml

I know the “sensor method” is old, and it should be done using templates (Im a little slow:-)
However, I can not figure out why this is then not working,. It only includes the defined sensors from the templates.yaml file, not the templates-power.yaml

template: !include templates.yaml
template power: !include templates-power.yaml

Now, I got in doubt if this should work at all on template files?

1 Like

khvej8,

What about using a template directory like follows:

template: !include_dir_merge_list templates/

And move those .yaml files into the templates sub-dir in the config folder? I’ll be the first to admit I’m pretty fresh and still learning, but that’s the direction I’d probably go.

1 Like

Using !include file.yaml is basically identical to copying the contents of that file and pasting them into that spot. So does what you’re showing work? I have no idea because you aren’t showing me the contents of any of these files.

Basically you absolutely can do what you’re showing. Whether it works or not for you depends entirely on whether the contents of those files makes sense when copied and pasted into configuration.yaml in the specified spot.

Hi Mike, I agree, it should work, and it works for my sensor files. I have the below in the 2 different “template files”.

It is as if it never loads the templates-power.yaml file. I do not have any errors in the log related to this. I even tried to include a error in the file, and it was not detected. Maybe “template” does not work with more include files.

Templates.yaml

- sensor:
  - name: "TEST1boolean"
    state: >
      {{ states('input_boolean.aa_test_boolean') }}

templates-power.yaml

- sensor:
  - name: "TEST2boolean"
    state: >
      {{ states('input_boolean.aa_test_boolean') }}

hm possibly. I’ve never tried the named blocks with anything besides automations, scripts and scenes. Perhaps they don’t work with everything. Might want to go with DaBer’s suggestion instead.

If this is found by others.

I have looked around and found some other threads which describe the same behavior, not loading the second template file from include.

Im not sure if this is an error or intended. Personally I have a lot of sensor files and stick with those, only using template for the triggerbased sensors for now.

It sounds to me like it’s only reading the first template file because they start with the same name. Try changing the name of the second entry and include file and see if that works.

Fwiw you might want to check out packages. Seems like it would fit config organization style better since it looks like you are grouping things by use case and then labeling that group (power, power-totals, etc.). That’s what packages are for.

And I can assure you that you can have a template in multiple packages. Since I have like 15 packages and nearly all of them include template.

Suggestion of changing the filename did not have any effect. Still not loaded.

I have seen the “packages” before, not really using time to understand. This is definitely a super cool idea, which will solve some of the issues I have today. Like a combined setup for my garage which is in 3 different files or when I constantly forget “hikvision” is in binary_sensor file.

Will take some time to re-arrange. Will start with my new nordpool price setup.
Thanks for the idea

1 Like