Bug? Nested configurations

I try to split the configuration.yaml like so:


template: !include templates.yaml


!include energy_templates.yaml

- sensor:
   name: Aussentemperatur Durchschnitt
   unit_of_measurement: "°C"
   state: >
     {%- set temps = [states("sensor.motion_eingang_temperature"),states("sensor.thp_schuppen_temperature"),states("sensor.thp_schuppen_temperature2")]|map("float","invalid")|select("float")|list %}
     {%- set temps_avg = temps|sum / temps|count  %}
     {{ temps_avg|round(0) }}

- sensor:
    name: Durchschnitt Heizkörper Öffnung
    unit_of_measurement: "%"
    state: >-
      {{ ((states.sensor | selectattr('entity_id', 'search', 'valvetappet') | map(attribute='state') | map('int',0) | list | sum) / (states.sensor | selectattr('entity_id', 'search', 'valvetappet') | list | count)) | round(2)}}


- trigger:
  - platform: state
      - 'sensor.ac_tim_heat_energy_consumption'
      - 'sensor.ac_tim_cool_energy_consumption'
    name: Klima Energy Tim
    unit_of_measurement: kWh
    device_class: energy
    state: "{{ (states('sensor.klima_energy_tim') | float(0)) + (states('sensor.ac_tim_heat_energy_consumption') | float(0)) + (states('sensor.ac_tim_cool_energy_consumption') | float(0)) }}"
    state_class: total_increasing

This should work as of

Nesting !include s (having an !include within a file that is itself !include d) will also work.

!include filename.yaml is the statement that tells Home Assistant to insert the contents of filename.yaml at that point.

Yet the check in the Developer Tools complains:

Error loading /config/configuration.yaml: mapping values are not allowed here in "/config/templates.yaml", line 3, column 9

(This is the line succeeding the include statement).

Something here clearly does not work as documented. Bug in code or bug in doc - or is the problem on my side of the screen?

Any input is appreciated.


The documentation is correct your config is not.

That is not valid. See how all your other includes have a key then an include. You can’t have !include starting the line. It must be of the form:

something: !include...

That’s not what’s in the doc:

!include filename.yaml is the statement that tells Home Assistant to insert the contents of filename.yaml at that point.

And I cannot see how nesting would make sense otherwise.

The line you quoted from the documentation is referring to the YAML example that precedes it.

I have a sub-directory named templates. All of my Template entities are in several files within that sub-directory. The following (in configuration.yaml) tells Home Assistant where to find all Template-related configuration files.

template: !include_dir_merge_list templates/
1 Like

Have a look at packages. It may suit you better:

Thanks for your input. I dug a bit deeper and came to the conclusion that the doc is a bit misleading here (to say the least).

The YAML loader in util/yaml/loader.py “abuses” the YAML tag mechanics to create a custom constructor for included files. That means there is no “file included” - the !include filename tag is loaded, parsed and the resulting dict is placed in the parent nodes value.

Thus the somewhat obvious solution to my “problem” is:

  - !include config1.yaml
  - !include config2.yaml

The numerous questions I stumbled across while researching this tells me that the documentation is missing some important information. I’m gonna suggest an edit.

None of that is correct or alluded to in the documentation.

You are misinterpreting it.

Feel free to submit clarifications though.

Yeah, sure…

By that completely un-constructive reply I take it that you disagree. Please elucidate your arguments and we may be able to assist you.

1 Like