Basically, what I want to do is take the color state from an existing light and pretty much copy/paste it into my other lights. I currently have remote light sensors and I pass the detected color to an MQTT light.
Here’s what I threw together untested, to get you an idea of what I’m trying to do.
I must say that YAML is one of the least-intuitive (non-intentional) languages I’ve ever used. When it comes to moving data around, it feels like disassembling and rebuilding a car engine just to change the tire.
I can’t try as i’m not home, but your rgb_color would need to be in the format (0,0,0)
Not sure what data your sensor has, but if I wanted to get the data out of another light, the data would be like this: {{states.light.bedroom_up.attributes.rgb_color}}
Can you share the exact YAML code? It should have worked if you had exactly what you posted first, but changed states.light.rgb_sensor.state.color to states.light.rgb_sensor.attributes.rgb_color, assuming, of course, that light has that attribute. Or, you could use something like:
Invalid service data for light.turn_on: None for dictionary value @ data['rgb_color']. Got ['(228, 223, 255)']
I tried with and without apostrophes around the curly braces, and with/without the square brackets. You guys are definitely very helpful. I’ll be sure to post the working version when it gets going.
No, the outside (single) quotes are needed. For me, at least, it’s trying to figure out what rgb_color wants. Let me look at some code and try a few things. If I come up with something better I’ll let you know. Maybe someone who has been through this will jump in in the interim…
state_attr is returning a tuple, which, when (by default is) turned into a string, comes out “(1, 2, 3)”. rgb_color wants a “list” of three numbers. Although I’m not 100% sure, in YAML, I believe that can look like either of these:
rgb_color:
- 1
- 2
- 3
or
rgb_color: 1, 2, 3
So, to convert the tuple returned by state_attr (or states.xyz.attributes.xxx) into a string of three numbers separated by commas (with no parentheses or brackets), my latest proposed solution uses the string filter (to explicitly convert the tuple to its string representation) followed by two replace filters (to get rid of the parentheses.)
Whoa! I’ll admit I’m pretty new to this, so I’m sure I’m missing something. I was under the impression that when you use data_template, that the template needs to be quoted, either directly using quotes, or by using the “>” technique. Maybe that’s wrong.