Light group made from light in areas

Can we do that?
some thing like:

light:
  - platform: group
    name: "first floor"
    area:
      - dining_room
      - kitchen

and so on…
the idea is to update the area or add a new light to the area and update the group automatically…

Should be possible to do it with templates. Create an automation that creates that group on start up based on the rooms. You could also create a blueprint in order to easily manage the rooms / create multiple groups.

All on that is where I need some help… may be a lot of help.

I can create something for you in a bit. If you just want to be able to turn on/off lights you can use something like this

service: light.toggle
data: {}
target:
  area_id:
    - room1
    - room2

Nevertheless I created an automation for you:

1 Like

Was there no way to fulfill the following requirement?

You can add new lights to an area by adding them to the area. If you then also want to add them to the group, you need to manually rerun the automation. In all honesty, I don’t think that anyone is constantly adding/removing lights anyway. I also don’t know how to create a trigger that reacts to a new entity or its change of area id.

The following (demo) automation triggers when an entity’s information is updated. It uses an Event Trigger listening for entity_registry_updated. Obviously several kinds of updates are possible so the condition limits it to the one that contains the area_id property.

alias: Entity Area Updated
description: ""
trigger:
  - platform: event
    event_type: entity_registry_updated
    event_data:
      action: update
condition:
  - "{{ trigger.event.data.changes.area_id is defined }}"
action:
  - service: notify.persistent_notification
    data:
      message: >
        {{ trigger.event.data.changes.area_id if
        trigger.event.data.changes.area_id is not none else 'undefined' }}
mode: single

Ideally, area_id would report the entity’s new assigned area. Curiously, it reports the entity’s old assigned area (or null if the entity had no previously assigned area).


NOTE

Here’s an example of an entity_registry_updated event.

event_type: entity_registry_updated
data:
  action: update
  entity_id: input_boolean.switch_1
  changes:
    area_id: f1a3e02eadba4e7c81fa5f56d0d39f8f
origin: LOCAL
time_fired: "2023-01-10T21:24:56.597424+00:00"
context:
  id: 01GPES4TMN05BFDXZ78WS27CAX
  parent_id: null
  user_id: null
2 Likes