Advice in Splitting Config needed

Hello there,

I’ new with Home Assistant. After much trial and error I was able to use waste collection schedule".
I tried to put this in another file and user !include. But If I do:

sensor: !include … : I get an YAML error: duplicate mapping key . How to avoid this? Or can I ignore it?

Also: where to put the integration? (e.g. the entries before sensor: )

This I have in my configuration. yaml:

type or paste code here
############      Waste Collection Schedule
waste_collection_schedule:
  sources:
    - name: ics
      args:
        url: "https://azv.hausmuell.info/ics/ics.php?egebiet=24990&ort=Wutha-Farnroda&ortsteil=Mosbach"
      calendar_title: "AZV-Wartburgkreis"
      customize:
      - type: Bioabfall
        show: false
      - type: 'Papier, Pappe, Karton'
        alias: Altpapier
  fetch_time: "23:15"

sensor:

#  - platform: waste_collection_schedule
#   name: "naechste_abfuhr"
#    value_template: ' {{ value.types[0] }} in {{ value.daysTo }} Tagen  '
#    date_template: '{{value.date.strftime("%d.%m.%Y")}}'
    
  - platform: waste_collection_schedule
    name: muell_hausmuell
    value_template: '{{value.date.strftime("%a, %d.%m.%Y")}}'
    types:
      - "Restmüll"
  - platform: waste_collection_schedule
    name: muell_gelbetonne
    value_template: '{{value.date.strftime("%a, %d.%m.%Y")}}'
    types:
      - "Gelbe Tonne"
  - platform: waste_collection_schedule
    name: muell_altpapier
    value_template: '{{value.date.strftime("%a, %d.%m.%Y")}}'
    types:
      - "Altpapier"
    
  - platform: waste_collection_schedule
    name: muell_naechster
    value_template: '{% if value.daysTo == 0 %}Heute{% elif value.daysTo == 1 %}Morgen{% else %}in {{value.daysTo}} Tagen{% endif %}'
    date_template: '{{value.date.strftime("%d.%m.%Y")}}'
  
###############    Ende Waste Collection Schedule

If you have sensor: !include.... in your configuration.yaml, you must move all sensors out into the included file(s). You cannot have an additional sensor: block also in the configuration.yaml file, which is what the error is telling you: duplicate mapping key.

I use:

sensor: !include_dir_merge_list yamls/sensor/ # includes .yaml files located in config/yamls/sensor

So I have a folder called sensor in which I can have as many .yaml files as I want.
There are good examples for every case at the bottom of this page.

Thank you @Troon.

I tride to move the sensor: part in another file and use sensors: !include …, but then all the sensors disappeared im Home assistant. Also the calendar disappeared. SoI belive hat the “platform” (e.g. the entries between “waste collection schedule” and the sensors: where not found anymore. Where to put this?

Paste in your current configuration.yaml.

Must be sensor: !include [etc] not sensors:.

OK. Maybe typo, will try again when I’m at home.

Hello @Syntox,

can you explain why you use

sensor: !include_dir_merge_list yamls/sensor/ ?

What is the difference to !include_dir_merge_named …/ ?

And what about !include_dir_list and !includ_dir_named ? When to use what?

Up to you, and you can always change later. The top of my configuration.yaml looks like this:

# Configure a default setup of Home Assistant (frontend, api, etc)
default_config:

automation: !include automations.yaml
automation manual: !include_dir_merge_list automations
binary_sensor: !include binary_sensors.yaml
camera: !include cameras.yaml
climate: !include climate.yaml
group: !include groups.yaml
light: !include lights.yaml
proximity: !include proximity.yaml
rest: !include_dir_merge_list rest
script: !include scripts.yaml
sensor: !include_dir_merge_list sensors
shell_command: !include shell_commands.yaml
switch: !include switches.yaml
template: !include_dir_merge_list templates

I have automations spread across many folders and files under the automations/ folder, same for rest, sensor and template.

At the moment, I don’t have enough content under the other domains to need more than one file, so my (non-template) binary sensors, for example, are in a single file in the same folder as configuration.yaml. If this file grows larger than I want it to, I will split it out in a similar way.

I use yamls/sensor/ just for organisation. yamls/ is the folder where all my .yaml files are are stored in subfolders like sensor/ where all my files from the sensor integration are.

I think the differences are very well explained at the link I posted.
It’s all about how the files are combined. For example !include_dir_list ignores the filename and can only contain one entry where !include_dir_named uses the file name as the indented configuration option and can contain only one entry too.

I’ ve been studying the documentation again, going through the examples and taking notes. I think I have understood it now. Thanks for your help.

Great, it’s a bit confusing if you’re using yaml and !include for the first time, but it’s easy to understand if you compare the different examples.