πŸ’‘ Group Lights by Model

tl;dr

This is a blueprint for Grouping together Lights by a particular Model - using a reference device to group all light devices of the same type and manufacturer, so that their controls are unified.

Source vibe


Hello, I have a mix of several brands of lights in my setup with various controls (Brightness, White Balance, Color mixture)

While creating a group of all lights so I can turn everything off at once using toggle buttons, I noticed that the white balance (light temperature) control for my bulbs is not aligned, since the group has 2.5 different manufacturers (OSRAM / LEDVANCE, IKEA) HA does not know that 3200K of IKEA TRADFRI isn’t the same temperature of 3200K of OSRAM Smart+.

This is why I asked Gemini to create a blueprint for me for grouping lights by manufacturer, so that I can control the white temperature throughout the house and balance it between the manufacturers.

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