MQTT Configuration Core 2022.6.6

I just upgraded to Home Assistant Core 2022.6.6 (from 2022.5.5) but i cannot completly figure out the new style of MQTT configuration.

The configuration.yaml

mqtt: !include_dir_merge_list mqtt/

Example of mqtt/voordeur_deurbel.yaml

binary_sensor:
  - name: "Voordeur_Deurbel"
    state_topic: "shellies/shellyuni-483FDA82C3FF/input/0"
    payload_on: "1"
    payload_off: "0"

  - name: "Voordeur_Magneetcontact"
    state_topic: "shellies/shellyuni-483FDA82C3FF/input/1"
    payload_on: "1"
    payload_off: "0"

  - name: "Voordeur_Online"
    state_topic: "shellies/shellyuni-483FDA82C3FF/online"
    payload_on: "true"
    payload_off: "false"

But it looks like the sensors are now missing

I think (not 100%) that it’s because that’s not a list. Try:

mqtt: 
  sensor: !include_dir_merge_list mqtt/
- name: "Voordeur Deurbel"
  state_topic: "shellies/shellyuni-483FDA82C3FF/input/0"
  payload_on: "1"
  payload_off: "0"

- name: "Voordeur Magneetcontact"
  state_topic: "shellies/shellyuni-483FDA82C3FF/input/1"
  payload_on: "1"
  payload_off: "0"

- name: "Voordeur Online"
  state_topic: "shellies/shellyuni-483FDA82C3FF/online"
  payload_on: "true"
  payload_off: "false"

Not sure, but I think after the include is performed, what HA will see from your config is:

mqtt:
binary_sensor:
  - name: "Voordeur_Deurbel"
    state_topic: "shellies/shellyuni-483FDA82C3FF/input/0"
    payload_on: "1"
    payload_off: "0"

  - name: "Voordeur_Magneetcontact"
    state_topic: "shellies/shellyuni-483FDA82C3FF/input/1"
    payload_on: "1"
    payload_off: "0"

  - name: "Voordeur_Online"
    state_topic: "shellies/shellyuni-483FDA82C3FF/online"
    payload_on: "true"
    payload_off: "false"

So it probably thinks mqtt is empty and binary_sensor has lots of items.
Perhaps indent your voordeur_deurbel.yaml file, so that it looks like:

#mqtt binary sensors
  binary_sensor:
    - name: "Voordeur_Deurbel"
      state_topic: "shellies/shellyuni-483FDA82C3FF/input/0"
      payload_on: "1"
      payload_off: "0"

    - name: "Voordeur_Magneetcontact"
      state_topic: "shellies/shellyuni-483FDA82C3FF/input/1"
      payload_on: "1"
      payload_off: "0"

    - name: "Voordeur_Online"
      state_topic: "shellies/shellyuni-483FDA82C3FF/online"
      payload_on: "true"
      payload_off: "false"

After some fiddling around i changed to the following include and this seems to be working

mqtt:
  binary_sensor: !include_dir_merge_list mqtt/binary_sensor/
  sensor: !include_dir_merge_list mqtt/sensor/
  button: !include_dir_merge_list mqtt/button/
  cover: !include_dir_merge_list mqtt/cover/
  fan: !include_dir_merge_list mqtt/fan/
  light: !include_dir_merge_list mqtt/light/
  lock: !include_dir_merge_list mqtt/lock/
  switch: !include_dir_merge_list mqtt/switch/

and for example the Doorbell Shelly Uni

root@knopjes02:/home/homeassistant/.homeassistant/mqtt# cat binary_sensor/voordeur_deurbel.yaml 
  - name: "Voordeur_Deurbel"
    state_topic: "shellies/shellyuni-483FDA82C3FF/input/0"
    payload_on: "1"
    payload_off: "0"
    icon: mdi:doorbell


  - name: "Voordeur_Magneetcontact"
    state_topic: "shellies/shellyuni-483FDA82C3FF/input/1"
    payload_on: "0"
    payload_off: "1"
    device_class: door

  - name: "Voordeur_Online"
    state_topic: "shellies/shellyuni-483FDA82C3FF/online"
    payload_on: "true"
    payload_off: "false"
    device_class: connectivity
root@knopjes02:/home/homeassistant/.homeassistant/mqtt# 

root@knopjes02:/home/homeassistant/.homeassistant/mqtt# cat sensor/voordeur_deurbel.yaml 
  - name: "Voordeur_Temperatuur"
    state_topic: "shellies/shellyuni-483FDA82C3FF/ext_temperatures"
    expire_after: 86400
    qos: 1
    device_class: temperature
    unit_of_measurement: '°C'
    icon: mdi:home-thermometer-outline
root@knopjes02:/home/homeassistant/.homeassistant/mqtt# 

The temperatur sensor needs some additional config to strip

{"0":{"hwID":"2843446b050000f5","tC":34.5}} °C

But for know my house is working like it was when running 2022.05.05

1 Like

From splitting up the configuration:

!include_dir_merge_list will return the content of a directory as a list by merging all files (which should contain a list) into 1 big list

So this:

mqtt: !include_dir_merge_list mqtt/

will fail for multiple reasons:

  1. The example shown of a file in this folder is not a list. So !include_dir_merge_list will fail on it.
  2. !include_dir_merge_list makes a list. But mqtt wants a dictionary. So even if you make every file in the mqtt folder a list its still going to be invalid.

Has nothing to do with tabbing in the file.

@raymonvdm your latest looks good. Although just an FYI, discussions on the release thread for 2022.6 made me (and many others) aware of the huge performance cost of using YAML-defined MQTT entities over ones created by MQTT discovery during restart. See here for the post where Taras helped a user reduce their startup time by a full minute simply by switching defining MQTT entities in YAML to using a script to create MQTT discovery messages.

If you are splitting up your MQTT config this much I figured you probably have a lot of MQTT entities and so this might be something you’re interested in.

Thank you very much @raymonvdm for this solution. :+1:

Using include_dir_merge_named instead of include_dir_merge_list makes it possible to put all MQTT integrations in one place, just like author wanted in first post.