snarky-snark / home-assistant-variables

A custom Home Assistant component for declaring and setting generic variable entities dynamically.
Apache License 2.0
274 stars 16 forks source link

Add support for unique_id attribute #68

Closed Santanachia closed 2 years ago

Santanachia commented 2 years ago

image

snarky-snark commented 2 years ago

https://www.home-assistant.io/faq/unique_id/

RoboMagus commented 2 years ago

I've been doing some development on this component yesterday, including to add the unique ID. It's quite an easy addition, but after playing with it I do not believe this is something we should actually want to add.

Mostly as anything that is editable through the UI is also part of the configuration of the var entities in YAML, i.e. as far as I can tell we're not missing anything by not having a unique ID for each var entity. Second, providing a unique ID allows the user to change the entity_id of var entities. This opens up all sorts of problems with the YAML configuration and the entities in Home Assistant getting out of sync.

Santanachia commented 2 years ago

"we're not missing anything by not having a unique ID" I use variables to store data that is used later in the sensor. I don't need to see them on the dashboard, and without unique_id I have no way to hide them.

Of course you may argue that I can manually edit the dashboard and remove variables from it, but then no new entities will automatically appear on it

Santanachia commented 2 years ago

p.s. "This opens up all sorts of problems (...)" There are many other integrations that have unique_id and I don't see anyone wanting to abandon it to avoid any errors.

snarky-snark commented 2 years ago

I tend to agree with @RoboMagus. There is a risk of causing confusion in this component by supporting unique_id, if not done carefully. Though, I think this confusion is a general issue with unique_id in Home Assistant, and so it might not be up to the var component to address that general issue.

I use variables to store data that is used later in the sensor. I don't need to see them on the dashboard, and without unique_id I have no way to hide them.

Can you elaborate on how unique_id enables you to hide variables from the dashboard? I'm not sure I understand what the benefit is here.

I see that there are integrations that support user-defined unique_id attributes - namely, the templates and mqtt integrations. I think a reasonable start towards support for unique_id in the var component would be to allow the user to define it explicitly (rather than deriving it from entity_id), but revert to entity_id-only behavior if the unique_id is not present.

Before doing considering this much further, I would like to enumerate the cases where user changes through the UI and YAML might conflict and cause confusion in identifying variables. Perhaps there is a way to reduce or eliminate these issues.

Here are some references to HA documentation on unique_id:

Santanachia commented 2 years ago

@snarky-snark this image is from a custom component that has a unique_id: image I can select the area where it is, I can hide it and still leave it running (and that's what I want with var) in the variables at this point I see: image

RoboMagus commented 2 years ago

One way to have the best of both worlds would be to explicitly add a unique_id field to the variable entity configuration. This way the option is essentially opt-in and can be enabled explicitly by users who'd want to, without exposing others to the potential issues of creating duplicate entities when renaming from both the HA UI and in YAML.

Based on what I could find whilst playing with this, this solution mitigates all the issues I have against adding the unique_id for such a YAML centric component as variables. Though the user should take care to have actually unique unique_id's ofcourse.

Here's a snippet that shows the coexistence of variables both with and without unique_id (Note the editable status and room for Renamed UUID Test): image

snarky-snark commented 2 years ago

Added in v0.15.