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