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

tracked_entity_id template? #82

Closed nobwyn closed 2 years ago

nobwyn commented 2 years ago

I was wondering - is there any possibility to have tracked_entity_id list to be generated dynamically instead of using a static list?

I'm trying to create a variable, which depends entities in specific area. So within value_template I can easily do:

{{  expand(area_entities('my-area-id')) | selectattr ... }}

But in order for the variable to be updated only when something changes on any of the entities in that area, I would need something like:

tracked_entity_id: {{ area_entities('my-area-id') }}

Now I have to add all the entities from the area to tracked_entity_id one-by-one, which sometimes leads to errors when entities are added or removed to/from the area ...

snarky-snark commented 2 years ago

You can use the var.set service to update the list of tracked entities, however you still need a way to detect when your list of entities has changed so that you can trigger the update. I'm not sure how to detect that change off-hand.

snarky-snark commented 2 years ago

In general, a dynamic template for tracked_entity_id will likely never be supported because there is no way for the var component to determine when to refresh that template.