Phil, your point of the state “on” is obvious but was overlooked, thanks .
Having said so, my HA wont accept the string:
condition: template
value_template: “{{ is_state_attr(‘light.hue_go_1’ , ‘rgb_color’ , (255, 207, 120) }}”
It say: Message malformed: not a valid value for dictionary value @ data[‘condition’][0][‘condition’]
I think I understand the main difference between a tuple vs a list (mutability; nicely summarized here) but help me understand the syntax. When defining it in YAML it’s with square-brackets:
[215, 125, 125]
whereas in the Jinja2 template it’s with brackets:
(125, 125, 125)
Is that simply due to the convention used by the specific interpreter? In other words, YAML represents tuples and lists the same way, with square-brackets, but Jinja2 is pythonic; lists are represented differently from tuples (square-brackets vs regular brackets).
YAML, AFAIK, doesn’t have such a thing as a tuple.
When using a template, to YAML, it’s just a string. It has no idea that it’s Jinja, JSON, or whatever. E.g., notice: value_template: "{{ ... }}". See the quotes? It’s a string!
Now that string gets interpreted as a Jinja expression. And in Jinja (at least in this Python based implementation) there are both Jinja and Python constructs. (E.g., is_state_attr() is really a Python function. See this piece of code.) And objects/variables are Python objects. E.g., the rgb_color attribute of a light entity is a Python tuple. So, when you’re using the is_state_attr() function with this attribute you need to compare it against a tuple – i.e., (255, 207, 120), not [255, 207, 120], because that’s a list, and in Python (255, 207, 120) != [255, 207, 120].
OK, so it’s because is_state_attr is a python function and rgb_color is a tuple so the supplied argument must also be a tuple.
I did a search and, like you said, YAML has no means of defining a tuple and so it must be defined as a list. That explains why rgb_color expects a tuple yet this is the way to define it (like a list):
Well, that’s a different story. That’s a service call parameter, which is controlled by a “schema”. And in this case it’s this piece of code. So, yes, since YAML can only represent a list, you have to enter it that way. But the schema converts it to a tuple (behind the scenes.)
Ok, 3 hours and I have to give up… hopefully one of you sharp minds can assist finalizing this with me?
Basically this is the mission. Get an automation running where i get to toggle through different hue_scenes depending on what state of rgb color the entity has.
{% if (check the rgb color as above on a specific light entity) %}
true = run NEXT hue.scene call service with a specific group_name and scene_name
{% else %}
false = run START hue.scene call service with a specific group_name and scene_name
{% endif %}
Ok, so you’re not really looking for an automation condition after all. It seems you want to use data_template in a service call to figure out which scene to apply. At least that’s what it seems like you’re looking for.
I don’t use hue, so I’m not sure what to tell you. E.g., how do you know what scene has been previously applied? I’m guessing it’s more than just knowing if you’ve applied the last scene (and therefore should start at the “first” scene again), but the template would also have to be able to figure out which scene is “active” so it can figure out what the “next” scene is in the other cases.
Maybe what you should do is use a counter. Have the automation first increment the counter if it has not reached it’s maximum value, or reset it if it has, then use that in the automation to select a scene (group and/or scene name) from a list or lists. Something like: