How to trigger an automation when the last of a collection of lights are turned OFF?

I’m new to Home Assistant and I’m pondering a way to accomplish something.

I’d like to know the best way to trigger an automation when the last of a collection of lights is switched OFF. And if one or more of the lights in the collection is turned ON, I’d like trigger another automation.

I want to treat the complete extinguishing of the lights in the collection as an indication that the occupant of the room has gone to bed for the night.

Any thoughts?

Create a light group. You can do this in the UI from Settings → Devices & Services → Helpers. You can read about it in the docs here

A light group will be on when one or more entities are on. The group will be off when all entries are off.

So once you have the group created, you can use it to trigger your automations.

1 Like

@mekaneck Thanks for the assistance. I’ve run into a snag. One of the lights I want to include in the group isn’t seen as a light by Home Assistant. It appears as a switch. I’m guessing it’s because it isn’t connected to a dimmer but rather it is connected to an ON/OFF wall switch. I have a number of light switches around my home that are Z-Wave Decora style ON/OFF units. Is there a way to get home assistant to allow switches and lights to co-exist in a group?

I noticed that when Home Assistant creates a dashboard it throws everything in a location into an Entities Card and puts a “Header Toggle” at the top of the card. That header toggle seems not to care if the entities are a mix of lights and switches. And it behaves in the way that you describe a group. If any of the entities in the location are ON the header toggle is ON. If every entity in the location is OFF then the header toggle is OFF also.

Any thoughts?

Choose the “Change Device Type of a Switch” Helper.

Open your Home Assistant instance and show your helper entities.

Or you can set up a legacy group via yaml configuration. The older style groups allow you to mix entities.

The the toggle in the entities card only exists in the frontend, so it isn’t available in the backend for you to utilize. There are ways to replicate that functionality in the backend of grabbing every switch and light in an area and putting them in a group if you wanted to go down that path (it requires some template code). But you can’t simply access the toggle that the frontend lures you into believing exists.

The two methods @Didgeridrew provided are the easiest routes to get what I think you want.

@Didgeridrew I added a “Change Device Type of a Switch” helper for the light switch and that worked perfectly. I then created a new Group and was able to add all of the lights including the light switch (as a light.)

From the Home Assistant web interface I can now turn the Group ON and OFF and all the lights respond (Very quickly I might add. Quicker than my existing script that addresses the lights.) This is awesome.

But now I’m stumped as to how to create a binary sensor (or something) that will trigger an automation if all the lights in the Group are OFF or if one or more lights in the Group are ON.

Can you help me with this last hurdle?

Edit: I just realized that I can trigger an automation from a state change of the Group. Looks like I have what I was trying to achieve. Thank you to both @Didgeridrew @mekaneck for the guidance!

As a refugee from the ISY994i world, Home Assistant is a much deeper well to plumb but I’m really impressed so far by Home Assistant and this helpful forum.

1 Like