MQTT Discovery Detecting Entities

Been reading posts and official documentation around MQTT device discovery and it really feels like I set it up right but MQTT never discovers a device as a device and will always treat it as an entity, even when it does find it with the discovery endpoint.

I am using the mosquitto MQTT broker which is connected just fine and can manually create sensor entries in the config.yaml. Now I wanted to swap that to use a device discovery so I changed my code to publish to

homeassistant/sensor/500291D66C79/config

It publishes the data:

{
  "name": "AQISensor",
  "device_class": "aqi",
  "state_topic": "device/aqi/500291D66C79",
  "device": {
    "identifiers": "aqi",
    "manufacturer": "SuperJonotron",
    "model": "PMS5003",
    "name": "PMS5003"
  }
}

Which shows up as an entity but doesn’t have a unique_id, which I defined when I did this for manual sensor readings. I see the entity reading the properly unparsed json packet form the state_topic defined so something is working but this shouldn’t be an entity, it should be a device. No devices show up in the mqtt service or device list.

What am I missing here?

Ensure it contains unique_id and the value for identifiers is a list.

{
  "name": "AQISensor",
  "device_class": "aqi",
  "state_topic": "device/aqi/500291D66C79",
  "unique_id": "put_something_unique_here",
  "device": {
    "identifiers": ["aqi"],
    "manufacturer": "SuperJonotron",
    "model": "PMS5003",
    "name": "PMS5003"
  }
}

For more information, refer to the example posted here:

Adding the unique_id created the device and one entity named by the config block. This helped make it clear that I’d have to make multiple config entries for the same device if I wanted to break out the json payload into individual readings but that’s a separate matter.

Now that the device is auto configuring though, if I wanted to manually map part of the paylod to a new entry with that device, what does that look like? Haven’t had success yet with things and my last attempt put home assistant into safe mode, a mode I didn’t know existed.

This will map a value out to a new entry but has no device relationship, but I can’t figure out how to associate it with the device.

mqtt:
  discovery: true
  sensor:
    - name: PM 1.0
      state_topic: device/aqi/500291D66C79
      object_id: 500291D66C79.pm1.0
      unique_id: 500291D66C79.pm1.0
      value_template: "{{ value_json.standard.pm10 }}"

I think I was wrong about manually connecting to the device via the yaml, the note concerning device only works during discovery I didn’t see before but now makes sense.

One thing that seems to not work though is when I added the object_id to the config json block. I assumed this would allow me to define the entity_id in the same way you do when manually creating entities but this appears to just completely block the discovery from working. Is this an expected result? Is there a different way to define the entity_id other than object_id during device discovery?