IKEA Button Press Actions Dependent on States

I’ve got an IKEA Remote (one of the five button version) that works relatively well. I have each button set to a different room of the house; so center is our Living Room, Up is the Game Room, Left is the Bar, etc.

My goal is to set it so that, when each button is pressed, it turns on or off the lights in said room.

So far, the only way I’ve found to set this up is:

–IF: (Pick one light in that room) is on, turn everything off
–ELSE: Run a script that turns on the lights (based on the time of day, I have a script that sets it to various brightness and tones).

Honestly, it works…fine. But it’s a little convoluted in the setup. Has anyone found an easier way to do this that I’m missing?

You could create a light group helper for each room that contains all the lights in that room, and then just toggle it. If at least one light is on, the group will be on, so toggling it will turn all off. Similarly, if none of the lights are on, the group will be off, so toggling it will turn them all on.