Skip to content

Instantly share code, notes, and snippets.

@asaf400
Last active November 26, 2025 17:20
Show Gist options
  • Select an option

  • Save asaf400/c95142a7bb850e972fa00d73e992ad4d to your computer and use it in GitHub Desktop.

Select an option

Save asaf400/c95142a7bb850e972fa00d73e992ad4d to your computer and use it in GitHub Desktop.
blueprint:
name: Auto Light Group by Reference
description: >
Select a "Reference Device" (e.g., one specific IKEA bulb).
This automation will automatically find ALL other lights in your system
that match that device's Manufacturer and Model exactly and add them to a group.
domain: automation
input:
group_id:
name: Group Entity ID
description: The ID of the group to create (e.g., ikea_warm_bulbs). Do not include "group.".
group_name:
name: Group Friendly Name
description: The friendly name of the group (e.g., IKEA Warm Bulbs).
reference_device:
name: Reference Device
description: >
Select one device to use as the template. The automation will read this
device's 'Model' and 'Manufacturer' and group all other matching devices.
selector:
device:
entity:
domain: light
multiple: false
variables:
group_id: !input group_id
group_name: !input group_name
ref_device_id: !input reference_device
trigger:
- platform: homeassistant
event: start
- platform: event
event_type: automation_reloaded
- platform: time_pattern
hours: "/1"
action:
- delay:
hours: 0
minutes: 1
seconds: 0
- service: group.set
data:
name: "{{ group_name }}"
object_id: "{{ group_id | lower | replace(' ', '_') }}"
entities: >
{%- set lightgroup = namespace(ids=[]) -%}
{# Get the Model and Manufacturer from the Reference Device #}
{%- set target_man = device_attr(ref_device_id, 'manufacturer') -%}
{%- set target_mod = device_attr(ref_device_id, 'model') -%}
{# Loop through all lights to find matches #}
{%- for state in states.light -%}
{%- set dev_id = device_id(state.entity_id) -%}
{%- if dev_id -%}
{%- set dev_man = device_attr(dev_id, 'manufacturer') -%}
{%- set dev_mod = device_attr(dev_id, 'model') -%}
{# Check for Exact Match. We handle None types just in case. #}
{%- if dev_man and dev_mod and dev_man == target_man and dev_mod == target_mod -%}
{%- set lightgroup.ids = lightgroup.ids + [state.entity_id] -%}
{%- endif -%}
{%- endif -%}
{%- endfor -%}
{{- lightgroup.ids -}}
mode: restart
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment