How to automate a target "label_a AND label_b"

I am considering switching to labels to select automation targets. To set the context, lets say that I have, for a given entity

  • a “room” label living room
  • a “type” label light

I have many rooms, each with their label, and I have entities, including many that have the “type” label set to light.

I want to target all lights in the living room.

Unfortunately, what I get from building an automation and choosing these two labels is:

action: light.toggle
metadata: {}
data: {}
target:
  label_id:
    - light
    - salon

The labels are connected with an OR. How can I connect them with an AND?

You have to calculate it yourself.

Yes easier said than done and custom code… Depends on your appetite for that.

The indexer in my Friday’s Party project was designed to solve this very problem - from an LLM perspective. After Frenk delivered the set operations functions earlier this year I modified mine to use the builtin… The custom template basically works as you describe a. Epts two labels and an operator… Feel free to rip out the indexer and use it. For your automation. You’d hav to build it in yaml and call a custom template but you can make it work.

I put it here

And funny enough last night’s work was documentibg the darn thing.

Supports AND, OR, NOT, XOR, and limited CART (you’ll overrun CART fast only good for small sets, I had to choke it when you exceed template specs. ) returns a list of ents or a state dump.

(also for the record this - set ops on selectors) would be an incredible add to the picker. Its amazing with an LLM)