Confused MQTT config

Hello!

I have my heating from FHEM connected to HA via MQTT, and it works, i.e. I can read all defined values. I haven’t cared yet for writing values back, and this is not the topic here.

What puzzles me now is that (only now) I realise that I seem to have a redundant config for the MQTT sensor:

First, I have this in /homeassistant/configuration.yaml (just one MQTT sensor parameter shown as an example, there are more):

...
sensor: !include_dir_merge_list sensors
...
mqtt:
  sensor:
    - name: Mythz_outsideTemp
      state_topic: "fhem/Mythz/outsideTemp"
      unit_of_measurement: "°C"
      device_class: temperature

Second, I have this in /homeassistant/sensors/mqtt.yaml:

mqtt:
  sensor:
    - name: Mythz_outsideTemp
      state_topic: "fhem/Mythz/outsideTemp"
...

(obviously the same despite the lacking unit_of_measurement and device_class and thus redundant, as I see now)

As I set up the MQTT-related stuff a longer while ago, I do not remember why I did it like this, if it is correct (I doubt it), and which one of the two I should prefer.

I guess that the second one has advantages (I could add unit_of_measurement and device_class there, too), as it helps to keep oversight, which I was obviously lacking till now. :face_with_open_eyes_and_hand_over_mouth:

Thanks for sharing your thoughts and for your help! :heart:

Kind regards
7wells

This one is incorrect with include_dir_merge_list so is ignored. You might have errors on your log for this (or not :wink: )

1 Like

Yes, I just found out that after removing the config from configuration.yaml, the values of those entities became unavailable.

Would you mind letting me know what exactly is wrong with “outsourcing” the mqtt-related sensor as I did? Is my syntax wrong?

Each file in the directory should contain a list.

1 Like

I’m not sure what you mean and know the docu you kindly refer to (well, I thought I did :wink:).

My configuration.yaml contains this row:

sensor: !include_dir_merge_list sensors

In folder sensors I have various yaml files, one among them mqqt.yaml, which contains the aforementioned mqtt sensor definitions.

What is wrong with this?

Have a look at the example I linked, it might be more obvious.

1 Like

Ah, is it this?

It is important to note that when using !include_dir_merge_list, you must include a list in each file (each list item is denoted with a hyphen [-]). Each file may contain one or more entries.

That’s exactly what I said above :wink:

1 Like

Each file in the directory should contain a list.

Yep, I was not sure if I understood it correctly (not an English native speaker).

Thank you so much! :+1:

Hm, I am still unsure how to adopt the guidance …

It is important to note that when using !include_dir_merge_list, you must include a list in each file (each list item is denoted with a hyphen [-]). Each file may contain one or more entries.

… in my current (wrong) sensors/mqtt.yaml

mqtt:
  sensor:
    - name: Mythz_outsideTemp
      state_topic: "fhem/Mythz/outsideTemp"

… i.e., where and how to add a hyphen to make it a correct list.

I need to remove the sensor:, I assume, because the sensor is already defined (in configuration.yaml).

I looked for other examples and found this one:

However, there are multiple entries of - platform:, and I do not understand how that translates to my need of various mqtt definitions, e.g.:

mqtt:
  sensor:
    - name: Mythz_outsideTemp
      state_topic: "fhem/Mythz/outsideTemp"
      unit_of_measurement: "°C"
      device_class: temperature
    - name: Mythz_flowTemp
      state_topic: "fhem/Mythz/flowTemp"
      unit_of_measurement: "°C"
      device_class: temperature
    - name: Mythz_returnTemp
      state_topic: "fhem/Mythz/returnTemp"
      unit_of_measurement: "°C"
      device_class: temperature

EDIT: It seems that this thread, specifically this post, gets me going:

And I vaguely remember that back then (~2 years ago) I messed it all up. :face_with_open_eyes_and_hand_over_mouth: