Proposition of change how the entity id is generated

Hello,

I have been starting to set up HA, I have already running MQTT server to which connects a lot of ESPs.

The problem:
While adding all devices using files (because I have the control myself), I found extremely annoying how the entity id is generated. I have (for now) 3 power meters (based on ESP8266/8285), and when I set the sensor (MQTT) name “Current” for each one (that is the name I want to use) , I got 3 entities:

  • sensor.current
  • sensor.current_2
  • sensor.current_3

And HOW in the hell I suppose to know which “Current” is for which power meter?
(in files I know which one is which)

Current solution:
Change it’s name - this is really dumb solution :expressionless: (and this looks ugly/primitive/stupid in UI later)

My suggestion:
There is possible to define variable https://www.home-assistant.io/integrations/sensor.mqtt/#unique_id (but it’s not really used as I see)
So why not to use this to generate entity id , of course when it’s specified in config file.

I have in file e.g.:

- platform: mqtt
  name: "Current"
  unique_id: "ESP.HYK.SE0111.111B1B-1111.I"
  state_topic: "home/esp/hykker1/SENSOR"
  value_template: '{{ value_json["ENERGY"]["Current"] }}'
  unit_of_measurement: "A"

so the entity could be:

sensor.ESP_HYK_SE0111_111B1B_1111_I

I suggest to introduce (or test) this first in mqtt sensor (since there is already variable to set in sensor definition), then eventually introduce it to other (binary_)sensor integrations and maybe other elements too (e.g. switches).

I guess that you could argue that some people would want the name to be used, even if they also set a unique id. Besides, using the name to base the entity id on is common throughout HA, so to change that behaviour might be confusing.

You could use name to contain a uniquely identifiable string, and then set friendly_name to “Current” for each of your sensors:

# in configuration.yaml
customize:
  sensor.ESP_HYK_SE0111_111B1B_1111_I:
    friendly_name: Current

When you flash you have the opportunity to set a name, each one can be different.
You either have the work at the beginning and/or at the end, your choice.
But if you click on an item in the UI, the entities list for example, you can then click on the cog (top right) and you can change the entity id from there so entity_id: sensor.current_2 (or sensor.ESP_HYK_SE0111_111B1B_1111_I in your case) could become sensor.current_bedside_lamp
You need to keep the domain the same though

When writing code sensor.ESP_HYK_SE0111_111B1B_1111_I would mean less than nothing to me but sensor.current_bedside_lamp has meaning. Thus when reading the code you can picture the elements and the actions and achieve better understanding both now and when you come back to it in 6 months

@robertklep So what is the purpose of “unique id” - for now it do nothing really?

I did not was aware of this approach, more intuitive for me seems the way I suggested - since there is that unique id (I was hoping that will be used as entity id :frowning_face: ) .
I might be unaware of this because for now I add everything to HA, later I’ll be organizing it.
(but having 2 files might be a bit irritating :face_with_monocle: )

@Mutt I have mind of programmer/engineer It’s easier for me to identify device by this example than using “human understandable name” :grin: - so when I see suffix “_2 … _3 … _x” it makes me sick… I have no problem with this kind of naming :smiley:, later for others I just change display name.
If there would be something like “Title” or “label” or “Display name” property to set with sensor I would not complain :wink:
btw. sensor.current_bedside_lamp - which bed :sweat_smile:

I use mostly Tasmota and other devices (servers, rpi’s with my own scripts/programs…) that publish to MQTT values, I have already set up MQTT topics in logical structure that I will not change .
One of my main reason to not use ready-to-go integrations (like Tasmota) that mass-add devices - because those can’t find or add properly my devices.

Then I suggest you give it back :rofl:

Many of the members here are engineers and/or programmers.
And there’s no constraints as to what you call stuff - just don’t expect everybody else to adopt your naming as it would be a backward step and as obtuse as the unique id you talk about.
This (unique id) is just for the system and it’s very hard to change (possible, but really not recommended)
You don’t need it in automations or scripts but if you use the gui editors, they stick them in there.
Many here use a text editor to write them by hand and so don’t see them

1 Like

:rofl: , not, a, chance - I need something to annoy other :rofl:

Backwards :thinking:, if HA see unique id then it use it for entity id, if not then go for normal way to create entity id… Or introduce an option to define my own entity id - if I screw it it’ll be my problem :crazy_face:
(those are just my thought, if devs don’t like it - I can’t help, not everyone works on that same wavelength like me… So, I’ll be saying under my nose something ‘unprintable’ :stuck_out_tongue: every time I see a list of next numbers at end of entities in entity list)

Also, this was just proposition, because I don’t see it being used in UI. And that was just an example :slightly_smiling_face:

I didn’t started to tinker with UI yet, if the “unique id” is there and I will be able pick it up then , there was no problem… For now in dev tools I only see in Entities: sensor .current , .current_2, .current_3 , etc… which is giving me impression " srsly they couldn’t do this more refined way :expressionless: " - that’s why I started this suggestion.

Hard to change you say… Hold my beer :beer: :joy:
I’ve been using sqlite recently more often (had to do few programs for work), and I remember there is not much in ha db too (few tables only, if my memory serves right).

I just told you how to do that