Help on automation template

Hi folks! I don’t have a clie why this work

- id: 'pzem_004t_color'
  alias: PZEM-004T color
  initial_state: 'on'
  trigger:
  - platform: time_pattern
    minutes: "/1"
  action:
    - service: light.turn_on
      data:
        entity_id: light.pzem_004t
        brightness: 255
        rgb_color: [128,0,0]

…and this didn’t …

- id: 'pzem_004t_color'
  alias: PZEM-004T color
  initial_state: 'on'
  trigger:
  - platform: time_pattern
    minutes: "/1"
  action:
    - service: light.turn_on
      data_template:
         entity_id: light.pzem_004t
         brightness: 255
         rgb_color: "[{{(states('input_number.power_test') | int / 6000*255) | int }},0,0]"

Obviously I’ve tried Jinja2 model template and it works… I’ve some like [128,0,0]

You can’t have data and data_template for the same service call, either one or the other. Remove the data block.

- id: 'pzem_004t_color'
  alias: PZEM-004T color
  initial_state: 'on'
  trigger:
  - platform: time_pattern
    minutes: "/1"
  action:
  - service: light.turn_on
    data_template:
      entity_id: light.pzem_004t
      brightness: 255
      rgb_color: "[{{(states('input_number.power_test') | int / 6000*255) | int }},0,0]"

I’m sorry, I’ve made a mistake writing the post, now I’ve edited it with the right version…
So the problem is still here.

Any errors in the logs?
Can you please try changing the action part as below and show the persistent notification it creates.

action:
  - service: persistent_notification.create
    data_template:
       message: "[{{(states('input_number.power_test') | int / 6000*255) | int }},0,0]"
  - service: light.turn_on
    data_template:
       entity_id: light.pzem_004t
       brightness: 255
       rgb_color: "[{{(states('input_number.power_test') | int / 6000*255) | int }},0,0]"

Maybe I found the issue in the cast of the template, that it is be a string instead of a python list

I must be implement some like that

rgb_color: 
    - "{{ states('input_number.led_strip_r') | int }}"
    - "{{ states('input_number.led_strip_g') | int }}"
    - "{{ states('input_number.led_strip_b') | int }}"

Ah yes, I see know. Jinja templates always return a single string.

Your original rgb_color template is almost correct. You want YAML to interpret it as a list but by wrapping it all in double-quotes you’ve explicitly defined it to be a string. Remove the double-quotes on the outside and add them inside to delimit the actual template:

rgb_color: ["{{(states('input_number.power_test') | int / 6000*255) | int }}",0,0]

More info here.

2 Likes