Problem with HA script from esphome. RGB

I am starting on work to create some buttons for my daughter to control her new LED strip. She only needs to change colour with these buttons.

The LED strip works fine inside HA. from the developer tools it has the following attributes

To change the light via HA calling a service via the developer tools look likes this:

service: light.turn_on
data:
  rgb_color:
    - 216
    - 14
    - 255
target:
  device_id: c3fa823141ba3b79dc9893904d426142

After some research i think the solution is to make a script that can receive the parameters from esphome. so in my script file i have:

set_light_rgb:
  alias: 'ESPHome RGB light set'
  sequence:
  - service: light.turn_on
    data_template:
      rgb_color:
      - '{{ red }}'
      - '{{ green }}'
      - '{{ blue }}'
      target:
        device_id: '{{ lightid }}'

and my esphome config looks like this:

 binary_sensor:
   - platform: gpio
     pin: 
       number: D4
       mode:
         input: true
         pullup: true
     name: "set lights"
     on_press:
         then:
          - homeassistant.service:
              service: script.set_light_rgb
              data:
                 lightid: 'c3fa823141ba3b79dc9893904d426142'
                 red: '255'
                 green: '255'
                 blue: '255'

However nothing is happening. the esphome log see the button press and shows:

within HA the logbook does not see it. and the logs show this error:

Template variable warning: ‘dict object’ has no attribute ‘tag_name’ when rendering ‘{{ value_json.tag_name }}’

12:17:45 – (WARNING) helpers/template.py

Any help will be hugely appreciated.

Shouldn’t it look like:

set_light_rgb:
  alias: 'ESPHome RGB light set'
  sequence:
  - service: light.turn_on
    data_template:
      rgb_color:
      - '{{ red }}'
      - '{{ green }}'
      - '{{ blue }}'
      entity_id: '{{ lightid }}'

Thanks Daryl,

After some playing i think the script should look like this:

 set_light_rgb:
  alias: 'ESPHome RGB light set'
  sequence:
  - service: light.turn_on
    data_template:
      rgb_color:
      - '{{ red }}'
      - '{{ green }}'
      - '{{ blue }}'
      device_id: '{{ lightid }}'

When i call the script from the developer tools it works:

service: script.set_light_rgb
data:
  red: '2'
  green: '233'
  blue: '1'
  lightid: 'c3fa823141ba3b79dc9893904d426142'

when calling it from esphome, nothing happens,

         - homeassistant.service:
             service: script.set_light_rgb
             data:
               red: '255'
               green: '255'
               blue: '255'
               lightid: 'c3fa823141ba3b79dc9893904d426142'

the logs show this:

Logger: homeassistant.helpers.template
Source: helpers/template.py:1914
First occurred: 23:11:02 (1 occurrences)
Last logged: 23:11:02

Template variable warning: ‘dict object’ has no attribute ‘tag_name’ when rendering ‘{{ value_json.tag_name }}’

Any Suggestions?

Hmm - I had a look at the example on the HA docs rather that the ESPhome docs - and it seems to suggest:

 set_light_rgb:
  - alias: 'ESPHome RGB light set'
    service: light.turn_on
    target:
      entity_id: "{{ lightid }}"
    data:
      rgb_color: [{{ red }},{{ green }},{{ blue }}]