Confirm xy color of a light in an automation "Choose" condition

Hi Everyone,

I’m trying to set up an automation that will cycle a light through a set of scenes on each press of a button. I’m using a “Choose” action with a condition set to the state of the light, with the state set to attribute and the attribute set to xy_color in order to determine the current colour. The current colour will be used to determine which scene to cycle to next.

However, I’m not sure how to form the ‘state’ string, as anything I try always results in a “Condition Did Not Pass” when I test the condition.

This is the current state of the light according to the developer tools:

And this is the set up of the choose action:

I’ve tried using the rgb_color attribute 255, 9, 0 with the same result. I also tried the same with the hs_color attribute with state set to 2.118, 100

I have managed to get a condition to pass by testing the color_mode attribute with state: xy so it seems the condition check can work but I get the impression I’m not giving the state string in the correct form for it to pass.

Sorry if this is a bit of a noob question but I’ve spent a long time trying to find the solution. I’ve wrapped the state string in round, square and curly braces, tried various combinations of spaces, commas, single and double quotes and nothing works!


Welcome to the community forums!
Use a template condition:

condition: template
value_template: "{{ state_attr('light.isla_s_bedroom_light_light', 'xy_color') == (0.1561, 0.1606) }}"

Amazing! That worked thanks.

I still don’t understand though how to correctly use the light colour attribute in the ‘State’ condition checker. I know it doesn’t matter now you’ve provided a solution, but I like to try and understand what was incorrect about the method I was trying to use.

Thanks again!

Try representing the value as a tuple:


Doesn’t work; see below.

When you past the code into Developer Tools / Template you will see that the output is a tuple (you can also check it with {{ state_attr('light.isla_s_bedroom_light_light', 'xy_color') is tuple }} ).

🥷 by Taras.

Problem is that the tuple neither trigger an automation nor meet the condition.

I just tested it and you’re right; a State Condition’s state option handles its value as a string. So even if one assigns it a list or tuple, it’s handled as a string. Plus it doesn’t support a template so we can’t leverage Home Assistant’s native typing to make it handle it as anything other than a string.

So I was never going to get it to work! Thanks for clarifying what the issue was.