Developer: What is the proper way to name MQTT devices now?

Hey! I am maintaining a service which exposes Unraid OS servers state as mqtt entities for home assistant.

The service exposes each servers:

  • Virtual machine entities (turn on/off)
  • Docker container buttons (turn on, off, restart)
  • Server control buttons (power, array on, etc)

This works properly, a single container can manage multiple Unraid servers. Which is where the problem starts. Until now I would use the Server name as unique_id and device.name.

Considering that each server can expose the same container or VM. Now with the latest update I am not sure how I can make it work for multiple servers. Since I would need to set the unique name the server name to be able to differentiate the mqtt devices between two different servers. As of the latest update I get this error:

MQTT device name is equal to entity name in your config 

This is how it is setup:

      JSON.stringify({
        payload_on: "started",
        payload_off: "stopped",
        value_template: "{{ value_json.status }}",
        state_topic: `${env.MQTTBaseTopic}/${serverTitleSanitised}/${docker.name}`,
        json_attributes_topic: `${env.MQTTBaseTopic}/${serverTitleSanitised}/${docker.name}`,
        name: `${serverTitleSanitised}_docker_${docker.name}`,
        unique_id: `${serverTitleSanitised}_${docker.name}`,
        device: {
          identifiers: [serverTitleSanitised],
          name: serverTitleSanitised,
          manufacturer: server.serverDetails.motherboard,
          model: "Docker"
        },
        command_topic: `${env.MQTTBaseTopic}/${serverTitleSanitised}/${docker.name}/dockerState`
      }),
      { retain: env.RetainMessages }

My question is, how can I setup properly the names so it works for multiple servers and does not bother home assistant

Speculation is on:

What i understand is that, you need to supply different names for device and sensors and sensor names are generated on the fly with concetenation.

Device: bedroom multi sensor
Entities;

  • illuminance
  • Temperature

Speculation is off.

I don’t know :slight_smile:

Expansive thread on this. The first post also has links about all of this.

There is this post: The naming of MQTT entities changes to correspond with HA guidelines | Home Assistant Developer Docs

What I understood is that the name of the sensor must not have the device name in it.
Before:
Device name: XXX
Sensor name: XXX_YYY

Now:
Device name: XXX
Sensor name: YYY

So regarding your example, maybe remove “serverTitleSanitised” from “name:”

2 Likes