MQTT Discovery: How to set the sensor name in the MQTT message

I have read MQTT Discovery: single component

Implemented and it is working almost perfectly. I have 1 device with 3 sensors that magically appear as below.

The problem I am having setting the sensor name. As you can see, all 3 sensors are MQTT Sensor

Here is the MQTT message for one of the sensors

{
  "dev": {
    "mdl": "LHT52",
    "ids": "5390B0",
    "name": "T3S3",
    "mf": "Dragino"
  },
  "o": {
    "name": "T3S3"
  },
  "val_tpl": "{{value_json['LwDecoded']['LHT52']['TempC_Internal']}}",
  "unit_of_meas": "°C",
  "stat_t": "tele/LWG-T3S3_5390B0/SENSOR/A840414E4F5CAE3D",
  "device_cla": "temperature",
  "pl_avail": "Online",
  "ic": "mdi:thermometer",
  "state_cla": "measurement"
  "avty_t": "tele/LWG-T3S3_5390B0/LWT",
  "pl_not_avail": "Offline",
  "uniq_id": "tasmota_34B7DA5390B0_TempC_Internal",
  "name": "test",
}

Suggestions?

  1. This is not proper json (the comma is only valid if there actually is a field following up)
  2. Even if you fix this, I think the name is set when the entity is created, so likely too late to change it via MQTT, you’ll have to do it manually

Thanks: Your comment that the name is set when the entity is created was the clue.

  • Deleted the device and sensors in HA
  • Resent MQTT discovery message.
  • Sensors now have the name set from the JSON

Thanks for your help

Just pointing out for others that its not necessary to delete devices from HA, per the documentation (link below) you can:

To remove the components, publish an empty (retained) string payload to the discovery topic. This will remove the component and clear the published discovery payload. It will also remove the device entry if there are no further references to it.

However the other comments are correct:
AutoDiscovery doesn’t really implement updates, you have to delete (via the method above) and re-add devices to force HA to reflect any changes you want to make.