Can't figure out the use of include for MQTT sensor for partial sensors

Hello all, here again.
In my configuration.yaml I have several sensor that I would like to keep there, but I would like to add others from another file.
My mqtt section looks like:

mqtt:
  sensor:
    - name: firstone
      state_topic: "homeassistant/sensor/firstone/state"
      unit_of_measurement: "W"
      unique_id: watt_firstone
      device_class: power
    - name: secondone
      state_topic: "homeassistant/secondone/temperature"
      unit_of_measurement: "°C"
      device_class: temperature
      unique_id: temp_secondone

and so on.
I have created a file that I would like to include.
The file is called “otherfile.yaml” whose content is:

- name: thirdone
  state_topic: "homeassistant/sensor/firstone/state"
  unit_of_measurement: "W"
  unique_id: hum_thirdone
  device_class: humidity
- name: fourthone
  state_topic: "homeassistant/sensor/fourthone/state"
  unit_of_measurement: "kWh"
  unique_id: energy_fourthone
  device_class: energy

I have tried in many way to add an include for it but so far without success.
I have tried :

mqtt:
  sensor:
    - name: firstone
      state_topic: "homeassistant/sensor/firstone/state"
      unit_of_measurement: "W"
      unique_id: watt_firstone
      device_class: power
    - name: secondone
      state_topic: "homeassistant/secondone/temperature"
      unit_of_measurement: "°C"
      device_class: temperature
      unique_id: temp_secondone
    - !include otherfile.yaml

or

...
...
      unique_id: temp_secondone
      !include otherfile.yaml

or several combination, but I can’t make it works.
I get errors from:
Invalid config for ‘mqtt’ at configuration.yaml, line 43: expected dict ‘mqtt->0->sensor->0’, got None
to
Error loading /config/configuration.yaml: mapping values are not allowed here in “/config/configuration.yaml”, line 52, column 11
if I remove the dash.

How I’m supposed to make this working ?
Please, if you don’t mind, let’s stay on this. I’m not willing to modify all sensors in a dir or the like, at the moment.
Thanks in advance
Pierluigi

Hi Pierluigi,

This is one way…

I do it a bit different…
Configuration.yaml:


mqtt:
  - binary_sensor: !include_dir_merge_list mqtt/binary_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/
  - sensor: !include_dir_merge_list mqtt/sensor/
  - switch: !include_dir_merge_list mqtt/switch/

and the folder structure:
Home-Assistant-Config/mqtt at master · SirGoodenough/Home-Assistant-Config · GitHub.

It’s a dictionary of lists.