Include in Configuration.yaml file

Hello,
I’m trying to use the include in the configuration.yaml file.
I’m seeing different behavior when I would add all the files in the configuration.yaml file. When I do this alle the enties/sensors will be created. If start separating them in directory called sensor, they won’t be created and I don’t see any messages in the log file.

This is my configuration.yaml file:

group: !include groups.yaml
automation: !include automations.yaml
script: !include scripts.yaml
scene: !include scenes.yaml
light: !include lights.yaml
utility_meter: !include utility_meter/utility.yaml
sensor: !include_dir_list sensor/

File 1 in the sensor folder (sensor):

  • platform: template
    sensors:
    energy_gass_eur:
    friendly_name: ‘Kosten vandaag gas’
    value_template: “{{ (states(‘sensor.gas_daily’)|float * states(‘input_number.gas_energy_cost’)|float)|round(2) }}”
    unit_of_measurement: “€”
    icon_template: mdi:currency-eur

PRICES GAS

  • platform: template
    sensors:
    gas_price_today:
    unit_of_measurement: ‘EUR’
    value_template: >-
    {% set a = states(‘sensor.gas_daily’) | float %}
    {% set b = states(‘input_number.all_in_enkeltarief_gas’) | float %}
    {% set c = states(‘input_number.netbeheerkosten_gas’) | float %}
    {% set d = states(‘input_number.vaste_leveringskosten_gas’) | float %}
    {{ (((a * b) + c) + d) | round(2) }}
    gas_price_yesterday:
    unit_of_measurement: ‘EUR’
    value_template: >-
    {% set a = states(‘sensor.gas_yesterday’) | float %}
    {% set b = states(‘input_number.all_in_enkeltarief_gas’) | float %}
    {% set c = states(‘input_number.netbeheerkosten_gas’) | float %}
    {% set d = states(‘input_number.vaste_leveringskosten_gas’) | float %}
    {{ (((a * b) + c) + d) | round(2) }}

File 2 (folder sensor):

  • platform: template
    sensors:
    energy_water_eur:
    friendly_name: ‘Kosten vandaag water’
    value_template: “{{ (states(‘sensor.water_daily’)|float * states(‘input_number.water_energy_cost’)|float)|round(2) }}”
    unit_of_measurement: “€”
    icon_template: mdi:currency-eur

PRICES GAS

  • platform: template
    sensors:
    water_price_today:
    unit_of_measurement: ‘EUR’
    value_template: >-
    {% set a = states(‘sensor.water_daily’) | float %}
    {% set b = states(‘input_number.water_energy_cost’) | float %}
    {% set c = states(‘input_number.water_belasting_cost’) | float %}
    {% set d = states(‘input_number.vaste_leveringskosten_water’) | float %}
    {{ (((a * b) + c) + d) | round(2) }}
    water_price_yesterday:
    unit_of_measurement: ‘EUR’
    value_template: >-
    {% set a = states(‘sensor.water_yesterday’) | float %}
    {% set b = states(‘input_number.water_energy_cost’) | float %}
    {% set c = states(‘input_number.water_belasting_cost’) | float %}
    {% set d = states(‘input_number.vaste_leveringskosten_water’) | float %}
    {{ (((a * b) + c) + d) | round(2) }}

What have I done wrong?
thx
sasa

It’s quite difficult to diagnose without proper formatting. Please edit your post and enclose the YAML in a preformatted code block (</> icon).

It’s indeed hard to tell without proper formatting, but from what I can tell, both files are laid out as a list (i.e. separated with the hyphen) containing multiple instances of the full template config like so:

- platform: template
  sensors:
    energy_water_eur:
      [bla bla]
- platform: template
  sensors:
    water_price_today: 
      [bla bla]

I think this format in conjunction with !include_dir_list won’t work because the contents of each file are grouped together in a single list item, and inside each file is a list, so in effect you’re double-nesting the list which won’t work. !include_dir_merge_list will join the files into a single list, instead of making each file a separate list item, which is what the sensor: line in your base config is expecting.

You can also run python -m homeassistant --script check_config --files -c /config from the CLI to make sure your !includes catch all the yaml files you’re expecting, but in your case I suspect it’s including the right file but taking issue with the formatting.

Also might be worth noting that:

  • You’re using the legacy template format, there is an updated one. I’m not sure if/what benefits there are in using it, but if you’ve heard that you can’t use !includes with the newer format, that was previously true but resolved in August :wink:
  • You can define multiple template sensors under a single platform like so:
- platform: template
  sensors:
    energy_water_eur:
      [bla bla]
    water_price_today: 
      [bla bla]

Thanks for the reply. I didn’t include the sensor files, because they are quite big with amount of lines.
I tried this morning !include_dir_merge_list option and things seen to work.
With regards to your comment on the new format, I’m using sensors from different GitHub repository’s. And I’m not a good programmer so I try to leave things as they are… :slightly_smiling_face:

sasa

The formatting comment is in regards to your post on the forums. Please take time to read the posting guidelines (In the FAQ), specifically point 11. It will show you how to properly format when posting.