2022.4: Groups! Groups! Groups!

It’s because it’s a rumour and the spread should be stopped. Only integrations are moving away from YAML.

the problem is in the target not in the message

I know I’m late to the game but is there any way at all to know when the database migration is complete?

I updated 5 hours ago and my history is still locked up completely. So I don’t know if it’s still working on something or just locked up and I should restart.

It really would be nice if there was some kind of “complete” message when it was done.

2 Likes

I’m fairly sure I saw a log message in my log when the DB migration completed. My DB is 1.8GB and it took a few seconds.

Mine took at least ~8 hours (3GB) and i never saw anything indicating it was completed. But I didn’t look in the log specifically for it since there was a pop up notification that the db migration started and not to restart until it was done so I assumed it should have popped up another notification that it was done. Nobody should need to look for a random log entry for something like that.

the only way I was confident that it was done was that all my history graphs came back.

Odd. Not that I can offer any more insights, but which DB do you use? I use Postgres.

MariaDB (10 char min… :roll_eyes:)

Did you find a way to get back the old group behaviour?

Or has someone a tip how I could count lights without expanding a group nested inside another group (as groups works prior to HA 2022.4?

Regards
Ulrich

{{ state_attr('group.all_lights', 'entity_id') | list | count }} 
1 Like

expands the contained light group, too.
As I understood user atv, he wants to count individual lamps and the light groups as a whole.

i couldn’t get that to work, but this did:

Upsttairs:  {{ expand('light.upstairs_lights') | list | count }}
Downstairs: {{ expand('light.downstairs_lights')  | list | count }}
outside:    {{ expand('light.outside_lights')  | list | count }}
All:        {{ expand('light.all_lights') | list | count }} 

I have groups for upstairs, downstairs, and outside. the all lights group contains these groups and the expand does iterate through all of them:

Upsttairs:  16
Downstairs: 11
outside:    4
All:        31 

EDIT: just saw @pedolsky detail and i completely missed that bit about counting the group as one light without expanding. i tried it with the hide members option, but it still expanded the groups.

EDIT part deux: @123 is right, i just had an error in my template:

Upsttairs:  {{ expand('light.upstairs_lights') | list | count }}
Downstairs: {{ expand('light.downstairs_lights')  | list | count }}
outside:    {{ expand('light.outside_lights')  | list | count }}
All:        {{ expand('light.all_lights') | list | count }} 
ALL - @123: {{ state_attr('light.all_lights', 'entity_id') | list | count }} 

yields:

Upsttairs:  16
Downstairs: 11
outside:    4
All:        31 
ALL - @123: 3 
1 Like

I’m not following what you’re saying because the template I posted doesn’t use expand.

I tested it by creating a Switch Group containing two switches and another Switch Group (which contains two other switches). The resulting Switch Group’s entity_id contains three entities (not five) and 3 is the count produced by the template.

Hard for me to comment because I don’t know what you were trying to achieve.

Your examples employ expand which recursively expands all nested groups. If you want a count of all entities in all nested groups, you would use expand. If you don’t want nested groups to be expanded, your template cannot employ expand.


EDIT

Here’s the PR that modified the behavior of expand.

Expand’s inability to expand nested groups was reported in this Issue:

It was considered to be a bug. FWIW, I feel it probably should have been reported as a Breaking Change in the Release Notes because its new behavior is significantly different from previous versions. However, the modification was probably overlooked and didn’t get documented.

2 Likes

The solution @123 gave seems to work. Instead of:

{{ expand('group.all_lights', 'entity_id') | list | count }} 

use:

{{ state_attr('group.all_lights', 'entity_id') | list | count }} 

I could have sworn I tried this before posting my question but I guess not…

Have pity on my lousy language skills :slightly_smiling_face: I meant this comment:

I tested it with an old-style group containing single lights, a Hue group and one HA light group. I also haven’t found a solution to only count the members of the group.

Works for me, thanks!

1 Like

In Developer Tools → States find your old-style group entity and look at its entity_id attribute. The number of entities shown in its entity_id attribute will be the count returned by the template I posted.

Yes, absolutely d’accord. But how to count lights on with the described mixed group?

I’ll go search if you don’t know, but in case you do: Do you know whether introducing a parameter to control the depth was considered? Looks to me like what should’ve been done, because that way a default could’ve been specified to keep the current behaviour the same while introducing useful new functionality.

So the problem is your light group has light groups and you do not want it to recursively expand is that the gist? Yes in that case you won’t be able to use expand in this spot anymore. expand always recursively expanded group entities but did not recursively expand other types of groups (like light groups for example). Now all groups work the same with expand which is more consistent and less confusing but appears to be an issue for you.

I think your best solution here is now this:

{% set ns = namespace(on_lights=0) %}
{% for light in state_attr('group.all_lights', 'entity_id') if is_state(light, 'on') %}
  {% set ns.on_lights = ns.on_lights + 1 %}
{% endfor %}
{{ ns.on_lights }}
1 Like