MQTT Sensor configuration payload and entity ID vs Name?

Doing a special purpose sensor for a telescope, and have it creating sensors through an MQTT broker. Very neat.

One minor issue I can’t resolve. In the JSON that I send to home assistant to do the configuration I have it working but one thing I want to change. Here is an example:

{
  "unit_of_measurement": "°C",
  "icon": "mdi:thermometer",
  "name": "Telescope Ambient Temperature",
  "state_topic": "telescope/sensor/telescope_temp/state",
  "unique_id": "telescope_temp",
  "availability_topic": "telescope/status",
  "device": {
    "identifiers": "abc1ae10d154",
    "name": "telescope",
    "sw_version": "weather pre alpha",
    "model": "rPi3B",
    "manufacturer": "lef"
  }
}

My issue is that the entity ID in HA is coming in as “sensor.telescope_ambient_temperature” drawn from the name. I do not see that the unique_id is used (though maybe under the covers).

Is there a way to set the textual display name in HA separately from the sensor entity id name, i.e. I want:

sensor.telescope_temp = "Telescope Ambient Temperature".

Is there a way to do it?

Is there a specification for the format of these JSON configuraiton strings?

Yes, I realize I can go in afterwards inside HA and make this change, I would like to send it properly in the first place.

Thanks,

Linwood

What you are thinking of is known as friendly_name and it you can’t specify it via MQTT Discovery. It uses name for friendly_name and to create the sensor’s object_id (that’s the telescope_ambient_temperature in sensor.telescope_ambient_temperature.

After the sensor has been created via MQTT Discovery, you can edit its options by going to Configuration > Entities and clicking on the desired sensor.

Customizations can also be done using manual configuration in a file.

1 Like

OK, was hoping the MQTT JSON config string could set it, guess not. Thank you!

There is a feature request exactly for this: https://community.home-assistant.io/t/mqtt-discovery-allow-setting-the-entity-id-via-disovery-message
Sadly the dev’s do not see the need for it :frowning: