How to get back an "all lights" on/off switch in 0.104?


prior to 0.104 I had an entities card with an entity group.all_lights.
This gave me the ability to quickly check if all my lights were off or turn them off with a single button toggle.

Now that the all_lights group is gone, is there an elegant way to get back this behavior without having to define such a group manually?
Using entities: all is not a solution since I only want to target entities from the light domain.
Using an entity filter card with a light.* filter would add a switch for every light entity that is found, so that’s not it either.



You may find this earlier post suits your needs;

Hope it helps?


Thanks, John!
Somehow I missed that thread.

I solved it in my case by building a template switch using one of the proposed templates:

platform: template
    value_template: >
      {% set domain = 'light' %}
      {% set state = 'on' %}
      {{ states[domain] | selectattr('state','eq', state) | list | count > 0 }}
      service: shell_command.nop
      service: light.turn_off
        entity_id: all

The switch turns on when at least one light is on and off when all are turned off.
When manually turning it off, all my lights are turned off.
As I never felt the need to turn all my lights on at the same time, I set the turn_on: config to basically doing nothing:

  nop: /bin/true



@sebk-666 this is really helpful! I am new to this and looking to leverage a goodnight routine that can turn off almost all the lights/switches. How would I exclude a few known items?

Well, the “switching” part of the template switch is bluntly calling the “light.turn_off” service on all entities (which only has an effect on entities in the “light” domain).
The template part is used to determine if the switch should be in an “on” or “off” state.
The template retrieves the state of all “light” entities and if at least one is “on”, it evaluates to “true” and otherwise “false”.

For your routine it’s probably easiest to create a script that calls light.turn_off on a list of entities that you maintain manually.
Your goodnight routine then only has to call the script.

You can auto-generate a list of all your lights in the UI via “Developer Tools” → “Templates” and then paste this as template:

{% set domain = 'light' %}
{% for item in states[domain] %}
- {{item.entity_id-}}
{% endfor %}

Then take this list and add it to the script, leaving out the lights that you don’t want to turn off in your goodnight routine.


1 Like

Use reject in the template.

Copy-paste this into the Template Editor and change the entities you want to exclude.

{{ states.light
   | selectattr('state', 'eq', 'on')
   | map(attribute='entity_id')
   | reject('in', ['light.hallway', 'light.bathroom'])
   | list }}

The resulting list can be used with the light.turn_off service call.

  - service: light.turn_off
      entity_id: >
        {{ states.light | selectattr('state', 'eq', 'on') | map(attribute='entity_id')
            | reject('in', ['light.hallway', 'light.bathroom']) | list }}
1 Like