I am trying to get an RGB bulb to set its color based on an MQTT message formatted 255, 255, 255 and I cannot for the life of me get it to accept it. Above is what I ended with before deciding I needed some help, the automation triggers fine, but it throws the error below. I think there is something I am just missing in the formatting of it all, but this is my first go at lists and RGB so I am a little in the weeds. Thanks for any help!
Error while executing automation automation.ledvance_a19_rgbw_00061a28_1_light_color. Invalid data for call_service at pos 1: None for dictionary value @ data['rgb_color']
Iâm pretty sure that wonât work either. The problem is the value for rgb_color is a template (one, big, multi-line template), and a template will output one string. The string will contain end of line characters and dashes, but that wonât make it a list, because that is YAML, and the YAML parsing happened a long time before when the file was originally parsed.
Nutz! I think I now understand the principle correctly. You create the listâs âframeworkâ in YAML:
rgb_color:
-
-
-
and restrict Jinja2âs templates to generating the content of each item in the list:
rgb_color:
- "{{ }}"
- "{{ }}"
- "{{ }}"
So the scope of the templating is restricted to creating strings for each list item. Any expansion of this scope and then the whole result becomes a string (with only the appearance of being a list).
EDIT
So whatâs the accepted etiquette for âbumpingâ a long-overlooked PR? Because that one would definitely help alleviate this very common struggle with setting rgb_color.
I donât really know. I have seen people ask on discord to have their PRâs looked at, but I try to avoid doing that myself. Besides, this one has sat around long enough that it has to be re-done to be merge-able again. Same goes for the doc PR that goes with it. And I didnât want to do the work, only for it to sit and be ignored again (which, I think, Iâve already done once, so I should have said I donât want to do the work again.)
Thanks for all the help, I got it working but needed to change the RGB string to hex on the MQTT side, and ended up with the code below. Input is now in the form âRRGGBBâ