I’m extensively using MQTT discovery in conjunction with ESP8266 devices. One thing that I found quite annoying and counterintuitive is that the entity id of discovered entities derived from the MQTT name without a way to change it. My friendly names are not necessarily globally unique (for example, I want to have an “Uptime” sensor for each device). Moreover, I’d like to have them in my local language but keep entity names etc. in English.
Since people using zigbee2mqtt / tasmota probably don’t want the entity id to be derived from the unique_id, my proposal is as follows: Add an optional field entity_id to the MQTT discovery message. If present, the homeassistant entity id is set to <platform>.<discovery json entity id>, requiring that this entity id is unique. Optionally, entity_id could be used as unique_id, too. If entity_id is not present, fall back to the “old” behaviour. This would mean that nothing changes for existing setups.
I think this should be quite easy to add, either in the generic entity id derivation function or in the one of MQTT mixins (I guess MqttAttributes). I’m not sure which is better though.
EDIT: Changed my proposal slightly since different use cases don’t want unique_id in their system.
That would be a nightmare, given the way tasmota and zigbee2mqtt create unique id’s. Tasmota -> unique id is derived from the Mac address, zigbee2mqtt -> unique id is derived from the IEEE address. We would end with totally incomprehensible entity id’s. Worst feature request ever !
At least in my case, zigbee2mqtt requires manually setting a name in either case (after all, how could it possibly know the name?). For me, it doesn’t really matter whether you edit the zigbee2mqtt yaml or change the entity id in homeassistant. And yes, the ids aren’t readable, but thats not the purpose of an (unique) ID. That’s what friendly names are for IMO.
Alternatively, MQTT discovery messages could be equipped with an additional “entity_id” field which is required to be unique if present.
I really think “friendly names” shouldn’t have any impact on the behaviour except display or as a fallback. However, I do see your point (I’m not working much with zigbee or tasmota). I’m adding dozens of devices via MQTT, each with several sensors, manually changing them is quite tedious and errorprone to be honest.
Let me reformulate my request. What I am missing is a way of setting sensor ids via MQTT. So maybe instead one could add an optional entity_id or similar to the MQTT message. Then, the entity_id is derived as <platform>.<entity_name>, requiring that this id is unique. Moreover, entity_id could then be used as unique_id, too. If entity_id is not set, fall back to the previous behaviour.
And I fully agree with @incaseoftrouble. There must be a way to set the entity ID separately.
The advantage of the discovery is that the entities get generated automatically. If I now have to manually remove the device name from the friendly name, I am almost faster on doing all manually without using the discovery!
But there seems to be an undocumented feature (or I get dump):
I added now the device name to the name and expected that each name then also has it. But it looks as if they remove the device name from the name again:
Looking on the documentation once more, it looks like as if it is not fully correct.
They clearly state that the object_id in the config topic is not used for the entity ID, how ever it looks as if they still use it that way!
In your screenshot I don’t see the sensors Friendly name. Is it now “SMA Grid Frequency” or “Frequency”? I want to have the later one. And it seems to work this ways although the documentation states differnetly.