Unique_id and object_id are being ignored in my MQTT sensor

I have a DHT22 temperature and humidity sensor running on a Raspberry Pi Zero which I want to be autodiscovered. So far autodiscovery is working albeit with two problems:

  1. The unique_id and object_id properties of my discovery payload are being ignored and no matter what I do, the entity ID is always derived from the name property.
  2. Since the entities were discovered with the wrong name, I wanted to delete them but I get the error "This entity ('sensor.temperature') does not have a unique ID, therefore its settings cannot be managed from the UI." which seems to be an issue that will be gone if I resolved the first problem.

None if this was ever done with YAML configs.

The MQTT config payload I’m using is the following one, though I’ve tried all possible combinations of object_id, and unique_id I could think of, even not having them there at all and only having them as part of the topic, as stated in the docs:

{
  "device_class": "temperature",
  "name": "Temperature",
  "object_id": "dht22_zero1",
  "unique_id": "dht22_zero1",
  "state_topic": "homeassistant/sensor/dht22_zero1/state",
  "unit_of_measurement": "°C",
  "value_template": "{{ value_json.temperature }}"
}

Some more context: I plan to deploy many of these sensors so when you see dht22_zero1 in the above payload, it means DHT22 (the sensor type) zero means Raspberry Pi Zero W, and 1 means the first Pi (there will be many). Ideally this can become a zero-config product that I can produce a mid-size batch of.

Have you tried deleting the device (in Integrations) rather than the entity?

Edit:

See this - similar question about removal just posted:

Hi @zoogara, thanks for the prompt reply. I don’t see them under devices, only under entities. However, as I was reading the docs for the Nth time I noticed that when sending a message to the config topic with an empty payload would delete the entity (which it did).

However, question number 1 in my original message still remains :frowning:

This is how the system works. It will only be derived from the unique_id of name is omitted. All of home assistant works this way.

Ah, it didn’t occur to me to try not including the name property. To be fair, that’s not what the docs say. In fact, the specific example in the docs has both, which is what I was trying:

{
  "name":"My Super Device",
  "object_id":"device1",
  "state_topic": "homeassistant/sensor/device1/state"
 }

It depends on the order in which you did things. If you created this originally with just the name and unique_id then the name would be taken and the unique_id would register the entity. Then any configuration changes would not update the entity_id as it’s already set in the registry.

That explains it then! Thank you so much for your insight. I’m not sure if you have write-access to the docs, but it feels like what you just said would be incredibly useful to have in there.

Hi,

Sorry, I´ve just found this thread and I think this is related with my issue also…
Apologize because I´m very new in mqtt and in HA in general…

Can give me some advice of my problem?

Please make a new post, your issue has nothing to do with this thread or the inclusion of unique_id. Entities without a unique_id have to be managed through yaml. That’s all that message is saying.

OK @petro I´ll do.

Any suggestion to post it in the correct place? I´m little bit lost regarding where to post it: mqtt; lovelace; etc.

Sorry about that, and thanks for your support.

When in doubt → #configuration

1 Like

Hi Petro, I have read this thread over and over and still can’t get an unique ID. Can you please help?

Topic: homeassistant/sensor/22b5ea03f787/config

Payload:

{
  "device_class":"temperature",
  "stat_t":"outdoor/backyd/Sens1/state",
  "unique_id":"22b5ea03f787"
}

Shows up as: sensor.mqtt_sensor

You can’t access the unique_id. If you want to name the sensor, add a name and a object_id to your payload. Otherwise rename the entity_id and name in the UI.

Thank you for your quick response! If I change the payload to:

{
  "device_class":"temperature",
  "name":"my_sensor",
  "object_id":"22b5ea03f787",
  "stat_t":"outdoor/backyd/Sens1/state",
  "unique_id":"22b5ea03f787"
}

It shows up as: sensor.22b5ea03f787 but I still can not manage (e.g. delete) it from the UI. I want the device to be managable from the UI, I know how delete it by sending an empty payload to the topic that I used to create it.

you can’t delete any entity from the UI, only orphaned entities. Yours won’t be orphaned because it was created by MQTT. You’re orphaning it when you send an empty payload. This is how all entities work in home assistant, not just MQTT. You’ll notice you can’t delete other entities either, only disable them.

Thank you for your clear explanation!