Unique ID for template sensor

Hi

I am struggeling with my configuration of templatede sensors. The work fine, but I am not able to set the unique ID.

This is my configuration:

  • platform: template
    sensors:
    cerius_beregnet:
    friendly_name: “Cerius elmåler”
    unique_id: cerius
    device_class: Power
    unit_of_measurement: “W”
    value_template: “{{ states(‘sensor.nr_tvedevej_12_power’)|float - states(‘sensor.nr_tvedevej_12_power_returned’)|float }}”

Works like a charm, but the ID is named sensor.result_sensor

Any ideas?

unique_id does not affect your entity_id with legacy templates. It creates a spot in the entity_registry so that you can adjust the entities settings via the UI. Your entity_id will be based off the slug, in your case that would be cerius_beregnet. So with the configuration above, I would expect your entity_id to be: sensor.cerius_beregnet. However, if your slug was originally result_sensor and you had a unique_id, then you change the slug to cerius_beregnet, the entity_id would remain sensor.result_sensor because you had a unique_id which registered it in the entity_registry. Your only option now is to change the unique_id or rename the entity_id in the UI.

Thank you very much :slight_smile: