MQTT Discovery - How to realize?

Hello,

I send the data from my gas boiler to Home Assistant via MQTT. Now every data set is an own entity, but there is no device for my gas boiler. As far as I read, there is especially for the the MQTT-Discovery-function in Home Assistant. Unfortunately I don’t get it to work. Can you please support me?

I am using the Mosquito Broker inside Home Assistant and the entry in my configuration file looks like this:

mqtt:
  sensor:
    - name: "vitodens_Betriebsart"
      unique_id: vitodens_Betriebsart
      state_topic: "mqttGenericBridge/Vitodens200W/Betriebsart"
    - name: "vitodens_Aussentemperatur"
      unique_id: vitodens_Aussentemperatur
      state_topic: "mqttGenericBridge/Vitodens200W/Aussentemperatur"
      unit_of_measurement: "°C"
    - name: "vitodens_Brennerlaufzeit"
      unique_id: vitodens_Brennerlaufzeit
      state_topic: "mqttGenericBridge/Vitodens200W/Brennerlaufzeit"
      unit_of_measurement: "h"
    - name: "vitodens_Brennerlaufzeit_Today"
      unique_id: vitodens_Brennerlaufzeit_Today
      state_topic: "mqttGenericBridge/Vitodens200W/Brennerlaufzeit_Today"
      unit_of_measurement: "h"
    - and so on

What device is sending the boiler mqtt data?

Can you program it to publish discovery mqtt messages?

Its a smarthome server called FHEM. The device in FHEM asks for the data of the boiler every 300 seconds and sends the data through MQTT.


The topic that is sent is for instance:
2023-12-22 08_44_51-Window
How does the message have to look like, to fit for a discovery mqtt message?

https://www.home-assistant.io/integrations/mqtt/#mqtt-discovery

Thank you. I already knew that description. But somehome it goes above my small understanding… Do you have an idea, how the MQTT message could look like in my special case?

Right now I configured the MQTT message that is sent to this format, which does not work:
2023-12-22 09_51_06-Window

I think I’m on the wrong track due to my lack of understanding of the matter

Hi,
I’ve experience in writing MQTT discovery for several projects to implement auto-discovery down to icons and suggested area names. There’s a few posts on this forum on this matter, so I’d suggest a few links and the forum search.

Do you have an idea, how the MQTT message could look like in my special case?

It looks like several hot beverages of your choice :coffee:, the documentation, the above examples, and several prototypes you publish and experiment with something like mosquitto_pub!

It’s not as hard as it looks; it just takes a few tests which happily give instant results in HASS giving a very fast debug-cycle (HINT: delete retained topics to remove test data to clean up afterwards).

If this helps, :heart: this post!

1 Like

Hi,

I am not sure if your main objective is to group the entities as a device, or if it is to enable auto discovery.

If the main objective is to group them as a device, try something like the following, where you add the device section to each of the entities, such that Home Assistant can now that they belong to the same device. I just used a random name and identifier in the below.

mqtt:
  sensor:
    - name: vitodens_Betriebsart
      unique_id: vitodens_Betriebsart
      state_topic: mqttGenericBridge/Vitodens200W/Betriebsart
      device:
        name: "Vitodens"
        identifier: "1232"
    - name: vitodens_Aussentemperatur
      unique_id: vitodens_Aussentemperatur
      state_topic: mqttGenericBridge/Vitodens200W/Aussentemperatur
      unit_of_measurement: °C
      device:
        name: "Vitodens"
        identifier: "1232"
    - name: vitodens_Brennerlaufzeit
      unique_id: vitodens_Brennerlaufzeit
      state_topic: mqttGenericBridge/Vitodens200W/Brennerlaufzeit
      unit_of_measurement: h
      device:
        name: "Vitodens"
        identifier: "1232"
    - name: vitodens_Brennerlaufzeit_Today
      unique_id: vitodens_Brennerlaufzeit_Today
      state_topic: mqttGenericBridge/Vitodens200W/Brennerlaufzeit_Today
      unit_of_measurement: h
      device:
        name: "Vitodens"
        identifier: "1232"

There are a description of the device info that can be included here: MQTT Sensor - Home Assistant

You are right, the main goal would really be to group them as a device. Unfortunately this entry does not work. It shows me an error when loading the mqtt entities:

I tried

  sensor:
    - name: "vitodens_Betriebsart"
      unique_id: vitodens_Betriebsart
      device:
        name: "Vitodens200W"
        identifier: 123

and also

  sensor:
    - name: "vitodens_Betriebsart"
      unique_id: vitodens_Betriebsart
      device:
        - name: "Vitodens200W"

I made a typo. it should be identifiers with an s at the end.

Try this:

mqtt:
  sensor:
    - name: vitodens_Betriebsart
      unique_id: vitodens_Betriebsart
      state_topic: mqttGenericBridge/Vitodens200W/Betriebsart
      device: 
        name: "Vitodens"
        identifiers: "1232"
    - name: vitodens_Aussentemperatur
      unique_id: vitodens_Aussentemperatur
      state_topic: mqttGenericBridge/Vitodens200W/Aussentemperatur
      unit_of_measurement: °C
      device:
        name: "Vitodens"
        identifiers: "1232"
    - name: vitodens_Brennerlaufzeit
      unique_id: vitodens_Brennerlaufzeit
      state_topic: mqttGenericBridge/Vitodens200W/Brennerlaufzeit
      unit_of_measurement: h
      device:
        name: "Vitodens"
        identifiers: "1232"
    - name: vitodens_Brennerlaufzeit_Today
      unique_id: vitodens_Brennerlaufzeit_Today
      state_topic: mqttGenericBridge/Vitodens200W/Brennerlaufzeit_Today
      unit_of_measurement: h
      device:
        name: "Vitodens"
        identifiers: "1232"

Works here :slight_smile:

Thank you, that did the job :slight_smile:

1 Like