How to format the JSON in MQTT Discovery

Currently I am developing home automation components with the usage of MQTT. Since a “plug and play” user experience is wanted I am using the MQTT Discovery for the registration of the components to Home Assistant.

However since Home Assistant 2023.8 I have some issues with this set-up. My current UI looks like this. (with the automatic/default dashboard active)


Note: the current temperature is a hardware issue.

The “Server” room should contain the following:

  • 1 Light
  • 1 Security door (cover) (missing)
  • 2 Binary sensors (connected to the cover for remote IO)

The “Toilet” room should contain the following:

  • 1 Light (placed in the “Server” room)
  • 1 Button
  • 1 Window (placed in the “Server” room)
  • 1 Occupancy sensor (placed in the “Server” room)

The “Livingroom” room should contain the following:

  • 1 Dimable light (named Main)
  • 1 Climate
  • 2 Binary sensors (connected to the climate for remote IO)

Each of these components has a mqtt path as described in the documentation eg. <discovery_prefix>/<component>/[<node_id>/]<object_id>/config. (see below)

A few of the problematic components are as follows.
The cover (that is missing), has the topic homeassistant/cover/server/security/config and the following JSON

{
  "name": "Security",
  "unique_id": "serversecurity",
  "object_id": "serversecurity",
  "device_class": "Door",
  "state_topic": "homeassistant/cover/server/security/state",
  "command_topic": "homeassistant/cover/server/security/command",
  "availability": {
    "topic": "homeassistant/status/server"
  },
  "device": {
    "identifiers": [
      "Server",
      "Security"
    ],
    "manufacturer": "company",
    "model": "controller",
    "suggested_area": "Server"
  }
}

My 2 (problematic) lights have the following config
homeassistant/light/toilet/light/config

{
  "name": "Light",
  "unique_id": "toiletlight",
  "object_id": "toiletlight",
  "device_class": "light",
  "command_topic": "homeassistant/light/toilet/light/command",
  "state_topic": "homeassistant/light/toilet/light/state",
  "availability": {
    "topic": "homeassistant/status/woonkamer"
  },
  "device": {
    "identifiers": [
      "Toilet",
      "Light"
    ],
    "manufacturer": "company",
    "model": "controller",
    "suggested_area": "Toilet"
  }
}

homeassistant/light/server/light/config

{
  "name": "Light",
  "unique_id": "serverlight",
  "object_id": "serverlight",
  "device_class": "light",
  "command_topic": "homeassistant/light/server/light/command",
  "state_topic": "homeassistant/light/server/light/state",
  "availability": {
    "topic": "homeassistant/status/server"
  },
  "device": {
    "identifiers": [
      "Server",
      "Light"
    ],
    "manufacturer": "company",
    "model": "controller",
    "suggested_area": "Server"
  }
}

What I want to accomplish are the following points.

  • A separation between the different components. So that, with the default dashboard active, all the components that are made for a suggested_area aso end-up in their respective suggested_area.
  • Get rid of the “Mosquitto broker” part of the name (this should be somewhere in the release notes of 2023.8 but I didn’t have time to implement that (yet)).
  • Understand how do the identifiers portion works.

The issue I am facing is that, although there is a lot of documentation most/all of it is indented for yaml instead of json.

There is 1 more generic question about the availability of the device. This seems defined twice. The 1st is under availability → topic and the 2nd is under availability_topic. What is the correct way to handle this?
Note that the current system (availability → topic) works as intended.
Edit: I should read better. The text under availability_topic reads.

Must not be used together with availability

:man_facepalming:

Ok, so far I fixed 1 issue with my json. This is my current dashboard.

I Forgot to use the devicename element. So for my 2 lights I updated the config (and added the via_device element).
This has fixed the "Mosquitto broker” part of the name. However the still sharing the name and room.

homeassistant/light/toilet/light/config

{
  "name": "Light",
  "unique_id": "toiletlight",
  "object_id": "toiletlight",
  "device_class": "light",
  "command_topic": "homeassistant/light/toilet/light/command",
  "state_topic": "homeassistant/light/toilet/light/state",
  "availability": {
    "topic": "homeassistant/status/woonkamer"
  },
  "device": {
    "name": "Toilet",
    "identifiers": [
      "Toilet",
      "Light"
    ],
    "manufacturer": "company",
    "model": "controller",
    "suggested_area": "Toilet",
    "via_device": "woonkamer"
  }
}

and homeassistant/light/server/light/config

{
  "name": "Light",
  "unique_id": "serverlight",
  "object_id": "serverlight",
  "device_class": "light",
  "command_topic": "homeassistant/light/server/light/command",
  "state_topic": "homeassistant/light/server/light/state",
  "availability": {
    "topic": "homeassistant/status/server"
  },
  "device": {
    "name": "Server",
    "identifiers": [
      "Server",
      "Light"
    ],
    "manufacturer": "company",
    "model": "controller",
    "suggested_area": "Server",
    "via_device": "server"
  }
}