I don’t know if I understood you right, but there are a few issues, I see:
how can I properly represent the brightness value of that group, if the brightness is changed outside of home assistant?
adding color values would make things lot more complicated, i think.
how can I get this into a lovelace “light” card?
As far as I understood, a light group would be a simple way to go, because it processes all the states and capabilities of the associated lights and congregates them into one entity. This entity can be used as one light, without defining additional services and / or automations.
Is there really no way to dynamically create and modify a light group?
I believe you may have misunderstood the purpose of a Light Group. It creates a virtual light entity to provide control over a fixed group of light entities. Although each member of the Light Group can continue to be controlled independently, its state influences the Light Group’s state. In other words, if only one member of the Light Group is on, the Light Group’s state is also on.
You won’t be able to do that with a Light Group. You will have to control each member individually, as described by tom_I.
Yes, it seems like I misunderstood the purpose of a Light Group and also for the standard Group, if there is no way to modify its members while the system is running. I simply did not take into account, that such a basic thing like is not possible.
I simply did not find any word on where it is possible to use Templates and where it is not possible, so I was convinced, that it works basically in every place.
Sorry for the dumb question and thank you all for the clarification, I will try to make it the way, you described before.
If you already have a Light Group (defined with a fixed list of light entities), a template can use it to determine which of its members is currently on or off.
For example, if your Light Group is called light.first_floor then this template will select all members that are off and present them as a comma-delimited string of entity_ids.
Hi, I think one solution could be a template light, which handle the “group” internally. But there are some questions you need to think about:
What is the current brightness level of the group entity, when not all lights in the group have the same brightness?
The state of the group light will be ‘on’ when any of the lights is on. But what happens, when no light is on, so the group light is off, and then its turned on? At this moment there are no lights in the group, because none is on.
Anyway, this is a solution, which works sort of. First, make a group of all lights you possibly want to control, when they are on.
Then create a template light, which handles the states:
Light is on, when any of the lights is on
Brightness level is the maximum of brightness level from all lights in the group (maybe average is better?).
Turn off just turns the group off.
Set level calls a script, which sets the level of all lights in the group, that are on.
light:
- platform: template
lights:
on_lights:
friendly_name: "On Lights"
level_template: >
{%- set data = namespace(level=0) -%}
{% for s in state_attr('group.all_lights', 'entity_id') %}
{% if is_state(s, 'on') %}
{%- set data.level = [state_attr(s, "brightness"), data.level]|max -%}
{% endif %}
{%- endfor -%}
{{data.level}}
value_template: >
{%- set data = namespace(res="off") -%}
{% for s in state_attr('group.all_lights', 'entity_id') %}
{% if is_state(s, 'on') %}
{%- set data.res = "on" -%}
{% endif %}
{%- endfor -%}
{{data.res}}
turn_on:
# what to do if a group with all "on" lights is off and turned on then?
turn_off:
- service: light.turn_off
data:
entity_id: group.all_lights
set_level:
- service: script.set_brightness
data:
brightness: "{{ brightness }}"
This is exactly what I am looking for. Can anybody share the final code used for this template so that I can adjust the brightness of the lights (in a group) that are turned on? Thanks
Thank you but still no success,
i have the template in config.yaml figured out, and also got the group in group.yaml
but its the script that i get an error from…
maybe i have missunderstood how i should connect the template to the actual dimmer?
yes, the template creates a group (in my example light.gang_on) and you can control it with a slider / dimmer. There is one issue with the template, if everything is off… not sure how to resolve.
I habe the same question with controlling the lights which are currently ON.
I understand that there is an existing solution as described above. But this was all written before the changes of group behaviour in HA release 2022.4. So I tried to find something easier. I added the template mentioned above which gives me a list of all lights which are currently on in the script to „set group“. Unfortunately template seems to be not accepted here.
Does anyone have a more simple Solution than described above by using the new Features implemented in R2022.4?