Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

can not expand nested light groups more than 1 level #68836

Closed
Mariusthvdb opened this issue Mar 29, 2022 · 4 comments · Fixed by #68875
Closed

can not expand nested light groups more than 1 level #68836

Mariusthvdb opened this issue Mar 29, 2022 · 4 comments · Fixed by #68875

Comments

@Mariusthvdb
Copy link
Contributor

Mariusthvdb commented Mar 29, 2022

The problem

since https://next.home-assistant.io/integrations/group/#old-style-groups is actively discouraged, I was rebuilding all groups: with light entities as entities, to the light: platform:group format.

there is a serious issue though. We can not iterate over nested light groups, like we can over nested groups with lights.

Schermafbeelding 2022-03-29 om 13 22 37

What version of Home Assistant Core has the issue?

2022.4.0.dev20220329

What was the last working version of Home Assistant Core?

No response

What type of installation are you running?

Home Assistant OS

Integration causing the issue

light group

Link to integration documentation on our website

https://www.home-assistant.io/integrations/group

Diagnostics information

No response

Example YAML snippet

group:

  all_lights_only:
    name: All lights only
    icon: mdi:lightbulb-group
    entities:
      - group.all_inside_lights
      - group.all_outside_lights

  all_outside_lights:
    name: All outside lights
    icon: mdi:spotlight-beam
    entities:
      - group.outside_lights
      - group.terrace_outdoors_spots

  all_inside_lights:
    name: All inside lights
    icon: mdi:lightbulb-outline
    entities:
      - group.main_inside_lights
      - group.guest_inside_lights
      - group.plafond_spots

and same config in lights format:

  - platform: group
    unique_id: lightgroup_all_lights_only
    name: All lights only
    entities:
      - light.all_inside_lights
      - light.all_outside_lights

  - platform: group
    unique_id: lightgroup_all_outside_lights
    name: All outside lights
    entities:
      - light.outdoors_floodlights
      - light.terrace_outdoors_spots


  - platform: group
    unique_id: lightgroup_all_inside_lights
    name: All inside lights
    entities:
      - light.main_inside_lights
      - light.guest_inside_lights
      - light.living_ceiling_spots

some more nesting going down, but the picture is clear

Anything in the logs that might be useful for us?

No response

Additional information

{{expand('group.all_lights_only')|list|count}}

{{expand(state_attr('light.all_lights_only','entity_id'))|list|count}}

{{expand(state_attr('light.all_inside_lights','entity_id'),
         state_attr('light.all_outside_lights','entity_id'))|list|count}}

makes it clear what's happening, the expand only goes 1 level on light.groups.

in my python scripts I can use either the group.all_lights_only or light.all_lights_only, using:

def flatten(entity_id, result=[], searched=[]):
    state = hass.states.get(entity_id)

    if state is not None:
        entity_ids = state.attributes.get('entity_id')
        if entity_ids is not None:
            searched.append(entity_id)
            for entity_id in entity_ids:
                if entity_id not in result and entity_id not in searched:
                    flatten(entity_id, result, searched)
        else:
            result.append(entity_id)

or this in frontend Javascript buttons:

    label: >
      [[[
        function flatten(entity_id, result=[], searched=[]) {
          var state = states[entity_id];
          if (state) {
            var entities = state.attributes.entity_id;
            if (entities) {
              searched.push(entity_id);
              entities.forEach(entity_id => {
                if (!result.includes(entity_id) && !searched.includes(entity_id))
                    flatten(entity_id, result, searched);
                });
              }
            else
              result.push(entity_id);
            }
          }
        var light_ids = [];
        flatten(entity.entity_id, light_ids);

and that also works directly with the light group.

HA not doing that is out of expectation.

@probot-home-assistant
Copy link

group documentation
group source
(message by IssueLinks)

@probot-home-assistant
Copy link

Hey there @home-assistant/core, mind taking a look at this issue as it has been labeled with an integration (group) you are listed as a code owner for? Thanks!
(message by CodeOwnersMention)

@Mariusthvdb Mariusthvdb changed the title can not expand nested light groups can not expand nested light groups more than 1 level Mar 29, 2022
@balloob
Copy link
Member

balloob commented Mar 30, 2022

Fix #68875

@Mariusthvdb
Copy link
Contributor Author

wow that was fast!. thanks!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants