Trigger on Group / Action on Group

Hi,

I would like to use a group as a trigger and perform an action on it.
I have grouped all lights in a specific area of my house. Some of the lights are Hue and some are plain switches, all controllable via Home Assistant, though.
I want “I go to bed” button that shows me with its LED if any light is still on and turns them off when I press it. (The button hardware I have in place)
More specifically, I would like to achieve two things:

  1. If any of the lights is on, I would like to perform an action (turning on a LED on a switch). Ideally, I would also directly handle the “else” case and turn the LED off if all lights are off.
  2. On a trigger, I want to turn all lights off (This works in the dashboard when I show the group there, but I don’t find an action when creating an automation)

Thanks in advance for any hints!

Best regards,
Jonas

what doesn’t a light group do that you want it to?

It isn’t clear to me from your description how the group figures into the trigger… it seems more like its state is a condition to select which action to take.

Home Assistant Generic Services

Home Assistant Core Integration

service: homeassistant.turn_off
target:
  entity_id: group.living_room_lights

@Didgeridrew

Perfect, you solved the second part, thank you already so much!

About 1.: What I want is toggle a state (the LED). If any of the lights in the group is on, the LED should be on. If all lights in the group are off, the LED should be turned of. So the trigger is actually any state change of any light in the group. And then I need a condition to check to either turn the LED on or off. Does this make sense to you?

if you create a light group, the group is considered “on” if any of them are on. so if you already have a light entity for the led, just sync the led to the light group. you can use one of the light sync blueprints… but they are generally two way syncs, so if something turns on/off the led, it will turn on/off the light group.

if you don’t want that, the automation is quite easy still. something like this:

description: ""
trigger:
  - platform: state
    entity_id:
      - light.group_of_lights
condition: []
action:
  - service: light.turn_{{ states('light.group_of_lights') }}
    target:
      entity_id: light.led

You should be able to just use the state of the group…

alias: Control Button LED based on group state
trigger:
  - platform: state
    entity_id: group.living_room_lights
    not_to:
      - unknown
      - unavailable
condition: []
action:
  - service: light.turn_{{ trigger.to_state.state }}
    target:
      entity_id: light.button_light
mode: queued

Wow guys, thank you so much, this is exactly what I was looking for!

I am new to home assistant, but I am so happy to have chosen it. Not only was I already able to do anything I wanted so far (this was the first thing I struggled with). There is also a forum where you get help literally within minutes. And not only some help, but both of you took the time to create a perfect example. What a great community and thank you again!