Create a group with all lights and more

Hello,

I want to create a group that contains all lights plus some additional switches. I wonder how to mention all lights in the groups entities section.

I found plenty of related tipps there: PSA: Turn on/off all lights in Home Assistant 0.104+ (group.all_* changes) but they all seem to focus how to use it in templates, not some “virtual” entities like group.all_lights.

Use case is to have common switch and state for all lights + some switches.

Thanks!

1 Like

Use expand on the group inside a template, employing the methods used in the post you linked.

Hey, could you elaborate a bit?

Do you suggest to create a group from a templated expression? How so? Groups don’t seem to support value_template or alike.

Or should I create a sensor and a switch from the template? I think I could do that, but would prefer to use a group.

Thanks!

Make the static group. Use the expand function (A home assistant function used to expand groups into state objects) inside a template. Then use the state objects to map the information that you want. I’m not sure what you mean by this

Or this

This however, does exactly what you claim PSA: Turn on/off all lights in Home Assistant 0.104+ (group.all_* changes) doesn’t do. It creates a group of all lights or all switches, and then you can turn on or off the groups.

I think we somehow misunderstanding each other…

I can have a group:

beleuchtung:
  name: Licht
  entities:
    - light.esstisch_1
    - light.esstisch_2
    - light.esstisch_3
    - light.esstisch_4
    - [... all lights ...]
    - switch.janus_1

This group gives me a state and a common switch for all the lights and for switch.janus_1.

What I am trying to do is instead of writing every single light in the entities list, is to use an expression for all lights.

Is that possible with a group? Or should I go with a Template Switch - Home Assistant?

Thanks and sorry for the confusion!

It’s covered in that thread, just not the main post

- alias: Create Beleuchtung Group
    id: create_beleuchtung_group
    trigger:
    - platform: time
      at: '00:00:00'
    - platform: homeassistant
      event: start
    - platform: event
      event_type: call_service
      event_data:
        domain: template
        service: reload
    action:
    - service: group.set
      data:
        object_id: beleuchtung
        entities: >
          {{ expand(states.light, 'switch.janus_1') | map(attribute='entity_id') | list }}
4 Likes

Thanks Petro! Although this feels a little hacky it works great.

Would it be possible to do something like this for a light group? Meaning, the domain would be light rather than group, but still have it’s entities defined as a template rather than a static list of entities.

I don’t believe it’s possible w/ new style groups.

1 Like

Very old post, but almost working solution for me. Is it somehow possible to use this and exclude light groups but include lights. Or is there other solutions for that kind of use?