Exclude Entities: Turn on/off everything, except X

This would be a fantastic feature. I have an automation to turn off all the light except on ( at night ), when nobody is home. But now, I need to add all lights to one group to turn off all the lights except that one.

I too would like to see this feature. Being able to turn off all lights except the outdoor lights would be very practical in several scenarios.

You can try turning all off then turning one on.

Yes, this was already mentioned here in post #13: In a scene it’s unpredictable, which command (on or off) is executed first. You could implement it as a script and include a delay, but it makes this workaround even worse in my opinion.

And, last but not least, there are devices that take it badly to be turned off at all, f.e. computers. Or my lawn mower, which immediately starts panicking, if it can’t detect it’s perimeter wire anymore…

Hey @matthewjohn, I feel you! When my google home accidentally turned on every light and socket in my home for the first time, transforming it into a fun fair, I seriously began to doubt, if anyone working for the google home developer team is actually living in a real smart home…

The first thing I did was to add all phrases which came to my mind to a routine that just answers, that it won’t turn everything on or off at once. But even with currently about 20 phrases in these routine some weeks ago a friend of mine still managed to turn everything on by using some regional slang I didn’t think about… :man_facepalming:

1 Like

If anyone is interested in another approach for this problem, you may check out the minimal example I posted here:

1 Like

How many people have to vote on this before we see it?

Honestly, I don’t think it works like that.

My impression is that there’s no threshold beyond which a Feature Request ‘wins the lottery’ and becomes implemented. I feel the odds of that happening largely depend on how much a Feature Request piques a developer’s interest.

Why vote then?

2 Likes

So …

In recent 0.85.x changes, entity_id: all is required to target all entities of a particular domain. The following warning appears in the log if entity_id: all is not specified:

"Not passing an entity ID to a service to target all entities is deprecated. Use instead: entity_id: "all."

Therefore, I feel that it is even more useful and appropriate to implement an “EXCLUDE” feature.
The use case is simple:

- service: light.turn_off
  entity_id: all
  exclude: light.porch_light

This would greatly simplify configurations and for users such as myself with many devices, would be of great value. Putting lights (and other devices) into internal and external groups is a poor workaround at best, while this method would be far more scalable and flexible in my opinion and does not appear to be overly complex to implement.

4 Likes

Maybe this also comes close to what you request. It’s a way to create groups excluding members of other groups. You could then use the new group to turn off your lights (minus the few excluded ones). And you can use the groups in triggers, too, if you like.

this probably works … but the idea is to have a simple way to do this where any user can understand.

The way I described my use case seems super simple and fast and I don’t think it would take much to implement, although I’m not a dev, so if there is a caveat then someone would have to explain it to me. :slight_smile:

I’ll like also to see this implemented :slight_smile:, I usually turn off all lights when I tell Alexa “Good Night”, but I want the security lights in the garden to remain on…

Regards

While this would be a nice thing to have, it would have to be implemented in a way not to confuse.

lightsoff:
sequence:
- service: homeassistant.turn_off
entity_id: group.all_lights, group.all_switches
exclude: switch.espurna_pow2

how to exclude one of switch from group.all_switches?

i think is possible to copy group.all_switches to group.all_switches_nopowe2 and user this group.
but exclude (if its work) is easier

+1 for this, it would be really awesome

Now that 0.104 is out and the default group.all_entity feature has been removed, the need for exclusions is potentially greater.

Using “entity: all” is great for service calls but now “all” groups need to be manually created and worse, maintained.

For example, Consider a user who has manually created a new group.all_lights in 0.104.0 and wishes to use this group as a trigger.

- alias: 'An automation'
  trigger:
    platform: state
    entity_id: group.all_lights
    exclude: light.porch_lights, light.driveway_lights
    to: 'on'
    for:
      hours: 12

This user’s config could be more-easily managed if exclusions were implemented; however, without exclusions, the user must maintain separate groups, resulting an onboarding/offboarding process for all new lights.

Manually maintaining separate groups introduces a lot of unnecessary administrative overhead.

2 Likes

I think, the all_group-feature should be mimicable with the recent addition by @jhenkens to my script linked above…

This works for me:

Maybe somebody is looking to switch off lights, switches etc… I was looking for a good way and now I’ve found this too… but in case somebody finds this useful with the formatting…

  - service: light.turn_off
    data_template:
      entity_id: >-
        {% set domain = 'light' %} 
        {% set state = 'on' %}    
        {% set compare = 'eq' %}    
        {% set filter =['nothing to exclude'] %} 
        
        {% set MyVal= states[domain] | selectattr('state',compare, state) 
        |  rejectattr('entity_id','in', filter) 
        |  rejectattr('attributes.is_hue_group', '==' , true) 
        |  map(attribute='entity_id') 
        | join(',') 
        %}

        {% if MyVal.count('.') >=1 %}
        {{ MyVal }}
        {% else %}
        light.dummy
        {% endif %}
  - service: switch.turn_off
    data_template:
      entity_id: >-
        {% set domain = 'switch' %} 
        {% set state = 'unavailable' %}    
        {% set compare = 'ne' %}    
        {% set filter =['switch.57281806d8bfc004de91_1'] %}
        
        {% set MyVal= states[domain] | selectattr('state',compare, state) 
        |  rejectattr('entity_id','in', filter) 
        |  rejectattr('attributes.is_hue_group', '==' , true) 
        |  map(attribute='entity_id') 
        | join(',') 
        %}

        {% if MyVal.count('.') >=1 %}
        {{ MyVal }}
        {% else %}
        switch.dummy
        {% endif %}
  - service: media_player.turn_off
    data_template:
      entity_id: >-
        {% set domain = 'media_player' %} 
        {% set state = 'off' %}    
        {% set compare = 'ne' %}    
        {% set filter =['nothing-to-exclude'] %}
        
        {% set MyVal= states[domain] | selectattr('state',compare, state) 
        |  rejectattr('entity_id','in', filter) 
        |  rejectattr('attributes.is_hue_group', '==' , true) 
        |  map(attribute='entity_id') 
        | join(',') 
        %}

        {% if MyVal.count('.') >=1 %}
        {{ MyVal }}
        {% else %}
        media_player.dummy
        {% endif %}

It should be self explaining. At the beginning you tell what Domain, eq or ne of status, and an exception list. I’m able to switch off all lights except them in the bedroom. I hope somebody finds this useful too.
With the mediaplayers I’m not finished at the moment it works, but they have playing, pause on off etc… so checking for on is not usefull… so I’m checking for not off

3 Likes