MQTT uniq_id not unique

As per my previous topic Observability, logging and MQTT I have enabled MQTT so that I can receive updates and store them centrally. I get all the “benefits” of using the API, however I don’t agree with them all and there are downsides also. I actually prefer MQTT myself. That said, I will be cutting back over to the API until the issue here is resolved.

It appears you can’t have multiple devices if you use MQTT since the uniq_id for all the entities is not actually unique. For example:

{
    "pos_t": "garage-door-opener-car/cover/garage_door/position/state",
    "set_pos_t": "garage-door-opener-car/cover/garage_door/position/command",
    "name": "Garage Door",
    "stat_t": "garage-door-opener-car/cover/garage_door/state",
    "cmd_t": "garage-door-opener-car/cover/garage_door/command",
    "avty_t": "garage-door-opener-car/status",
    "uniq_id": "ESPcovergarage_door",
    "dev":
    {
        "ids": "f412fa9c449c",
        "name": "Garage Door Opener Car",
        "sw": "esphome v2024.6.1 Jun 21 2024, 08:45:30",
        "mdl": "esp32-s3-devkitc-1",
        "mf": "espressif",
        "sa": ""
    }
}

and

{
    "pos_t": "garage-door-opener-workshop/cover/garage_door/position/state",
    "set_pos_t": "garage-door-opener-workshop/cover/garage_door/position/command",
    "name": "Garage Door",
    "stat_t": "garage-door-opener-workshop/cover/garage_door/state",
    "cmd_t": "garage-door-opener-workshop/cover/garage_door/command",
    "avty_t": "garage-door-opener-workshop/status",
    "uniq_id": "ESPcovergarage_door",
    "dev":
    {
        "ids": "34b7da6119d0",
        "name": "Garage Door Opener Workshop",
        "sw": "esphome v2024.6.1 Jun 21 2024, 08:36:25",
        "mdl": "esp32-s3-devkitc-1",
        "mf": "espressif",
        "sa": ""
    }
}

Also, I would recommend setting the two “name” fields to the same value so they are unique also.

You might not necessarily need this as I think my description above shows the issues. However, if this helps:

2024-06-23 03:56:47.820 ERROR (MainThread) [homeassistant.components.sensor] Platform mqtt does not generate unique IDs. ID ESPsensordevice_id already exists - ignoring sensor.garage_door_opener_car_device_id
2024-06-23 03:56:47.930 ERROR (MainThread) [homeassistant.components.sensor] Platform mqtt does not generate unique IDs. ID ESPsensorwifi_signal__ already exists - ignoring sensor.garage_door_opener_car_wifi_signal
2024-06-23 03:56:47.945 ERROR (MainThread) [homeassistant.components.sensor] Platform mqtt does not generate unique IDs. ID ESPsensorgarage_openings already exists - ignoring sensor.garage_door_opener_car_garage_openings
2024-06-23 03:56:47.953 ERROR (MainThread) [homeassistant.components.button] Platform mqtt does not generate unique IDs. ID ESPbuttonrestart already exists - ignoring button.garage_door_opener_car_restart
2024-06-23 03:56:48.024 ERROR (MainThread) [homeassistant.components.button] Platform mqtt does not generate unique IDs. ID ESPbuttonfactory_reset already exists - ignoring button.garage_door_opener_car_factory_reset
2024-06-23 03:56:48.028 ERROR (MainThread) [homeassistant.components.light] Platform mqtt does not generate unique IDs. ID ESPlightgarage_light already exists - ignoring light.garage_door_opener_car_garage_light
2024-06-23 03:56:48.054 ERROR (MainThread) [homeassistant.components.cover] Platform mqtt does not generate unique IDs. ID ESPcovergarage_door already exists - ignoring cover.garage_door_opener_car_garage_door
2024-06-23 03:56:48.128 ERROR (MainThread) [homeassistant.components.lock] Platform mqtt does not generate unique IDs. ID ESPlocklock already exists - ignoring lock.garage_door_opener_car_lock
2024-06-23 03:56:48.132 ERROR (MainThread) [homeassistant.components.binary_sensor] Platform mqtt does not generate unique IDs. ID ESPbinary_sensormotion already exists - ignoring binary_sensor.garage_door_opener_car_motion
2024-06-23 03:56:48.143 ERROR (MainThread) [homeassistant.components.binary_sensor] Platform mqtt does not generate unique IDs. ID ESPbinary_sensorobstruction already exists - ignoring binary_sensor.garage_door_opener_car_obstruction
2024-06-23 03:56:48.145 ERROR (MainThread) [homeassistant.components.binary_sensor] Platform mqtt does not generate unique IDs. ID ESPbinary_sensormotor already exists - ignoring binary_sensor.garage_door_opener_car_motor
2024-06-23 03:56:48.156 ERROR (MainThread) [homeassistant.components.binary_sensor] Platform mqtt does not generate unique IDs. ID ESPbinary_sensorwall_button already exists - ignoring binary_sensor.garage_door_opener_car_wall_button
2024-06-23 03:56:48.229 ERROR (MainThread) [homeassistant.components.switch] Platform mqtt does not generate unique IDs. ID ESPswitchlearn already exists - ignoring switch.garage_door_opener_car_learn
2024-06-23 03:56:48.232 ERROR (MainThread) [homeassistant.components.switch] Platform mqtt does not generate unique IDs. ID ESPswitchtoggle_only already exists - ignoring switch.garage_door_opener_car_toggle_only
2024-06-23 03:56:48.249 ERROR (MainThread) [homeassistant.components.select] Platform mqtt does not generate unique IDs. ID ESPselectsecurity__protocol already exists - ignoring select.garage_door_opener_car_security_protocol
2024-06-23 03:56:48.270 ERROR (MainThread) [homeassistant.components.button] Platform mqtt does not generate unique IDs. ID ESPbuttonpre-close_warning already exists - ignoring button.garage_door_opener_car_pre_close_warning
2024-06-23 03:56:48.331 ERROR (MainThread) [homeassistant.components.button] Platform mqtt does not generate unique IDs. ID ESPbuttonreset_door_timings already exists - ignoring button.garage_door_opener_car_reset_door_timings
2024-06-23 03:56:48.336 ERROR (MainThread) [homeassistant.components.button] Platform mqtt does not generate unique IDs. ID ESPbuttonre-sync already exists - ignoring button.garage_door_opener_car_re_sync

Read the docs Dan! :slight_smile:

If someone else comes across this and has the same question. Here is the answer:

Set “discovery_unique_id_generator: mac”

discovery_unique_id_generator (Optional, string): The unique_id generator to use. Can be one of legacy or mac. Defaults to legacy, which generates unique_id in format ESP<component_type><default_object_id>. mac generator uses format <mac_address>-<component_type>-<fnv1_hash(friendly_name)>.

Example:

mqtt:
  broker: mosquitto-prod.goepp.net
  username: !secret mqtt_user
  password: !secret mqtt_password
  discovery_unique_id_generator: mac

Also, make sure to remove the api: section as per the docs:

1 Like

You can also use !extend to manually specify the topic names for specific entities. Example:

cover:
  - id: !extend gdo_door
    name: My Unique GDO
    state_topic: my/unique/topic/state
    command_topic: my/unique/topic/command