Automation - Script using IF conditional

Hi,
I’ve created an automation that change the lamp colors according to the temperature, but I receve the error message:

found character ‘%’ that cannot start any token.

Could you help me?

  • alias: Informa tempo cores
    trigger:
    platform: time
    at: ‘07:45’
    action:
    • service: light.turn_on
      data_template:
      entity_id: light.lampshare
      brightness: 20
      data:
      rgb_color: >-
      {%- if states(‘sensor.pws_temp_c’) | int >= 0 -%}
      - 255
      - 255
      - 0
      {% elif states(‘sensor.pws_temp_c’) | int >= 20 %}
      - 100
      - 100
      - 100
      {% elif states(‘sensor.pws_temp_c’) | int >= 50 %}
      - 30
      - 255
      - 240
      {% endif %}

The bracketed statements will need indenting, but even when you fix that the automation won’t work because jinja outputs a string not a list, so it will output -255-255-0 for the first one, which isn’t the correct format for rgb_color.

Hi, Thanks
Do you have some suggest that I can solve it?

Use the scenes component to create the lighting effects, and use the data_template in the automation to decide which scene to use :+1:

Hi mf_social , I followed your suggestion but the light didn’t turn on.
Can you see in that time what is wrong?
BR
Oescafandrista

automation

alias: Cube event tap_twice on
trigger:
platform: event
event_type: cube_action
event_data:
entity_id: binary_sensor.cube_158d00010167ce
action_type: tap_twice
condition:
condition: state
entity_id: light.lampshade
state: ‘off’
action:
service: scene.turn_on
data_template:
entity_id: >-
{% if states(‘sensor.pws_temp_c’) | int >= 0 %}
scene.teste
{% elif states(‘sensor.pws_temp_c’) | int >= 10 %}
scene.teste
{% elif states(‘sensor.pws_temp_c’) | int >= 17 %}
scene.teste
{% endif %}
####### scene #######################
name: teste
entities:
light.lampshade:
state: on
brightness: 30
rgb_color: [255,0,255]
transition: 3
###################################
</>