Different color depending on current temperature

Hi,
I’m fairly new to this, and have very little programing experience so perhaps i’m doing beginner mistakes.
I have put in alot of hours searching for a solution.

This is what i have thus far, light turns on but no colors is recognized so only turning on.

  action:
  - service: light.turn_on
    data:
      entity_id: light.osram_smart_e27_color_1
      brightness: 255
      color_name: >
        {% if states('sensor.framsidan') | float <= -10 %}
          blueviolet
        {% elif states('sensor.framsidan') | float > -10 or states('sensor.framsidan') | float <= 0 %}
          blue
        {% elif states('sensor.framsidan') | float > 0 or states('sensor.framsidan') | float <= 10 %}
          green
        {% elif states('sensor.framsidan') | float > 10 or states('sensor.framsidan') | float < 20 %}
          orange
        {% elif states('sensor.framsidan') | float >= 20 %}
          red
        {% else %}
          white
        {% endif %}
      transition: 20

So i have checked all kinds of pages learning templating and understanding if function on HA component pages.
I have it working in the dev tools editor so i’m guessing that i can’t use if statements like this on color_name as i’m doing it? Or i have formated it wrong?

Hope someone can give me pointers on how to do this.

Thanks in advance :slight_smile:

You were very close:

  action:
  - service: light.turn_on
    data_template: >

Ahh, thank you. works!
Soo close :slight_smile: