I am trying to make an automation where depending on the current colour of the light, it changes the lights to a different colour. I have tried using an IF statement for this but the IF statement never triggers the action. Am I doing something wrong? I checked that the RGB values of the bulb in the state menu match that in the IF statement but it still doesn't trigger the action.
#If condition never triggers action
1 messages · Page 1 of 1 (latest)
I don't think that state will be correct, you probably have to drop to YAML to do this.
Can you paste the YAML version of that code?
its got something to do with it expecting a properly formatted list, but instead its just getting 255, 174, 92 and (seemingly) just checking against 255 and returning false.
in a template you can surround with parenthesis it will work normally, doesnt seem to do that in a condition, templated or untemplated when surrounded with either parenthesis or brackets
I got this to work with a template condition. Couldn't figure out any syntax to make a state condition work:
{{ state_attr('light.kitchen_lights', 'rgb_color') == (255, 64, 112) }}
same here
I guess it's because the attribute is a tuple, and there's no syntax to represent a tuple in yaml, so I guess that's why state condition doesn't seem to be possible
So is there any way I could get round it?
I want to make it so a button on a switch cycles between a set group of colours
Like
If purple, set blue
If blue, set red
If red set green
If green set white
If white set blue
Else set white
If that makes any sense
It makes sense, and the information I've already given should help you do that.
I am very new to HA and have no experience writing YAML code, does this look correct or no? Sorry :/
you need to use a template condition
then you can enter the template straight from the ui
the template you have looks right, just need to put it in a template condition
(just don't include outer quotation marks in the UI)
Ok thank you, I have got it semi working, the only issue I have now is that it changes to a colour value a few off of what I tell it to?!!!
E.g. if I say set to 255, 213, 164
It sets it to 255, 214, 161?
Any idea why>
Here is my code: https://paste.ofcode.org/34X3Fi9iJ77iD87P38iD4JF
The first press obviously works, but when it tries to change to the second colour, it obviously doesn’t work as it is not set to the correct colour value
the state system usually reads it as a value 0-255 while some bulbs can only be set 1-100%
so it will just set it to the closest allowed value
so the answer is to change the condition to match what the bulb will actually set
Ok thank you
There is a custom macro "Color Multi-Tool" available in HACS that has a macro to get the closest color name from RGB.
Where can I find this? I have HACS installed.