Auto light grouping

Open your Home Assistant instance and show the blueprint import dialog with a specific blueprint pre-filled.

Select one or multiple rooms you would like to automatically group together. If you want to have multiple groups for each room, create multiple automations from this blueprint.
This will run automatically (with a short delay) after each Home Assistant restart. You can also manually run this automation once it has been set up.

blueprint:
  name: Auto light groups
  description:
    Select rooms you want to automatically create light groups for.
  source_url: https://community.home-assistant.io/t/auto-light-grouping/516373
  domain: automation
  input:
   group_id:
     name: Group ID
     description: ID of the group
   groupname: 
     name: Group name
     description: The name of the group
   rooms:
      name: Room(s)
      description: Select one or multiple rooms you would like to automatically group together. If you want to have multiple groups for each room, create multiple automations from this blueprint.
                   This will run automatically (with a short delay) after each Home Assistant restart. You can also manually run this automation once it has been set up.
      selector:
        area:
          multiple: true
variables:
  rooms: !input rooms
  groupname: !input groupname
  group_id: !input group_id
trigger:
  - platform: homeassistant
    event: start
condition:
action:
  - delay:
      hours: 0
      minutes: 5
      seconds: 0
      milliseconds: 0
  - service: group.set
    data:
      name: "{{groupname}}"
      object_id: "{{group_id | lower() }}"
      entities: >
       {%- set lightgroup = namespace(ids=[]) -%}
       {%- for state in states.light -%}
         {%- if area_id(state.entity_id) in rooms -%}
           {%- set lightgroup.ids = lightgroup.ids + [state.entity_id] -%}
          {%- endif -%}
       {%- endfor -%}
       {{- lightgroup.ids -}}
mode: restart
1 Like

Mate,

This is no longer working from what I can see. I have a setup with about 300 lights on three floors with a lot of rooms. I would love to be able to use this to build light groups for each room and then each floor and then all lights. I have been trying to work this out for about 15 hours a the computer now. I have created code to list all the lights in the system, restructure the output of the list for both JSON and YAML and I have even figured out how to make calls to the API to create group but there seem to be bugs in that when I make the calls it creates the group but does not assign a Unique ID from the ID registry. This is driving me a bit crazy.