WTH: Why no unique_id for sensors?

Of course it’s my mistake. As the documentation clearly states, there is no unique_id for sensor, so the following is clearly wrong:

- trigger:
    - platform: time_pattern
      minutes: "59"
  sensor:
    - name: My long and complicated human-readable name
      unique_id: mnemonic_sensible_id

Of course there is an id and it can be set and changed in the UI, but it’s not the one (wrongly) defined above. There is no error message and after identifying the problem it’s an extra step for each and every unit.
I’m used to being able to set an id for everything from Esphome and would like to be able to do it here too.
(N.B: there are several similar threads but seemingly none about this point.)

I am confused. What is the fragment you present from? An automation? Show your whole automation yaml file and tell us what you are trying to do.

It is unclear what you are asking… though, it seems like you may be trying to rehash something that was changed years ago and is now considered settled.

The unique ID is used in the backend, it cannot be changed in the UI.

There is, but it depends where you look. Old style sensors do not, template sensors do, trigger based template sensors do. That is why you get no error and can edit it in the gui.

What exactly is your problem?

Ps. WTH is only in specfic months. It was closed wuite a while ago. WTH’s outside this month will be ignored.

It is a template sensor and I show the relevant part. The id is constructed from the name. I can change it later in the UI, but I can’t set it in the template. The unique_id: line in there is invalid, not defined, and changes nothing.

Share the actual code you are attempting rather than a made up example.

Au contraire, I can only change it there. I can’t set it when writing the template, but I can click on settings later and change the automatically generated one. That works, but it’s tedious and badly described in the documentation.

Alright, here goes:

- trigger:
    - platform: time_pattern
      minutes: "59"
  sensor:
    - name: Solar Zaehler
      unique_id: t_solar_zaehler
      device_class: energy
      unit_of_measurement: "kWh"
      state: "{{ states('sensor.shellypmminig3_84fce638860c_energy')|float(0) }}"
      attributes:
        m00: "{{ states('sensor.shellypmminig3_84fce638860c_energy')|float(0) }}"
        m60: "{{ this.attributes['m00'] }}"

The reason for my wanting to choose it would have been more obvious if I had used the umlaut in the “Zähler” name. There are other cases, where a sensible id may be quite different from the friendly name.

In that case Drew answered your question here: WTH: Why no unique_id for sensors? - #3 by Didgeridrew

The entity id is always constructed from the name, not the unique id.

However if you give the entity a unique id you can change the entity id to whatever you want using the frontend.

Click on your entity in a dashboard, click the cog icon in the top right of the pop-up card, change the entity id to whatever you want.

That’s one id too many. If I explicitly specify an id, I of course want to use that in automations and templates and not another automatically generated one I don’t even know without looking. So why isn’t the entity id not generated but copied when an id is already specified?
Esphome employs the much more sensible system here.

The unique id is not an entity id. It has other uses in the backend for tracking the entity, for example if you change the entity id.

1 Like