Turn Off Lights That Are A Specific Color

I’ll try to keep this short. I want to turn off all (RGB) lights that are currently set to a particular color. The issue I’m having is getting the list of lights that are that color.

More details. I have three RGB bulbs that I only use for notifications. So let’s say something happens and an automation turns these bulbs blue. After that, something in a particular room will happen, and an automation will turn one of these bulbs to red. And then, whatever caused the bulbs to turn blue has been taken care of, so I’d like to turn off the bulbs that are blue.

Logically, I just want to test each member of the group I’ve created, and return all entities that are blue.

My approach has been to use the light.turn_off service and use a template for the entity_id. I want the template to return a list of entity_ids that are currently blue. This is my best attempt so far:

{{ expand('light.rgb_bulbs') | selectattr('rgb_color', 'eq', (0, 255, 0) ) | map( attribute='entity_id' ) | list }}

The specific issue I seem to be running into is that the attribute for the bulb’s color (rgb_color) isn’t a string, but a tuple. And I can’t seem to match that using selectattr(). I’ve tried lots of different combinations for (0, 255, 0), square brackets, no spaces, single quotes. It only seems to match on strings.

This would be easy if I wanted to match all the bulbs that are currently on. I’m surprised I can’t figure out how to match all the bulbs that are currently blue. Have I overlooked something or is there a better way to handle this?