Structure configuration.yaml

Hi there,
I’m struggling to get my setup sorted. Got data from MQTT and create an entitie - so far so good.

This works fine:

mqtt:
  sensor: 
    - name: "Helligkeit aussen"
      unique_id: "Messwerte_Helligkeit_aussen"
      state_topic: "Messwerte/Helligkeit_aussen"
      device_class: illuminance
      unit_of_measurement: "lx"

now I like to split this section and store in a subfolder called “mqtt-setups”.
In this folder I’ve got “light.yaml” which contains the following


  sensor:
    - name: "Helligkeit aussen"
      unique_id: "Messwerte_Helligkeit_aussen"
      state_topic: "Messwerte/Helligkeit_aussen"
      device_class: illuminance
      unit_of_measurement: "lx"

and configuration.yaml modified to

mqtt: !include_dir_merge_list mqtt-setups

# mqtt:
#   sensor: 
#     - name: "Helligkeit aussen"
#       unique_id: "Messwerte_Helligkeit_aussen"
#       state_topic: "Messwerte/Helligkeit_aussen"
#       device_class: illuminance
#       unit_of_measurement: "lx"

YAML configuration test passes but I do not get the values back (“not available”).
I’m quit sure I have some syntax error however I have no clue what’s wrong?!

Any idea - guess it’s rather simple…

Thanks
Timo

Hey man, there is a better route to go down. Packages.

You want to move your topic specific configuration elements in files under <HomeAssistantConfig>/packages/heating-or-something.yaml. In order to load that file you need to also enable packages in your <HomeAssistantConfig>/configuration.yaml via the line:

packages: !include_dir_named packages.

This way yo are able to arrange your configuration in a truly structured way and it can grow and scale with your ambitions. The file configuration.yaml will stay unchanged going forward. My bigger setup has north to 60 files in a bunch of subfolders in packages and you wouldn’t be able to maintain those in another way.

Imho it does not make sense to structure your code by technical elements like switches/binary_sensors/automations but rather by use-case driven topics like heating, night-light or garage-door-automation…

Read:

Also see: Packages as a default part of the yaml based configuration

Probably the spacing. Get rid of the initial two spaces.

I have mine structured like this:

mqtt:
  sensor: !include_dir_merge_list mqtt/sensors
  binary_sensor: !include_dir_merge_list mqtt/binary_sensors
  switch: !include_dir_merge_list mqtt/switches

with mqtt/sensors/immersion.yaml starting:

- name: "Immersion switch overtemperature"
  state_topic: "shellies/shelly1pm-XXXXXX/overtemperature"