Script Data Template Manipulation - RGB data

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?

random_color:
  sequence:
    service: light.turn_on
    target:
      entity_id: "{{ entity_id }}"
    data:
      rgb_color: "{{ rgb_color }}"
      brightness: "{{ brightness }}"

In the past, the value of rgb_color was passed as a string. That’s why your script used a string’s replace method to remove the string’s brackets and split to convert it to a list. It’s now passed as a list so there’s no need to attempt to convert it from string to list (in fact, it fails because a list doesn’t have a replace method).

Ha… well things just got a lot simpler, no need for the script at all… thanks heaps.

  action:
    - service: light.turn_on
      data_template:
        entity_id: light.my_light
        rgb_color: !include /config/random_color.yaml
        brightness: 255