Adding multiple MQTT devices to Home assistant, each device separately

Hello experts, sorry if I asr a noob question, but I am new to Home Assistant.
I have searched for a solution below, but was not able to find the right solution.

currently I have 4 mqtt devices, for testing only used 2.
Every device publish multiple sensory data, humidity, temperature etc.

I am running: Supervisor Latest version and HassOS 3.13

When I have a single file containing all the published topics it works fine, I am receiving all the data from the devices, when I have a single file with all the topics.

what I like to have is a directory where can put all my separated MQTT-device-1.yaml, MQTT-device-2.yaml files in.

Done this far:
1: Created a directory mqtt-devices and saved both the MQTT-device-1.yaml and MQTT-device-2.yaml file in this directory.

The device files are containing:

  • platform: mqtt
    name: “sn-163: Location”
    entity_id: “sensor.location_sn-163”
    state_topic: “sn-163/fd/Location”
    unit_of_measurement: ‘Location’
    unique_id: “sn-163: Location”
    icon: mdi:map-marker-outline
    availability_topic: “sn-163/fd/availability”
    payload_available: “online”
    payload_not_available: “offline”

  • platform: mqtt
    name: “sn-163: Temperature”
    entity_id: “sensor.temperature_163”
    state_topic: “sn-163/fd/Temperature”
    unit_of_measurement: ‘C’
    unique_id: “sn-163: Temperature”
    icon: mdi:temperature-celsius
    availability_topic: “sn-163/fd/availability”
    payload_available: “online”
    payload_not_available: “offline”

I have tried the following:
First in the configuration.yaml:

mqtt:
broker: 192.168.0.3
keepalive: 60
discovery: true
discovery_prefix: homeassistant

sensor:

  • platform: mqtt
    sensor: !include_dir_list sensors

error message is: Configuration invalid
Component error: sensors - Integration ‘sensors’ not found.

I also tried:
mqtt:
broker: 192.168.0.3
keepalive: 60
discovery: true
discovery_prefix: homeassistant
sensor: !include_dir_list sensors

gives: Configuration invalid
Invalid config for [mqtt]: [sensor] is an invalid option for [mqtt]. Check: mqtt->mqtt->sensor. (See /config/configuration.yaml, line 49).

Try MQTT discovery it might solve your problem

Thanks for the suggestion, as I am coding the esp8266 my self as a learning project.
I have not figured-out how the discovery exactly work. I know it is the best solution.

I have read the document you have pointed me to, countless times. but till this fare, I was not able to get it working (yet) this has to be with the lack of knowledge of the MQTT and HA protocol and environment.

But for now my testing would be much easier if i have the device seperation in place.

It won’t work that way.

Try in configuration.yaml :

sensor: !include_dir_merge_list sensors/

and then each file :

  - platform: mqtt
    name: "xxx"
    state_topic: "xxx"
    etc... 
1 Like

Crafting a mqtt discovery message is not so difficult.

This is an example for a auto-discovery message

topic : homeassistant/binary_sensor/garagedoor/config

'{"name": "garagedoor", "device_class": "garage_door", "state_topic": "sensor/garagedoor", "unique_id": "garagedoor", "off_delay": 30, "device": {"identifiers": ["rfbridge_564886"],"name": "garagedoor", "model": "Digoo door sensor", "manufacturer": "Digoo"}}'

Let me try.

The mqtt discovery indeed does not look complicated, however for some reason it does not work very well with the mqtt library of Adafruit_MQTT

This solution worked. thank you so much.

I tried all the options mentioned in this document:

  • !include_dir_list
  • !include_dir_named
  • !include_dir_merge_list
  • !include_dir_merge_named

but this was the solution. ```
sensor: !include_dir_merge_list sensors/ the added slash.

I think the documentation should be more clearer on this.

1: create a directoy sensors

add in the file configuration.yaml the following line:
sensor: !include_dir_merge_list sensors/

all your sensor configurations ending on .yaml will be included

1 Like

And please don’t post the same (or very similar) problem twice in different threads.

I just spent time answering in your other thread only to find you found the solution here. So I wasted my time there.

First of all I hope your answer does not reflect the kindness of this forum.

I surly don’t want to waste your time as I can understand you can spent your time better. Same for me.

I have addressed 2 different issues.
1: is the include statement in the configuration.yaml
2: is the separation method according to the page I was referring to, and therefor a different method.

In the documentation about the include is not a clear statement the last slash has to be added. thanks for mention this. This was splitting up configuration into different files.

The other one is splitting up one file into different understand that the 2 method’s can’t be mixed.

I will be more careful to ask beginners questions and to learn more about Home Assistant.

2 Likes