MQTT help needed 2022.3.8 > 2022.9.6 - only works in config.yaml?

Looking for some help here, after spending a lot of time preparing my system to be able to update to the latest version, I’m now stuck with one last issue - the Breaking MQTT change.

Everything MQTT working perfectly under 3.8 however moving to 9.6 this is where things just become a headache and I’ve tried my best getting this to work however there is something wrong or I am simply missing something and hoping someone can help.

Migrating my yaml files with the MQTT objects to the new syntax and HA saying it happy, I have switches and sensors that simply do not work when I use the “!include_dir_merge_list” format to keep the entries in separate files.

It will only work if I put everything in my configuration.yaml file (literally copy and pasting the info from my other yaml files - so the syntax is correct).

One thing I did notice is that I see conflicting info on here that when using “!include_dir_merge_list” and having the MQTT entries in a file I shouldn’t have the sensor or switch heading. eg. below:

This format in my “kitchen.yaml” file under sensor/mqtt directory makes the compiler check happy (HA reboot shows no errors) and Studio Code Server is ok with the syntax too:

sensor:
- name: "Kitchen Fridge kWh"
  state_topic: "tele/kitchen_fridge/SENSOR"
  icon: mdi:current-ac
  value_template: '{{ value_json.ENERGY.Today }}'
  unit_of_measurement: 'kWh'
  state_class: total_increasing
  device_class: energy

However everywhere I look in the community forums here it’s been stated to NOT have the “sensor:” part at the beginning of the yaml file - however removing this will cause the compiler check (when you go to reboot HA) to claim there is an error - however the error message is pointing to the line in configuration.yaml that has the newly added line:

mqtt:
  sensor: !include_dir_merge_list sensor/mqtt

So I’m at a loss on what to do - I do not want to have all my MQTT entries in my configuration.yaml file, however following any instruction I can find here I cannot get my sensors and switches to work with the merge_list option.

Any help would be fastastic!

Here is a post (marked as a solution) from a couple of releases ago that may help:

Well I finally got around to tackling this - I followed that link and it worked, that said the only thing that changed was the directory structure.

Instead of me using /sensor/mqtt and nesting my files there, I did as in the link and used /mqtt/sensor, etc

And then copied over my previous yaml files and then I was able to remove - sensor and everything worked.

Not sure why the inconsistency of the directory structure (or if maybe the latest update fixed something? Not sure if it was the same core version that I tried last time, OS was certainly newer), but since everything works this way I’m happy.