How to Do on / OFF group switch

Hi
i am looking for way that all group switch can be on / off from one switch.
please help with some lines of codes.
thanks

When you put a number of switches into a group, you automatically get a switch that turns them all on or off at once.

This example comes directly from my groups.yaml file…
The Living Room group has a switch that turns all the others in the group on and off.

  default_view:
    view: yes
    icon: mdi:home-outline
    entities :
      - group.sensors
      - group.climate
      - group.frontyard
      - group.np_batteries
      - group.livingroom
      - group.bedroom
      - group.office
      - group.downstairs_garage
      - group.upstairs_garage
      - group.sprinklers


  livingroom:
    name : living room
    view : no
    entities :
      - switch.sun
      - switch.wind
      - switch.lamp
      - switch.recliner_table_lamp
      - switch.sofa_table_lamp
      - switch.christmas_tree

or a template switch

switch:
  - platform: template
    switches:
      mygroupswitch:
        turn_on:
          service: switch.turn_on
          data:
            entity_id: 
              - switch.myswitch1
              - switch.myswitch2
        turn_off:
          service: switch.turn_off
          data:
            entity_id: 
              - switch.myswitch1
              - switch.myswitch2
3 Likes

Hi
its works thanks
but its not toggle switch how i change switch to toggle switch.

once more question after doing groups i cant see my known_devices.yaml devices on top of screen.
any idea
thanks

You can do a group toggle using a Python script that you call from an automation for example:

state = hass.states.get(data['master']).state

if state == 'on':
    hass.services.call('homeassistant', 'turn_off',
                       {'entity_id': data['slave']})
else:
    hass.services.call('homeassistant', 'turn_on', {
                       'entity_id': data['slave']})

In automations.yaml:

- alias: "Toggle a group"
  trigger:
 ...
  action:
    service: python_script.master_toggle
    data:
      master: light.living_room_master_light
      slave: group.living_room_lights

I have mine done in this way;

Make a group in your groups.yaml file

kitchen:
  name: Kitchen
  entities:
    - light.p16tw_01
    - light.p16tw_02
    - light.p16tw_03
    - light.p16tw_04

Then, when you place the entity group.kitchen in say your livingroom group, it will have a toggle switch on it. Not the most elegant solution, but works for me.

2 Likes

thanks for everyone .
it works

that worked for me, thanks

1 Like