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.

Another use for this would be for 3rd party integration such as Alexa. Without a lot of needless work around, there really isn’t a way for Alexa to control a dynamic group. I use labels because it’s easier for the wife to mark certain devices with a label when she wants to move devices, like smart plugs, to a different function (such as to control plant lights). It will then be controlled by whatever automation that label uses dynamically. However, you cannot say " Alexa, plant lights on/off and she controls that same dynamic group".

I agree that in several ways, the group and labels would be redundant. But there are also many ways the usefulness would out-weigh the redundancy. Would a compromise be to enable dynamic groups with filters/ templates, much like you can do with Tom_L’s Auto-Entities?

That sounds like a use case for a Template Light instead of a light group.

Which is a pain in the ass for people who aren’t experts at this stuff to set up; I think that was the point the OP was making. Yes, there are ways to do it, but they aren’t necessarily intuitive for most users. Having the ability built into the group integration can save a lot of work for people

By the way, I chuckle every time I see your name.