Help adding additional yaml files using !include to configuration.yaml

I have been trying for a week now to break out my configuration.yaml into a few yaml files. When I try to add them with the !include I keep getting an error similar to this:

extra keys not allowed @ data[‘camera’]

Here is what I have added to my configuration.yaml:

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

# Uncomment this if you are using SSL/TLS, running in Docker container, etc.
# http:
#   base_url: example.duckdns.org:8123

homeassistant:
#  switch: !include switch.yaml
  camera: !include camera.yaml

frontend:
  themes: !include themes.yaml
  

As you can see, I tried adding a switch.yaml and camera.yaml and both of them throw the same error. The themes.yaml worked as expected, so not sure what is wrong.

I am very new to this and have found several post showing the exact thing I am doing, or at least I think it is the exact thing, but I keep getting errors. Any help would be greatly appreciated.

This is kind of confusing at first. Your issue is that you have it nested under homeassistant: and it does not belong there, these are top level domains. Here’s how it should look:

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

# Uncomment this if you are using SSL/TLS, running in Docker container, etc.
# http:
#   base_url: example.duckdns.org:8123

homeassistant:

frontend:
  themes: !include themes.yaml

# Included files go here like this, no spaces before them
switch: !include switch.yaml
camera: !include camera.yaml

Also post one of the files you’re breaking your configuration out into. Not only do you need to define the include in the correct part of the main configuration, you have to make sure spacing and indentation is proper in the file. And make sure you’re not re-defining the domain in the file you’re including.

As an example, here’s the start of mine:

default_config:
group: !include groups.yaml
automation: !include automations.yaml
script: !include scripts.yaml
camera: !include cameras.yaml
sensor: !include_dir_merge_list sensors
switch: !include switches.yaml

I have separate files for each of those domains; and multiple sensor files all within the sensors subdirectory. The switches.yaml starts thus:

# immersion heater relay
- platform: mqtt
  name: "Shelly 1PM-xxxxxx relay"

Note there’s no switch: in it, because that’s already covered above. The !include directive effectively drops in the included file at that point — in this case, after the switch: line in configuration.yaml.

UPDATE: The syntax for MQTT has changed since I wrote this — see the latest docs.

1 Like

Thank you so much for the information. I don’t have time to try these till I get a break from work later this afternoon. I will report back to let you know I got it working based on your guidance.

I was able to get the configuration to pass validation after your help. Now I just need to have some time to work on the cards to show the camera. Thank you for your help. Wish I could mark more than one as the solution.