How to use MQTT Discovery "Device" Attribute

I have an MQTT enabled “legacy” home automation system that controls (yes, really old!) X-10 switches, IR, inputs and outputs, etc., so it acts as a “hub” for these devices/functions.

I’ve added a discovery feature to it that exposes several dozen devices controlled by the system to Home Assistant via MQTT Discovery. This all works well.

However, I have questions about one part of the discovery payload: the “Device” variable. I would like to use this to indicate that a particular device (say an X-10 light) is associated with this “hub”.

Here are my questions:

  1. Does it make sense to use this attribute of the discovery payload to “connect” all of the resulting individual devices/entities to this “hub”? I would like to do this if possible and if it makes sense to do so. But it is optional for me, as the current discovery works otherwise.

If so:

  1. What should I use for the “Identifiers” attribute: one identical “id” for all entities or a separate id for each entity? If one “id”, how to define that “hub” device to have that “id”?
  2. How does the “via Device” attribute work? I assume that the purpose of it is to get the entity associated with a device that is defined as the “hub”. However, if my assumption is correct, I don’t know how to define the “hub” as a device in Home Assistant.

I’ve looked through the docs and issues, but have not found any discussion of how the “Device” attribute or its sub attributes as in #2 and #3 actually are used in practice.

It’s highly probable that I completely misunderstand how this is supposed to be used.

Thanks!

1 Like

Any luck figuring this one out? I am having the same problem… all my sensors end up in the same ha device

Here’s how I configured discovery for my controller system for my temp sensors and analog inputs. See the “device” part. For those devices you want to group together, use the same “identifiers”. For the ones I show here, the DTS sensors all show up under a device called “HomeVision Temp”, while the analog ones show up under “HomeVision Analog”. (The HVXLb1d0d912ed315aad" part is a unique id my system generates, but is the same for all device types. To make it unque to a device, I add the device type. E.g., “HVXLb1d0d912ed315aad_Temp” for allTemp sensors.)

Digital Temp Sensors:

Topic:

homeassistant/sensor/HVXLb1d0d912ed315aad_TE-0/config

Payload:

{
        "unique_id": "HVXLb1d0d912ed315aad_TE-0",
        "name": "TE-0 Digital_temp_sensor_0",
        "state_topic": "stat/Digitaltempsensor0/RESULT",
        "value_template": "{{ value_json.STATE }}",
        "unit_of_measurement": "F",
        "device_class": "temperature",
        "qos": 1,
        "device": {
                "identifiers": [
                        "HVXLb1d0d912ed315aad_Temp"
                ],
                "name": "HomeVision Temp",
                "model": "HomeVision",
                "manufacturer": "CustomSolutions"
        }
}

Analog Inputs:

Topic:

homeassistant/sensor/HVXLb1d0d912ed315aad_AN-0/config

Payload:

{
        "unique_id": "HVXLb1d0d912ed315aad_AN-0",
        "name": "AN-0 Analog_Input_0",
        "state_topic": "stat/AnalogInput0/RESULT",
        "value_template": "{{ value_json.STATE }}",
        "device_class": "battery",
        "qos": 1,
        "device": {
                "identifiers": [
                        "HVXLb1d0d912ed315aad_Analog"
                ],
                "name": "HomeVision Analog",
                "model": "HomeVision",
                "manufacturer": "CustomSolutions"
        }
 }