Automation to toggle lighting groups on/off

I have a lighting group light.ben_bedroom_uplighters and a toggle input_boolean.toggle_bedroom_ben_lights both set up as Herlpers.

I have defined an automation to toggle the toggle so far so good.

Now this is where I am stuck. I can do an automation that turns a single light on/off depending on the toggle. I can have an action per light

alias: Toggle Ben Bedroom Lights 1
description: ""
trigger:
  - platform: state
    entity_id:
      - input_boolean.toggle_bedroom_ben_lights
    from: "off"
    to: "on"
    id: power-on
  - platform: state
    entity_id:
      - input_boolean.toggle_bedroom_ben_lights
    id: power-off
    from: "on"
    to: "off"
condition: []
action:
  - choose:
      - conditions:
          - condition: trigger
            id: power-on
        sequence:
          - type: turn_on
            device_id: a4659e3c5bb97053b6e86f0b98115608
            entity_id: light.uplighter_l
            domain: light
          - type: turn_on
            device_id: daf6c0d07ed5871c19a709ed2a820c91
            entity_id: light.uplighter_r
            domain: light
      - conditions:
          - condition: trigger
            id: power-off
        sequence:
          - type: turn_off
            device_id: a4659e3c5bb97053b6e86f0b98115608
            entity_id: light.uplighter_l
            domain: light
          - type: turn_off
            device_id: daf6c0d07ed5871c19a709ed2a820c91
            entity_id: light.uplighter_r
            domain: light
mode: single

But how do I change it so rather than doing entity_id: light.uplighter_l & entity_id: light.uplighter_r I simply turn the whole lighting group ( light.ben_bedroom_uplighters) on or off?

As a side note I actualy built this with the GUI editorl, not in YAMLl. I notice it uses device_id & entity_id. If I was building this from scratch in YAML do I need to look up all the device IDs and include both or can I just use entity ID. If there is a doc covering this that would be great.

alias: Toggle Ben Bedroom Lights 1
description: ""
trigger:
  - platform: state
    entity_id:
      - input_boolean.toggle_bedroom_ben_lights
    from:
      - "off"
      - "on"
    to:
      - "on"
      - "off"
condition: []
action:
  - service: 'light.turn_{{ trigger.to_state.state }}'
    target:
      entity_id: light.ben_bedroom_uplighters
mode: single

Use a Service Call instead of a Device Action because it allows you to use an entity_id. Plus you can template the options of a service call (as seen in the example I posted) whereas a Device Action doesn’t support templating.

1 Like

Thanks, that is exacly what I was looking for. Did a bit og googeling for the service stuff you used and what I found is quite technical. I get what is going on but are there any good tutorials?

1 Like

PS are the quotes around on/off needed.

Also makes me realise I could just have a trigger on zigbee button pressed and toggle state of light group, no need for boolean.

I always recommend starting with the official documentation. Here’s the section for Triggers.

You’re welcome!

Please consider marking my post above with the Solution tag. It will automatically place a check-mark next to the topic’s title which signals to other users that this topic has been resolved. This helps users find answers to similar questions.

For more information about the Solution tag, refer to guideline 21 in the FAQ.

All done :wink: