Change Groups dynamically with group.set and group.remove

Hi,

I am trying to dynamically change members of a light group.
I found the services group.remove and group.set, but they seem to be hardly used and not really documented. Def Tools describes them as " Remove a user group." and " Create/Update a user group.", but I also saw it being used to control device groups, not user groups… :thinking:

This is how I configured my light group in configurations.yaml:

light:
  - platform: group
    name: Ambient_Wohnzimmer
    entities:
        - light.dekooben
        - light.dekounten
        - light.dekomitteunten
        - light.dekomitteoben
        - light.esstisch_ambient
        - light.sofaunten
        - light.sofamitte
        - light.sofaoben

That’s how I tried to use it:

test_1:
  alias: Test1
  sequence:
  - service: group.remove
    data:
      object_id: Ambient_Wohnzimmer

Gave me the error: “invalid slug Ambient_Wohnzimmer (try ambient_wohnzimmer) for dictionary value @ data[‘object_id’]”

I also tried:

test_1:
  alias: Test1
  sequence:
  - service: group.remove
    data:
      object_id: light.ambient_wohnzimmer

Gave me the error: “invalid slug light.ambient_wohnzimmer (try light_ambient_wohnzimmer) for dictionary value @ data['object_id]”

Anybody is having an idea?
Can group.remove be used for device groups as well?

I would be happy to see a function to remove specific entities from an existing group, without the need to remove the whole group and set it new.

Thank you,
Stefan

Try like this, you need to use the second part of the entity_id not the name of the group.

test_1:
  alias: Test1
  sequence:
  - service: group.remove
    data:
      object_id: ambient_wohnzimmer

Thank you, but this gives me the folllowing error:

remove:Group ‘ambient_wohnzimmer’ doesn’t exist!

Maybe because I defined the lights as light group, and not as normal group?

Ah, didn’t notice that it’s a light group. This service is only for groups. There’s no possibility to do this for light groups as far as I know.

damn… That’s sad and does not really make sense, from my point of view…

Can I use my light group still as light group, even when I define it as normal group?

No, you won’t get brighness slider, color wheel etc. For the group. You can only turn them on/off as a group.

Why do you want to dynamically change light groups? What’s the use case?

Interesting, I just tried and I did get all sliders an wheels :slight_smile:

For the following case: I have around 10 bulbs which are used for ambient light, 3 of them hanging over the sofa. When I am sitting at the sofa, I want to be able to turn the sofa bulbs “on” independently, they should get bright and white, stopping all effects of the ambient light. If in the meantime the settings for the ambient light are changed, they should not override the bright white of the sofa bulbs, therefore I wanted to remove the sofa bulbs from the ambient_light group for the time being used.

When I turn the sofa bulbs “off”, they should be added to the group again and automatically set to the color/effects of the rest of the group.

…And with your help, it is working now perfectly! :smiley:
So thank you very much!

1 Like