Trigger Automation if Any light with label is on, or if all are off

I haven’t found anyone doing quite what I’m trying to do. I want to enable a status LED if any light that has label “Main Floor Light” is On. If all lights that have the label are off, then I want to turn the LED off. I have automations that will Trigger all lights on/off based on the label, but have not been able to trigger an automation based on the status of all lights with the label being Off, or ANY of the lights with the label being On. Any suggestions?

I don’t think you can - labels don’t have a state. Won’t a group do what you want?

Triggers are event-based, so there is no trigger for things being in a certain state.

The closest current option is to create a Template Binary sensor that track whether any of the labelled entities are “on”, then use that binary sensor’s state changes as your trigger for the LED.

The state template for that binary sensor would be:

{{ label_entities('Main Floor Light') | select('has_value')
| reject('is_state', 'off') | list | count > 0 }}

That will give you a binary sensor that whose state will turn “on” when any of the labelled entities turn to “on” and will stay “on” until none of those entities’ states are “on”.

It doesn’t do it… I believe Petro is doing things in the template integration that may make this possible in the future but they simply don’t now. You’d have to be able to have the ents collected by the state be able to trigger and that’s where it breaks down at the moment.

If it were possible you would theoretically be able to tag ents to trigger on say motion or something else. It just doesn’t work that way atm

@jackjourneyman
Yes, a group should do what I need. Still learning, hadn’t thought about using a group because the group seemed like it was designed more as a switch to control a group of lights, as opposed to using it to get status. But I just did some testing and it should do the job I’m looking for. I think using Labels is a bit more multi-purpose and elegant, but hey, it works at least. :slight_smile:

@Didgeridrew I gave the state template a try, but it didn’t like it for some reason. Which is too bad, cause I liked the idea of using a binary sensor for it.