Exclude Entities: Turn on/off everything, except X

It would be nice if you could turn on/off everything but exclude certain entities. A use case is to simply add:
service: light.turn_off to my config to turn off every light in the system…however, I may want to exclude the porch lights. To simplify the config, I’d like it if we could do something like:

service: light.turn_off
  exclude:
    entities:
      - light.porch_light
      - etc.
`
that would make it much easier to configure global actions, IMO

Good idea. However, it isn’t that hard to do it now.

You can use scene or groups for this settings?

True, but I got the idea from someone who asked on Gitter and it makes sense. If you add new devices, it sucks having to re-configure all of the different scenes, scripts, etc.

With this method, no updates to configurations are necessary unless you want them excluded. This seems to be a dead-simple add on, no?

1 Like

not sure what you mean here - got an example of how it can be easily accomplished?

I’ve broken my lights into interior and exterior lights. My shut all really only affects the interior lights.

https://github.com/CCOSTAN/Home-AssistantConfig/blob/master/group/Indoor_Outdoor.yaml

Sorry for the late reply. CCOSTAN gave an excellent example.

I’d like to bring this up again, because I’m also missing an exclude function. Yes. working with groups as a workaround is possible but this gets pretty complex quiet fast and ends in way to much logical groups which get hard to take care of after a while.

But sticking to the concept of groups it would be great to exclude entities from groups - one example:

- action: homeassitant.turn_off
  entity_id: group.bathroom  
  exclude: switch.washingmachine

This would make my configs and groups look way more well arranged… :slight_smile:

2 Likes

I still agree, but ultimately use the suggested “interior / exterior” groups … not as convenient, as home assistant has the wonderful feature of service: light.turn_on which is a superior catch-all without having to touch the group config.

I’d like such a feature too, using groups may not always be the good answer.

Example

Using device tracker (with nmap), I want to be notified if an unknown device join the network. It would be pretty neat to do something like that :

groups.yaml

trusted_devices: device_tracker.my_computer, device_tracker.my_phone

automations.yanl

trigger:
  - platform: state
    entity_id: group.all_devices
    excludes: group.trusted_devices
    to: 'home'
(...)
2 Likes

+1 for this feature request

1 Like

I also vote for this feature, please implement it.

+1. The more lights you have controlled by home assistant, the more this feature is needed. I want to turn off all of my lights except for one in the kitchen, so I have to make a group of all of them except that one, and then when I add more lights, the scene breaks unless I remember to update that group. Then I want to turn off all of the lights except for one in the bedroom, so I have to make a group of all of them except that one, and when I add more lights I have to update both groups. Etc. You end up with a ton of huge groups and it’s not manageable.

I’ve been trying to work around this in scenes by turning off the group of all lights and then turning on the one light, but groups don’t seem to care about order and the behavior is unreliable. I’ve also tried using a script, but it waits for each light as it goes so it’s very slow.

As far as implementation goes, the most generally useful pattern I can think of would be something that allows both adding and subtracting entities to form a group as you go, like:

entity_group:
+group.all_lights
-group.bedroom_lights
+light.bed

2 Likes

+1

I have a number of groups that are just a replication of another group excluding one or 2 devices, it would be great to simplify this.

2 Likes

Hey Guys

Are you still interested in being able to exclude something from a group?

I also need this feature so I started tinkering with the code to make it work. It works roughly on groups so if you turn on/off a group with items excluded, those don’t get actioned. They do however participate in determining the group’s state. You can also use this in scripts for light/switch domains for now. Just add ‘exclude’ where you see ‘entity_id’. You should also be able to exclude a group from a group.

The initial commit is here:
https://github.com/mateuszdrab/home-assistant/commit/d4b7f62dc686759fd69719ff5ac82d8bcb1a582f

Example:

{
  "entity_id": "group.test2",
  "exclude":"light.bed_lamp"
}

and an example in a script

test_lights:
  sequence:
  - service: light.turn_on
    entity_id: group.test2
    exclude: light.bed_lamp

This is probably bound to be buggy as hell since I’m not a Python programmer but a C# guy however it seems that Python is amazingly simple and it’s gone well so far.

Looking forward to some feedback, you should be able to pull the master branch from me as this was merged with latest master from homeassistant today.

Thanks

1 Like

Did this ever get implemented? I would like this also!

Still not working I guess… Would be a good thing to have.

This would be awesome!

piling on here as I would also really like to see something like this. My use case is simple and I believe a very good argument for the need for this feature.

My automations, groupings and sheer number of devices is growing very quickly. Managing automations and scenes that turn on/off groups of devices becomes difficult to manage in terms of updating and maintaining them. Its much easier to split into groups and write automations that trigger scenes or turn on/off groups.

In many cases I need to aggregate groups together in order to avoid turning off or on something that otherwise belongs in the same group as everything else.

chiming in here as well - this would be great to see this implemented. My use case is similar to those above: I want to easily turn off all lights except the master suite. When I add more lights to HA, I don’t want to have to re-do groups to add them back in.