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.
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.
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.
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. ![]()
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
But you can have this today! You can specify more than one target for an action, and you can mix and match different target types. I canât see how the union would be the same priority as what OP is requesting or needed at all - as itâs already cleanly implemented in the UI.
Since we can pick area/device/entity/label, and a device can only belong to one area, and itâs redundant to intersect an area with just a specific device or entity in that area (just specify the thing as the target), in this case of yours weâd be intersecting only an area and a set of labeled elements. Or several of each. Ok this is a cool edge case but an edge case nonetheless.
This last case, to me, is where itâs at. I.e. by no means are the three use cases equal in priority, but Iâd be OK with an âAndâ vs âExceptâ selector for the second target. Iâm currently managing this via groups, but past a couple hundred devices, manually maintaining device lists in multiple groups, multiple scenes, etc gets old fast. Thereâs a lot of value in being able to apply an action to an entire room, where the room knows what devices it has. And being able to have an exception can take that much further.
To be clear, my opinion doesnât mean anything around here in regards to what the dev team decides to implement. Itâs simply my take on what Iâd expect to happen.
I do spend a fair amount of time on here and discord, and my experience is that âintersectionâ is the logic that is most often requested. And many users are adopting labels for everything, so itâs often an intersection between two labels. The intersection of âholidayâ and âlightingâ labels, for example. Certainly not an edge case. Take a look at the links in my post for more examples.
The reason I listed âunionâ is not because it doesnât already exist, but because it needs to continue to exist with any implementation of any other logic. My point was that I donât expect any change to be accepted unless it allows the user to choose from the three logic options I listed.
But again, thatâs just my opinion.
Accepted. Maybe âholidayâ and âoutdoorâ (a light would know itâs light and have a light.* action while I wouldnât have a non-âlightingâ light - but thatâs semantics; good argument).
This is exactly what many of us want. Because in the current situation that doesnât allow exclude, every time you add a new light to the room you have to go and add it to every group and label that youâre currently using to exclude the side table lamp. Both are annoying, but if you had many automations with the same exclusions, I also imagine youâd exclude a label (and then just add the new side table to the side table label)
The intent could be more clear and maintainability would be significantly better if you had an automation that turned off all lights except those labeled âside tableâ or ânight lightâ.
Instead right now you create a group or label that is something like âturnoffable lightsâ or âday lightsâ or âliving room lights except side tablesâ. Sometimes those might be better options, but there are many situations they are not.
Or maybe I want to instead turn on all lights labeled âholidayâ except those in the babies bedroom because I donât want an automation to accidentally wake up the baby. Ideally thereâd even be a simple way to say âturn on all lights both labeled holiday and in the living roomâ, but not holding out hopes for anything like that if exclude is off the table.
Being able to combine include and exclude would be really powerful and could make managing these systems a lot less frustrating.
Just pointing out that all the functionality you want already exists today; the problem is that it is not available through the UI. You have to use templates (as mentioned earlier in the thread)
On the bright side, Frenck recently added a few new template filters to help with managing lists, like union, intersect, and difference. And, if you use an action that is domain-specific (e.g. light.turn_on rather than homeassistant.turn_on) you donât need to filter down to only that domain because all entities not in that domain will be ignored.
So, the action for this:
target the lights in your living room minus the side table lamps
is simply:
action: light.turn_off
target:
entity_id: >
{{ area_entities('Living Room') | difference(label_entities('Side Lamps')) }}
Or, if you prefer:
action: light.turn_off
target:
entity_id: >
{{ difference(area_entities('Living Room'), label_entities('Side Lamps')) }}
And, as a final bonus, the HA release coming out in less than 24 hours will have some UI improvements for templates, so that you can now just apply a template to a single field (e.g. the entity_id field in the above examples) and you can still use the UI for everything else! (So again for the example above, you wouldnât have to write out the YAML for the action)
So weâre not quite there for solving this WTH but itâs pretty darn close!
I would love if this were in the UI, but I wasnât aware of those newest template filters. That helps a lot. Thereâs often a way to do almost anything if desired, but the more convoluted the approach is, the harder it is to deal with maintaining automations or trying to understand WTH you were trying to do when you come back to the automation 18 months later. Also, having to drop into templates often means you lose autocomplete or dropdown support (e.g. What exactly was the exact label, did it have an underscore or a space?) so it just adds more work to deal with.
Thatâs a big usability upgrade for more complex actions!
Hereâs the direct link to that announcement of the UI improvements for templates: