WTH isn't there a "except..." for turn off/on ?

I have a few automations that turn on / off all lights except a few specific ones.
It would be great to be able to just add that list to the turn on/off service as a parameter instead of using a template.

Isn’t that what scenes are for?

Can you provide a more specific example?

If you’re asking for a way to run a scene, but exclude some devices, check out this WTH: WTH - Why can't we apply a scene to an area?

If you’re asking to call light.turn_on on an area minus a device, that doesn’t exist yet. While it is a good WTH, I would recommend against using this feature(if it existed) because of the potential headache it could cause.

For example, imagine you target the lights in your living room minus the side table lamps. What happens when you add a new lamp to the room? It won’t be excluded and you’ll have to update every automation with the exclusion. As @sandman98321 mentioned, a scene is more suitable because you update new devices in one spot.

1 Like

This ^ (side note I love @potelux they’ve been a ride or die)

I feel like this actually also ties to a separate post I made WTH - Why isn't there a NOT operator for conditional cards?

I think having more NOT operators/except in home assistant would be cool in general. Sometimes it’s way easier to list everything you don’t want then what you do.

1 Like

You could easily turn all lights except a subset on/off by leveraging labels. E.g. give all lights you won‘t like to turn off by a specific action (button press, automation….) a label „dont-turn-off“.

Then you can use a template like this:

{{
  states.light 
  | map(attribute="entity_id")
  | reject("in", label_entities("dont-turn-off"))
  | list
}}

Use this template directly in the service call or wrap it in a helper sensor if you like.

This can also be extended to filter areas, floors, other domains etc. These are all accessable in templates.

2 Likes

Yes, I’m asking about a light.turn_on (or switch.turn_on) on an area minus x devices. Or a light.turn_off all the lights in the house except a few I want to keep on.
Right now I can do it with a template, but it would be cleaner if it would be possible to do in the light.turn_on / off call

Yes, I’m using a template similar to that one now. Just would like if it were possible to do directly in the service call. :slightly_smiling_face:

You can always do that when you use an automation or script. If you like do to so via UI using e.g. button card you simple can wrap this in a script and call the script instead of light.turn_on

That’s pretty much what I do now. Could be better

I (respectfully) disagree. The new lamp would be tagged with the ‘lamps’ label, and the exclusion rule could target labels (or areas, floors, etc) in the exact same way that the light.off function can.

So it would look like: automation action = light.turn off in area ‘living room’ EXCEPT label = ‘lamps’

I think it would work really well, especially for smart plugs which may change regularly.

The problem is that one set of logic isn’t any more desirable than any other. l don’t think this would ever be implemented unless it encompasses the other commonly-requested logic options. Which I think would be:

  • The UNION of Selection X and Selection Y (everything matching either set)
  • The INTERSECTION of Selection X and Selection Y (only the things matching both sets simultaneously)
  • Selection X EXCLUDING Selection Y (only the things that match the first set but don’t match the second set)

Similar requests for reference:
https://community.home-assistant.io/t/allow-selectable-and-or-logic-when-targeting-entities-in-automation-gui/731958
https://community.home-assistant.io/t/and-not-or-for-labels/713412

Non-UI:
https://community.home-assistant.io/t/select-match-all-any-when-multiple-labels-selected-in-call-service/738160
https://community.home-assistant.io/t/label-entities-allow-multiple-labels-selection-intersection/715659