I have noticed a weird problem pertaining to the group:
let’s say I have 5 lights in a group and only one of them is turned on. If I turn off the group, it appears that turn off command gets sent to all five lights in the group, not just the one lone light that is turned off. Since my lights are z-wave, which is not really known for its speed, this causes significant slowdowns in automations that rely on groups.
Is there a way to change this behavior? I only want commands to be sent to the group entities that need changing.
For example I have a few air conditioners in a group, only one is turned on (I hid the ones which are turned off):
As soon as I toggle the group switch that one turns off but the others turn on.
With the lights I face exactly the same issue. They’re all RF controlled via a Broadlink, because it sends the command to like 5-6 lights they turn off in sequence so it adds quite a lot of a delay. I have a few Broadlink IR remotes and I have load balanced them but there’s still quite a lot of delay, at least 5s in the worst cases.
My only solution is to use scripts like the ones below or use a template switch:
Be aware that you NEED to be able to check the state of the switch otherwise it cannot be done. In my case for my lights I am screwed, but I can do it for my AC.
Here’s just some templates I’m using in my automations for similar situations. For inspiration.
This value template counts the number of lights in a group that are turned on (or off if you change it just a tiny bit). You can use this in a condition of an automation:
In the action part of the automation, you can create a comma separated list of just the lights you want to trigger:
- service: light.turn_on
data_template:
entity_id: "{{ states | selectattr('entity_id', 'in', state_attr('group.colortemplights', 'entity_id')) | selectattr('state', 'equalto', 'on') | map(attribute='entity_id') | join(', ')}}" # comma separated list of entities that are currently turned on
color_temp: 300
transition: 3
I arrived at these templates because the Tradfri hub is quite prone to crashing when I feed it too many calls in a short time period. So trying to prevent any unnecessary call.
What happens if no entities are selected by the template?
Doesn’t home assistant apply the service to all the entities (and generate a warning that the value “all” should be used instead of not specifying an entity_id?
This would have the complete opposite effect of what was intended.
Then it will, as you’ve indicated, produce an empty string for entity_id thereby causing the automation to act on all lights (along with a warning message indicating a blank entity_id has been deprecated in favor of using all).
One hack would be to prepend a non-existent light entity so that if there are no lights on within the group, the template will return a minimum of one entity. Home Assistant will not (currently) complain about non-existent entities.