Dynamic Groups Based on Labels

Background: When managing a large number of similar devices (ex. lightbulbs), it can be helpful to apply labels (ex. accent vs. main) on the devices. While I understand some automations can be applied to all devices with a label, more advanced automations may or may not support lists defined by labels (ex. For Each loops).

Use-Case: For all accent lights, test if on/off. If on, change color to XYZ. If off, change color to XYZ, wait 0:02, turn back off (so that when they’re turned on next, they maintain the color).

Current Workaround: maintaining a manually defined group of “light 1”, “light 2”, etc. that I can use in a For Each loop.

Problem statement: As I reconsider which lights are accent lights vs. main lights (or any of the home’s other occupants do) or add new devices, maintaining groups requires more involvement than updating labels.

Request: A method of creating a dynamic group populated with all devices with a specified label.

Note: recognizing that a functional workaround exists for this solution, this is truly just a quality of life issue for me. It would be nice to be able to walk around with the other occupants and quickly update labels, rather than taking notes for later fiddling with groups.

edited for formatting

Repeat For Each actions will accept a template that renders a list or dictionary, likewise groups can be created ad hoc using the group.set action. Though, for the majority of uses, labels make such groups redundant.

Well, it is a general issue that HA’s groups cannot be truly dynamic (easily). It’s possible, but “complicated” (so yeah, quality of life improvement needed) and the solutions some would say are not “performant” (although I don’t see any performance issues with my setup).

Take a look at this thread:

You can take the same approach (templated time pattern trigger) to dynamically modify group members.