Error in splitting configuration.yaml into packages

I’m rebuilding my Home Assistance instance from scratch (using a VM in VirtualBox) and want to split the configuration from the start.

I had an earlier attempt using packages as I like the idea of functional grouping so that I can have different integrations in one yaml file. But I deleted a test configuration a few months ago and now can’t get this to work. This is what I have done:

  • Split the original configuration.yaml that included everything into various yaml files
  • Created a folder /config/packages and moved the various yaml files into that folder; e.g. sensor.yaml
  • Added the following to the configuration.yaml file
homeassistant:
 packages: !include_dir_merge_named packages/

I then created sensor.yaml with this content

sensor:
# Extract temp and humidity info from Xiaomi BLE sensors that connect to various ESP32s around the house
#
# Office sensor
  - platform: mqtt
    state_topic: "tele/tasmota_16CDAC/SENSOR"
    name: "Office temperature"
    unit_of_measurement: "°C"
    value_template: "{{ value_json['ATC-34ef40']['Temperature'] }}"

When checking configuration.yaml I get the following error message

expected a dictionary for dictionary value @ data['packages']['sensor']

The content in sensor.yaml works with the same indentation in the original configuration.yaml so I have no idea where I go wrong. Firstly I 'd like to understand the error message and secondly how to resolve it

Any ideas?

Try:

  packages: !include_dir_named packages

This is what i use for multple yaml files, including subdirs in the packages folder.

Did you put the sensor.yaml file into the packages folder?

Or is it directly in the config folder?

Yes, the sensor.yaml file is in the packages directory. Reading more on Packages - Home Assistant there’s a statement I don’t quite understand relating to

homeassistant:
  packages: !include_dir_named packages

This uses the concept splitting the configuration and will include all files in a directory with the keys representing the filenames. A key should be followed by a value but where would I specify this value?

Likewise for the statement

homeassistant:
  packages: !include_dir_merge_named packages/

the example of packages/subsystem1/functionality1.yaml translating to

subsystem1_functionality1:
  input_boolean:
  ...
  binary_sensor:
  ...
  automation:

can also be applied as packages/sensor.yaml and the contents as

sensor:
  input_boolean:
  ...
  binary_sensor:
  ...
  automation:

Which is basically what I was trying to achieve unless this directive requires an additional directory layer subsystem1

Also back to the question re the error

expected a dictionary for dictionary value @ data['packages']['sensor']

does this mean sensor is a key and doesn’t have any value (as in key: value)? What value would I provide?

Properly confused at this point :slight_smile:

If your file contents look like the last example then you need to remove “sensor:” from the top line.

As I understand it, packages are more for combining entities from several domains into a theme based package.

This is how it works for me:

configuration.yaml

homeassistant:
  packages: !include_dir_named packages

Template for a package:

## CUSTOMIZE #################################################

homeassistant:
#  customize:


## LOGGING #################################################

recorder:

history:

logbook:

## ACTORS ##################################################

cover:

light:

switch:

group:

## SENSORS #################################################

sensor:

template:


## HELPERS #################################################

input_boolean:

input_number:
  
input_text:

input_select:

input_datetime:

timer:

## ACTIONS #################################################

automation:

script:


    
    
    

If you use !include_dir_merge_named then you have to remove the “sensor:” from your sensor.yaml. Not sure if this even works with packages as it wouldn’t make any sense.

I had (sometimes still have) similar issues understanding this. Try following my questions here:

https://community.home-assistant.io/t/lovelace-button-card/65981/3286?u=bschatzow

Also

https://siytek.com/how-to-split-home-assistant-configuration/

When I make changes to my yaml files and find errors it is almost always do to errors on my end not understand how the split is handled.