Hi HA community.
I have a bit of code that use to work… 4 years ago (finally getting around to fixing it) and I’m stumped, something must have changed…
I’ve got a file called “random_color.yaml” containing the following…
'{{[
[0,0,255],
[255,0,255],
[0,255,0]
]|random}}'
I add “random” colours I like to this file, and all my automations that use random colours select a set of RGB parameters from this list… ( Note: pasting this into template in developer also executes correctly)
now, I have an automation that passes a data template to a script,
Automation…
- alias: 'random RGB Homeassistant'
trigger:
- platform: state
entity_id: input_boolean.random_rgb
to: 'on'
action:
- service: script.random_color
data_template:
entity_id: light.my_light
rgb_color: !include /config/random_color.yaml
brightness: 200
and finally, the script…
random_color:
sequence:
service: light.turn_on
data_template:
entity_id: "{{ entity_id }}"
rgb_color:
- "{{ rgb_color.replace('[','').replace(']','').split(',')[0]|int }}"
- "{{ rgb_color.replace('[','').replace(']','').split(',')[1]|int }}"
- "{{ rgb_color.replace('[','').replace(']','').split(',')[2]|int }}"
brightness: "{{ brightness }}"
I get the following error,
Template variable error: 'homeassistant.helpers.template.Wrapper object' has no attribute 'replace' when rendering '{{ rgb_color.replace('[','').replace(']','').split(',')[0]|int }}'
Note that if you use the following in developer → template… it renders correctly
"{{ '[255,0,5]'.replace('[','').replace(']','').split(',')[2]|int }}"
= 5
Any ideas?