Currently I’m trying to take a json field and send it via a light_on service. Unfortunately when I take my input it sends the data out as ‘[x,y]’ including the single quotes. I’m trying to figure out how to get rid of the single quote. I know I can use the replace() method do accomplish this but I’m not sure how it’s supposed to be implemented inside an automation. Any help would be appreciated.
Post more code so we can see what you’re doing
sure
this_is_a_field: {{ [input.value_1 | int, input.value_2 | int, input.value_3 | int] }}
results in '[1,2,3]'
and I need [1,2,3]
i just need to remove the single quote
{{ [input.value_1 | int }}, {{ input.value_2 | int }}, {{ input.value_3 | int] }}
ok…
my data should have been … my bad
this_is_a_field: '{{ [input.value_1 | int, input.value_2 | int, input.value_3 | int] }}'
inside of single quotes. I left that out. I tried your solution and I get an error ‘Extra {’
I’m trying to send an xy_color
to a light but when the values are read it sends the json parameter with the single quotes. i don’t know jinja so I’m left to googling and trying and failing and googling again. I need to send the json parameter as a list? or an array I think. So I’m having trouble doing that. Instead it’s sending it as a string.
My answer still stands. Send a 3 number separated by a comma. I’m pretty sure that’ll work - or at least get close. What you’re passing isn’t a list, it’s one big string.
ERROR (MainThread) [homeassistant.bootstrap] Invalid config for [automation]: invalid template (TemplateSyntaxError: unexpected ‘}’, expected ‘]’) for dictionary value
rgb_color: '{{ [states.input_slider.red.state | int}} , {{ states.input_slider.green.state | int }}, {{ states.input_slider.blue.state | int] }}'
What else did you try? The template dev tool is your friend.
How 'bout:
'[{{ [states.input_slider.red.state | int}} , {{ states.input_slider.green.state | int }}, {{ states.input_slider.blue.state | int] }}]'
(wrap the expression in [])
I’ve tried everything. Every iteration I can think of. It still sends it out as a string with the single quotes.
what I want to do is
{{ name|replace("'","") }}
but I don’t know how to do that in the automation.
I think you’ll still have the same issue. Is it possible that rgb_color needs floats instead of integers?
first off… thanks for the help. This has been driving me nuts
rgb needs ints… xy needs floats…
and I honestly had no idea the template tool existed… crazy enough I can get the output I want but when it’s loaded on startup it doesn’t see it as a ‘[r, g, b]’ it sees it as [r, g, b] which is what I want. Unfortunately HA halts because it’s expecting a string, ‘[r, g, b]’, and I’m assuming that string is a string in single quotes where the single quote is part of the string… Does that make sense?
I want to send the string as a string without the single quote. in other conventions it’s completely possible via trim, len, left, right and so on… I just don’t know how to do that with python and jinja through templates.
It looks like there’s a “replace” filter that you can try.
One other suggestion is the alternate non-single-quote way to express templates:
rgb_color: >
[{{ [states.input_slider.red.state | int}} , {{ states.input_slider.green.state | int }}, {{ states.input_slider.blue.state | int] }}]
that magic greater-than says “template starts on the next line”.