Automation: Make groups toggle as a whole like in UI

So you know how in the UI a group of lights and switches can be toggled with the switch next to group name.

Now this switches the whole group on/off instead of toggling each switch/light individually.

I want to acomplish this with automation, where instead of just toggling each individual switch it toggles the group as a whole.

for your action section use “homeassistant.turn_on” and then “group.lights”

Here is an example from my config:

  - alias: 'Turn Off Outside Lights'
    trigger:
      platform: sun
      event: sunrise
    action:
      - service: homeassistant.turn_off
        entity_id: group.outside_lights
4 Likes

Replace your service line with this service template

service_template: >
        {% if is_state('group.outside_lights','off') %}
          homeassistant.turn_on
        {% else %}
          homeassistant.turn_off
        {% endif %}
6 Likes

Hi everyone,

Is this still the only option to toggle light-groups?
As light-groups are much promoted now, I wonder If there was any progress on this?

I think

- id: '0x00158d000428fb20_action_single_left'
  alias: (S09) switch action single_left
  initial_state: true
  trigger:
  - entity_id: sensor.my_n01_p03_switch_s09_wandschakelaar_action
    platform: state
    to: single_left
  action:
  - entity_id: light.group_n01_p03_spots
    service: light.toggle

is much more readable than

- id: '0x00158d000428e9a1_action_single_left'
  alias: (S06) switch action single_left
  initial_state: true
  trigger:
  - entity_id: sensor.my_n02_p00_switch_s06_wandschakelaar_action
    platform: state
    to: single_left
  action:
  - data:
      entity_id: light.group_n02_p00
      transition: 0
    service_template: >
      {% if is_state('light.group_n02_p00','off') %}
        homeassistant.turn_on
      {% else %}
        homeassistant.turn_off
      {% endif %}