Change Light Color based on Outside Temperature

@petro Thanks for the quick reply. Where do I find the gradient generator in the UI? I had a look around and did not find it.

There is no such tool. It’ll be 100% custom.

This is a gradient slider that I use with the custom:slider-entity-row.

      - type: custom:slider-entity-row
        entity: input_number.quick_strip_hue
        full_row: true
        hide_state: true
        style:
          .: |
            ha-slider { 
              background: linear-gradient(to right, red 0%, #ff0 17%, lime 33%, cyan 50%, blue 66%, #f0f 83%, red 100%);
              border-radius: 10px;
            }

Keep in mind that this uses the custom card slider-entity-row and the custom card card-mod.

I also have automations that calculate the color value based on the sliders position. You’ll have to derive the equations by hand like zermo did.

Here is the finished product - still using my “Weather Temp Light” in my home office. It uses a TP-Link smart bulb.

sorry to dig up an old thread, I’m trying to control some WiZ rgb led bulbs by freezer temperature using temp sensors

this is my automations code…

- id: '1660686610046'
  alias: New Automation
  description: ''
  trigger:
  - type: temperature
    platform: device
    device_id: 3bfb01efec5ba51ac99ce60b37fdb5df
    entity_id: sensor.temp1
    domain: sensor
    above: -100
    below: 100
  condition: []
  action:
    service: light.turn_on
    data_template:
      entity_id: light.wiz_rgbw_tunable_44a1ea
      rgb_color: >
          {% if states.sensor.temp1.state | int <= -25 %} [0, 0, 255]
          {% elif states.sensor.temp1.state | int >= -20 %} [51, 51, 255]
          {% elif states.sensor.temp1.state | int >= -15 %} [102, 102, 255]
          {% elif states.sensor.temp1.state | int >= -10 %} [153, 153, 255]
          {% elif states.sensor.temp1.state | int >= -5 %} [204, 204, 255]
          {% elif states.sensor.temp1.state | int >= -0 %} [255, 102, 78]
          {% elif states.sensor.temp1.state | int >= 5 %} [255, 51, 51]
          {% elif states.sensor.temp1.state | int >= 10 %} [255, 0, 0]
          {% else %} [255, 0, 0]
          {% endif %}
          brightness_pct: 100

it worked earlier, but I changed something and now it doesn’t work… and I can’t figure out what I changed

I’m watching the temperature reported by the sensor change, so that should trigger it? (it’s only changing 0.1’C at time)

any ideas anyone?

Unfortunately I could not find the documentation of the device trigger explaining the various confguration options here. My guess would be that the above and below options here work similar to the state change trigger, where the trigger fires exactly once when the temperature moves into this range.
So, I would just remove these two options (or migrate them into a condition) and I would expect the trigger to fire each time the temperature changes.

above: -100, below: 100 was left over from when I made an automation with the ui

without it I get error…

2022-08-17 00:32:23.653 ERROR (MainThread) [homeassistant.components.automation.new_automation_2] New Automation: Error executing script. Invalid data for call_service at pos 1: None for dictionary value @ data['rgb_color']

I’m a bit lost with how to fix it, I’ve tried a bunch of different things (mostly copy/past other peoples code) but nothing seams to fix it

Interestingly, I just tried to reproduce this, and when I try to define a device trigger without above and below I get an error message saying that it “must contain at least one of below, above.”

Anyway, there are a few things I’d change in the action: data_template can be replaced with data; the target entity_id is normally defined outside data; and brightness_pct must be the same indentation as rgb_color.
Lastly, you will need to finet-tune the if statements, because the first match will set the colour, so for example if the temperature sensor reads 8ºC the second line (>= -20) will already match because 8 is indeed greater than -20. Or, are your comparisons maybe just the wrong way round?

  action:
    service: light.turn_on
    target:
      entity_id: light.wiz_rgbw_tunable_44a1ea
    data:
      rgb_color: >
          {% if states.sensor.temp1.state | int <= -25 %} [0, 0, 255]
          {% elif states.sensor.temp1.state | int <= -20 %} [51, 51, 255]
          {% elif states.sensor.temp1.state | int <= -15 %} [102, 102, 255]
          {% elif states.sensor.temp1.state | int <= -10 %} [153, 153, 255]
          {% elif states.sensor.temp1.state | int <= -5 %} [204, 204, 255]
          {% elif states.sensor.temp1.state | int <= -0 %} [255, 102, 78]
          {% elif states.sensor.temp1.state | int <= 5 %} [255, 51, 51]
          {% else %} [255, 0, 0]
          {% endif %}
      brightness_pct: 100

thankyou!

I changed the code to this…

- id: '1660686610046'
  alias: change bulb
  description: ''
  trigger:
  - platform: state
    entity_id: sensor.temp1
  condition: []
  action:
    service: light.turn_on
    target:
      entity_id: light.wiz_rgbw_tunable_44a1ea
    data:
      rgb_color: >
          {% if states.sensor.temp1.state | int <= -25 %} [0, 0, 255]
          {% elif states.sensor.temp1.state | int <= -20 %} [51, 51, 255]
          {% elif states.sensor.temp1.state | int <= -15 %} [102, 102, 255]
          {% elif states.sensor.temp1.state | int <= -10 %} [153, 153, 255]
          {% elif states.sensor.temp1.state | int <= -5 %} [204, 204, 255]
          {% elif states.sensor.temp1.state | int <= -0 %} [255, 102, 78]
          {% elif states.sensor.temp1.state | int <= 5 %} [255, 51, 51]
          {% else %} [255, 0, 0]
          {% endif %}
      brightness_pct: 100

and it looks like it’s working great so far, set the bulb to yellow… next time the temp probe updated it changed to red

in the end I’ll have 10 temp probes and 10 led bulbs… is there a better way to do this thatn just copy past the code 10 times?

1 Like

If there is a simple 1:1 relationship between temperature sensor and light, you could try working with trigger id:

trigger:
  - platform: state
    entity_id: sensor.temp1
    id: "light1"
  - platform: state
    entity_id: sensor.temp2
    id: "light2"
  ...

And then make the action more generic and make use of the available trigger data:

  action:
    service: light.turn_on
    target:
      entity_id: "light.{trigger.id}"
    data:
      rgb_color: >
          {% if trigger.to_state.state | int <= -25 %} [0, 0, 255]
          {% elif trigger.to_state.state | int <= -20 %} [51, 51, 255]
          {% elif trigger.to_state.state | int <= -15 %} [102, 102, 255]
          {% elif trigger.to_state.state | int <= -10 %} [153, 153, 255]
          {% elif trigger.to_state.state | int <= -5 %} [204, 204, 255]
          {% elif trigger.to_state.state | int <= -0 %} [255, 102, 78]
          {% elif trigger.to_state.state | int <= 5 %} [255, 51, 51]
          {% else %} [255, 0, 0]
          {% endif %}
      brightness_pct: 100

thankyou, I’ll try that over the weekend

it’ll make updating/changing how it works much easier :slight_smile:

Hello, I am currently starting out on Home Assistant.

I would like to integrate the outdoor temperature feature with my lights, but I can’t seem to do it.

Can someone explain me how to integrate it?

Thanks in advance.

would you know if this code would control a wled controller as I would like to do the same with my kettle water temperture and a section of my kitchens wled strip?

You will want edit your automations.yaml file - using this as a reference. This is exactly what I use, but you would need to replace the entity names with yours:

- id: Outside_Temp_Color_Change
  alias: Outside Temp Color Change
  initial_state: 'on'
  trigger:
    platform: state
    entity_id: sensor.outdoor_temperature
  mode: single
  action:
    service: light.turn_on
    entity_id: light.weather_light
    data_template:
      rgb_color:
      - '{% if states.sensor.outdoor_temperature.state | int <= 0 %} 255 {% elif states.sensor.outdoor_temperature.state
        | int == 1 %} 255 {% elif states.sensor.outdoor_temperature.state | int ==
        2 %} 255 {% elif states.sensor.outdoor_temperature.state | int == 3 %} 255
        {% elif states.sensor.outdoor_temperature.state | int == 4 %} 255 {% elif
        states.sensor.outdoor_temperature.state | int == 5 %} 255 {% elif states.sensor.outdoor_temperature.state
        | int == 6 %} 255 {% elif states.sensor.outdoor_temperature.state | int ==
        7 %} 255 {% elif states.sensor.outdoor_temperature.state | int == 8 %} 255
        {% elif states.sensor.outdoor_temperature.state | int == 9 %} 255 {% elif
        states.sensor.outdoor_temperature.state | int == 10 %} 255 {% elif states.sensor.outdoor_temperature.state
        | int == 11 %} 255 {% elif states.sensor.outdoor_temperature.state | int ==
        12 %} 245 {% elif states.sensor.outdoor_temperature.state | int == 13 %} 235
        {% elif states.sensor.outdoor_temperature.state | int == 14 %} 224 {% elif
        states.sensor.outdoor_temperature.state | int == 15 %} 214 {% elif states.sensor.outdoor_temperature.state
        | int == 16 %} 207 {% elif states.sensor.outdoor_temperature.state | int ==
        17 %} 198 {% elif states.sensor.outdoor_temperature.state | int == 18 %} 186
        {% elif states.sensor.outdoor_temperature.state | int == 19 %} 175 {% elif
        states.sensor.outdoor_temperature.state | int == 20 %} 167 {% elif states.sensor.outdoor_temperature.state
        | int == 21 %} 157 {% elif states.sensor.outdoor_temperature.state | int ==
        22 %} 140 {% elif states.sensor.outdoor_temperature.state | int == 23 %} 123
        {% elif states.sensor.outdoor_temperature.state | int == 24 %} 111 {% elif
        states.sensor.outdoor_temperature.state | int == 25 %} 93 {% elif states.sensor.outdoor_temperature.state
        | int == 26 %} 76 {% elif states.sensor.outdoor_temperature.state | int ==
        27 %} 64 {% elif states.sensor.outdoor_temperature.state | int == 28 %} 47
        {% elif states.sensor.outdoor_temperature.state | int == 29 %} 30 {% elif
        states.sensor.outdoor_temperature.state | int == 30 %} 17 {% elif states.sensor.outdoor_temperature.state
        | int == 31 %} 0 {% elif states.sensor.outdoor_temperature.state | int ==
        32 %} 0 {% elif states.sensor.outdoor_temperature.state | int == 33 %} 0 {%
        elif states.sensor.outdoor_temperature.state | int == 34 %} 0 {% elif states.sensor.outdoor_temperature.state
        | int == 35 %} 0 {% elif states.sensor.outdoor_temperature.state | int ==
        36 %} 0 {% elif states.sensor.outdoor_temperature.state | int == 37 %} 0 {%
        elif states.sensor.outdoor_temperature.state | int == 38 %} 0 {% elif states.sensor.outdoor_temperature.state
        | int == 39 %} 0 {% elif states.sensor.outdoor_temperature.state | int ==
        40 %} 0 {% elif states.sensor.outdoor_temperature.state | int == 41 %} 0 {%
        elif states.sensor.outdoor_temperature.state | int == 42 %} 5 {% elif states.sensor.outdoor_temperature.state
        | int == 43 %} 10 {% elif states.sensor.outdoor_temperature.state | int ==
        44 %} 15 {% elif states.sensor.outdoor_temperature.state | int == 45 %} 20
        {% elif states.sensor.outdoor_temperature.state | int == 46 %} 26 {% elif
        states.sensor.outdoor_temperature.state | int == 47 %} 31 {% elif states.sensor.outdoor_temperature.state
        | int == 48 %} 36 {% elif states.sensor.outdoor_temperature.state | int ==
        49 %} 41 {% elif states.sensor.outdoor_temperature.state | int == 50 %} 46
        {% elif states.sensor.outdoor_temperature.state | int == 51 %} 51 {% elif
        states.sensor.outdoor_temperature.state | int == 52 %} 61 {% elif states.sensor.outdoor_temperature.state
        | int == 53 %} 66 {% elif states.sensor.outdoor_temperature.state | int ==
        54 %} 75 {% elif states.sensor.outdoor_temperature.state | int == 55 %} 88
        {% elif states.sensor.outdoor_temperature.state | int == 56 %} 96 {% elif
        states.sensor.outdoor_temperature.state | int == 57 %} 106 {% elif states.sensor.outdoor_temperature.state
        | int == 58 %} 112 {% elif states.sensor.outdoor_temperature.state | int ==
        59 %} 122 {% elif states.sensor.outdoor_temperature.state | int == 60 %} 132
        {% elif states.sensor.outdoor_temperature.state | int == 61 %} 140 {% elif
        states.sensor.outdoor_temperature.state | int == 62 %} 153 {% elif states.sensor.outdoor_temperature.state
        | int == 63 %} 162 {% elif states.sensor.outdoor_temperature.state | int ==
        64 %} 174 {% elif states.sensor.outdoor_temperature.state | int == 65 %} 187
        {% elif states.sensor.outdoor_temperature.state | int == 66 %} 195 {% elif
        states.sensor.outdoor_temperature.state | int == 67 %} 208 {% elif states.sensor.outdoor_temperature.state
        | int == 68 %} 221 {% elif states.sensor.outdoor_temperature.state | int ==
        69 %} 234 {% elif states.sensor.outdoor_temperature.state | int == 70 %} 242
        {% elif states.sensor.outdoor_temperature.state | int == 71 %} 255 {% elif
        states.sensor.outdoor_temperature.state | int == 72 %} 255 {% elif states.sensor.outdoor_temperature.state
        | int == 73 %} 255 {% elif states.sensor.outdoor_temperature.state | int ==
        74 %} 255 {% elif states.sensor.outdoor_temperature.state | int == 75 %} 255
        {% elif states.sensor.outdoor_temperature.state | int == 76 %} 255 {% elif
        states.sensor.outdoor_temperature.state | int == 77 %} 255 {% elif states.sensor.outdoor_temperature.state
        | int == 78 %} 255 {% elif states.sensor.outdoor_temperature.state | int ==
        79 %} 255 {% elif states.sensor.outdoor_temperature.state | int == 80 %} 255
        {% elif states.sensor.outdoor_temperature.state | int == 81 %} 255 {% elif
        states.sensor.outdoor_temperature.state | int == 82 %} 255 {% elif states.sensor.outdoor_temperature.state
        | int == 83 %} 255 {% elif states.sensor.outdoor_temperature.state | int ==
        84 %} 255 {% elif states.sensor.outdoor_temperature.state | int == 85 %} 255
        {% elif states.sensor.outdoor_temperature.state | int == 86 %} 255 {% elif
        states.sensor.outdoor_temperature.state | int == 87 %} 255 {% elif states.sensor.outdoor_temperature.state
        | int == 88 %} 255 {% elif states.sensor.outdoor_temperature.state | int ==
        89 %} 255 {% elif states.sensor.outdoor_temperature.state | int == 90 %} 255
        {% elif states.sensor.outdoor_temperature.state | int == 91 %} 255 {% elif
        states.sensor.outdoor_temperature.state | int == 92 %} 255 {% elif states.sensor.outdoor_temperature.state
        | int == 93 %} 255 {% elif states.sensor.outdoor_temperature.state | int ==
        94 %} 255 {% elif states.sensor.outdoor_temperature.state | int == 95 %} 255
        {% elif states.sensor.outdoor_temperature.state | int == 96 %} 255 {% elif
        states.sensor.outdoor_temperature.state | int == 97 %} 255 {% elif states.sensor.outdoor_temperature.state
        | int == 98 %} 255 {% elif states.sensor.outdoor_temperature.state | int ==
        99 %} 255 {% elif states.sensor.outdoor_temperature.state | int >= 100 %}
        255 {% else %} 43 {% endif %}

        '
      - '{% if states.sensor.outdoor_temperature.state | int <= 0 %} 255 {% elif states.sensor.outdoor_temperature.state
        | int == 1 %} 255 {% elif states.sensor.outdoor_temperature.state | int ==
        2 %} 232 {% elif states.sensor.outdoor_temperature.state | int == 3 %} 209
        {% elif states.sensor.outdoor_temperature.state | int == 4 %} 184 {% elif
        states.sensor.outdoor_temperature.state | int == 5 %} 161 {% elif states.sensor.outdoor_temperature.state
        | int == 6 %} 138 {% elif states.sensor.outdoor_temperature.state | int ==
        7 %} 115 {% elif states.sensor.outdoor_temperature.state | int == 8 %} 89
        {% elif states.sensor.outdoor_temperature.state | int == 9 %} 66 {% elif states.sensor.outdoor_temperature.state
        | int == 10 %} 43 {% elif states.sensor.outdoor_temperature.state | int ==
        11 %} 20 {% elif states.sensor.outdoor_temperature.state | int == 12 %} 18
        {% elif states.sensor.outdoor_temperature.state | int == 13 %} 15 {% elif
        states.sensor.outdoor_temperature.state | int == 14 %} 13 {% elif states.sensor.outdoor_temperature.state
        | int == 15 %} 13 {% elif states.sensor.outdoor_temperature.state | int ==
        16 %} 10 {% elif states.sensor.outdoor_temperature.state | int == 17 %} 8
        {% elif states.sensor.outdoor_temperature.state | int == 18 %} 5 {% elif states.sensor.outdoor_temperature.state
        | int == 19 %} 3 {% elif states.sensor.outdoor_temperature.state | int ==
        20 %} 0 {% elif states.sensor.outdoor_temperature.state | int == 21 %} 0 {%
        elif states.sensor.outdoor_temperature.state | int == 22 %} 0 {% elif states.sensor.outdoor_temperature.state
        | int == 23 %} 0 {% elif states.sensor.outdoor_temperature.state | int ==
        24 %} 0 {% elif states.sensor.outdoor_temperature.state | int == 25 %} 0 {%
        elif states.sensor.outdoor_temperature.state | int == 26 %} 0 {% elif states.sensor.outdoor_temperature.state
        | int == 27 %} 0 {% elif states.sensor.outdoor_temperature.state | int ==
        28 %} 0 {% elif states.sensor.outdoor_temperature.state | int == 29 %} 0 {%
        elif states.sensor.outdoor_temperature.state | int == 30 %} 0 {% elif states.sensor.outdoor_temperature.state
        | int == 31 %} 0 {% elif states.sensor.outdoor_temperature.state | int ==
        32 %} 25 {% elif states.sensor.outdoor_temperature.state | int == 33 %} 50
        {% elif states.sensor.outdoor_temperature.state | int == 34 %} 75 {% elif
        states.sensor.outdoor_temperature.state | int == 35 %} 103 {% elif states.sensor.outdoor_temperature.state
        | int == 36 %} 126 {% elif states.sensor.outdoor_temperature.state | int ==
        37 %} 155 {% elif states.sensor.outdoor_temperature.state | int == 38 %} 178
        {% elif states.sensor.outdoor_temperature.state | int == 39 %} 206 {% elif
        states.sensor.outdoor_temperature.state | int == 40 %} 228 {% elif states.sensor.outdoor_temperature.state
        | int == 41 %} 255 {% elif states.sensor.outdoor_temperature.state | int ==
        42 %} 250 {% elif states.sensor.outdoor_temperature.state | int == 43 %} 245
        {% elif states.sensor.outdoor_temperature.state | int == 44 %} 242 {% elif
        states.sensor.outdoor_temperature.state | int == 45 %} 237 {% elif states.sensor.outdoor_temperature.state
        | int == 46 %} 232 {% elif states.sensor.outdoor_temperature.state | int ==
        47 %} 227 {% elif states.sensor.outdoor_temperature.state | int == 48 %} 222
        {% elif states.sensor.outdoor_temperature.state | int == 49 %} 219 {% elif
        states.sensor.outdoor_temperature.state | int == 50 %} 214 {% elif states.sensor.outdoor_temperature.state
        | int == 51 %} 209 {% elif states.sensor.outdoor_temperature.state | int ==
        52 %} 214 {% elif states.sensor.outdoor_temperature.state | int == 53 %} 219
        {% elif states.sensor.outdoor_temperature.state | int == 54 %} 222 {% elif
        states.sensor.outdoor_temperature.state | int == 55 %} 227 {% elif states.sensor.outdoor_temperature.state
        | int == 56 %} 232 {% elif states.sensor.outdoor_temperature.state | int ==
        57 %} 237 {% elif states.sensor.outdoor_temperature.state | int == 58 %} 242
        {% elif states.sensor.outdoor_temperature.state | int == 59 %} 245 {% elif
        states.sensor.outdoor_temperature.state | int == 60 %} 250 {% elif states.sensor.outdoor_temperature.state
        | int == 61 %} 255 {% elif states.sensor.outdoor_temperature.state | int ==
        62 %} 255 {% elif states.sensor.outdoor_temperature.state | int == 63 %} 255
        {% elif states.sensor.outdoor_temperature.state | int == 64 %} 255 {% elif
        states.sensor.outdoor_temperature.state | int == 65 %} 255 {% elif states.sensor.outdoor_temperature.state
        | int == 66 %} 255 {% elif states.sensor.outdoor_temperature.state | int ==
        67 %} 255 {% elif states.sensor.outdoor_temperature.state | int == 68 %} 255
        {% elif states.sensor.outdoor_temperature.state | int == 69 %} 255 {% elif
        states.sensor.outdoor_temperature.state | int == 70 %} 255 {% elif states.sensor.outdoor_temperature.state
        | int == 71 %} 255 {% elif states.sensor.outdoor_temperature.state | int ==
        72 %} 247 {% elif states.sensor.outdoor_temperature.state | int == 73 %} 238
        {% elif states.sensor.outdoor_temperature.state | int == 74 %} 230 {% elif
        states.sensor.outdoor_temperature.state | int == 75 %} 221 {% elif states.sensor.outdoor_temperature.state
        | int == 76 %} 213 {% elif states.sensor.outdoor_temperature.state | int ==
        77 %} 204 {% elif states.sensor.outdoor_temperature.state | int == 78 %} 200
        {% elif states.sensor.outdoor_temperature.state | int == 79 %} 191 {% elif
        states.sensor.outdoor_temperature.state | int == 80 %} 183 {% elif states.sensor.outdoor_temperature.state
        | int == 81 %} 174 {% elif states.sensor.outdoor_temperature.state | int ==
        82 %} 162 {% elif states.sensor.outdoor_temperature.state | int == 83 %} 149
        {% elif states.sensor.outdoor_temperature.state | int == 84 %} 136 {% elif
        states.sensor.outdoor_temperature.state | int == 85 %} 119 {% elif states.sensor.outdoor_temperature.state
        | int == 86 %} 106 {% elif states.sensor.outdoor_temperature.state | int ==
        87 %} 94 {% elif states.sensor.outdoor_temperature.state | int == 88 %} 81
        {% elif states.sensor.outdoor_temperature.state | int == 89 %} 68 {% elif
        states.sensor.outdoor_temperature.state | int == 90 %} 55 {% elif states.sensor.outdoor_temperature.state
        | int == 91 %} 43 {% elif states.sensor.outdoor_temperature.state | int ==
        92 %} 38 {% elif states.sensor.outdoor_temperature.state | int == 93 %} 34
        {% elif states.sensor.outdoor_temperature.state | int == 94 %} 30 {% elif
        states.sensor.outdoor_temperature.state | int == 95 %} 21 {% elif states.sensor.outdoor_temperature.state
        | int == 96 %} 17 {% elif states.sensor.outdoor_temperature.state | int ==
        97 %} 13 {% elif states.sensor.outdoor_temperature.state | int == 98 %} 9
        {% elif states.sensor.outdoor_temperature.state | int == 99 %} 4 {% elif states.sensor.outdoor_temperature.state
        | int >= 100 %} 0 {% else %} 255 {% endif %}

        '
      - '{% if states.sensor.outdoor_temperature.state | int <= 0 %} 255 {% elif states.sensor.outdoor_temperature.state
        | int == 1 %} 255 {% elif states.sensor.outdoor_temperature.state | int ==
        2 %} 244 {% elif states.sensor.outdoor_temperature.state | int == 3 %} 234
        {% elif states.sensor.outdoor_temperature.state | int == 4 %} 222 {% elif
        states.sensor.outdoor_temperature.state | int == 5 %} 211 {% elif states.sensor.outdoor_temperature.state
        | int == 6 %} 202 {% elif states.sensor.outdoor_temperature.state | int ==
        7 %} 190 {% elif states.sensor.outdoor_temperature.state | int == 8 %} 178
        {% elif states.sensor.outdoor_temperature.state | int == 9 %} 167 {% elif
        states.sensor.outdoor_temperature.state | int == 10 %} 156 {% elif states.sensor.outdoor_temperature.state
        | int == 11 %} 146 {% elif states.sensor.outdoor_temperature.state | int ==
        12 %} 158 {% elif states.sensor.outdoor_temperature.state | int == 13 %} 169
        {% elif states.sensor.outdoor_temperature.state | int == 14 %} 179 {% elif
        states.sensor.outdoor_temperature.state | int == 15 %} 191 {% elif states.sensor.outdoor_temperature.state
        | int == 16 %} 200 {% elif states.sensor.outdoor_temperature.state | int ==
        17 %} 212 {% elif states.sensor.outdoor_temperature.state | int == 18 %} 222
        {% elif states.sensor.outdoor_temperature.state | int == 19 %} 232 {% elif
        states.sensor.outdoor_temperature.state | int == 20 %} 245 {% elif states.sensor.outdoor_temperature.state
        | int == 21 %} 255 {% elif states.sensor.outdoor_temperature.state | int ==
        22 %} 255 {% elif states.sensor.outdoor_temperature.state | int == 23 %} 255
        {% elif states.sensor.outdoor_temperature.state | int == 24 %} 255 {% elif
        states.sensor.outdoor_temperature.state | int == 25 %} 255 {% elif states.sensor.outdoor_temperature.state
        | int == 26 %} 255 {% elif states.sensor.outdoor_temperature.state | int ==
        27 %} 255 {% elif states.sensor.outdoor_temperature.state | int == 28 %} 255
        {% elif states.sensor.outdoor_temperature.state | int == 29 %} 255 {% elif
        states.sensor.outdoor_temperature.state | int == 30 %} 255 {% elif states.sensor.outdoor_temperature.state
        | int == 31 %} 255 {% elif states.sensor.outdoor_temperature.state | int ==
        32 %} 252 {% elif states.sensor.outdoor_temperature.state | int == 33 %} 250
        {% elif states.sensor.outdoor_temperature.state | int == 34 %} 250 {% elif
        states.sensor.outdoor_temperature.state | int == 35 %} 247 {% elif states.sensor.outdoor_temperature.state
        | int == 36 %} 245 {% elif states.sensor.outdoor_temperature.state | int ==
        37 %} 245 {% elif states.sensor.outdoor_temperature.state | int == 38 %} 242
        {% elif states.sensor.outdoor_temperature.state | int == 39 %} 242 {% elif
        states.sensor.outdoor_temperature.state | int == 40 %} 240 {% elif states.sensor.outdoor_temperature.state
        | int == 41 %} 238 {% elif states.sensor.outdoor_temperature.state | int ==
        42 %} 217 {% elif states.sensor.outdoor_temperature.state | int == 43 %} 198
        {% elif states.sensor.outdoor_temperature.state | int == 44 %} 182 {% elif
        states.sensor.outdoor_temperature.state | int == 45 %} 161 {% elif states.sensor.outdoor_temperature.state
        | int == 46 %} 143 {% elif states.sensor.outdoor_temperature.state | int ==
        47 %} 122 {% elif states.sensor.outdoor_temperature.state | int == 48 %} 101
        {% elif states.sensor.outdoor_temperature.state | int == 49 %} 83 {% elif
        states.sensor.outdoor_temperature.state | int == 50 %} 66 {% elif states.sensor.outdoor_temperature.state
        | int == 51 %} 46 {% elif states.sensor.outdoor_temperature.state | int ==
        52 %} 41 {% elif states.sensor.outdoor_temperature.state | int == 53 %} 36
        {% elif states.sensor.outdoor_temperature.state | int == 54 %} 31 {% elif
        states.sensor.outdoor_temperature.state | int == 55 %} 28 {% elif states.sensor.outdoor_temperature.state
        | int == 56 %} 23 {% elif states.sensor.outdoor_temperature.state | int ==
        57 %} 18 {% elif states.sensor.outdoor_temperature.state | int == 58 %} 13
        {% elif states.sensor.outdoor_temperature.state | int == 59 %} 8 {% elif states.sensor.outdoor_temperature.state
        | int == 60 %} 5 {% elif states.sensor.outdoor_temperature.state | int ==
        61 %} 0 {% elif states.sensor.outdoor_temperature.state | int == 62 %} 0 {%
        elif states.sensor.outdoor_temperature.state | int == 63 %} 0 {% elif states.sensor.outdoor_temperature.state
        | int == 64 %} 0 {% elif states.sensor.outdoor_temperature.state | int ==
        65 %} 0 {% elif states.sensor.outdoor_temperature.state | int == 66 %} 0 {%
        elif states.sensor.outdoor_temperature.state | int == 67 %} 0 {% elif states.sensor.outdoor_temperature.state
        | int == 68 %} 0 {% elif states.sensor.outdoor_temperature.state | int ==
        69 %} 0 {% elif states.sensor.outdoor_temperature.state | int == 70 %} 0 {%
        elif states.sensor.outdoor_temperature.state | int == 71 %} 0 {% elif states.sensor.outdoor_temperature.state
        | int == 72 %} 0 {% elif states.sensor.outdoor_temperature.state | int ==
        73 %} 0 {% elif states.sensor.outdoor_temperature.state | int == 74 %} 0 {%
        elif states.sensor.outdoor_temperature.state | int == 75 %} 0 {% elif states.sensor.outdoor_temperature.state
        | int == 76 %} 0 {% elif states.sensor.outdoor_temperature.state | int ==
        77 %} 0 {% elif states.sensor.outdoor_temperature.state | int == 78 %} 0 {%
        elif states.sensor.outdoor_temperature.state | int == 79 %} 0 {% elif states.sensor.outdoor_temperature.state
        | int == 80 %} 0 {% elif states.sensor.outdoor_temperature.state | int ==
        81 %} 0 {% elif states.sensor.outdoor_temperature.state | int == 82 %} 0 {%
        elif states.sensor.outdoor_temperature.state | int == 83 %} 0 {% elif states.sensor.outdoor_temperature.state
        | int == 84 %} 0 {% elif states.sensor.outdoor_temperature.state | int ==
        85 %} 0 {% elif states.sensor.outdoor_temperature.state | int == 86 %} 0 {%
        elif states.sensor.outdoor_temperature.state | int == 87 %} 0 {% elif states.sensor.outdoor_temperature.state
        | int == 88 %} 0 {% elif states.sensor.outdoor_temperature.state | int ==
        89 %} 0 {% elif states.sensor.outdoor_temperature.state | int == 90 %} 0 {%
        elif states.sensor.outdoor_temperature.state | int == 91 %} 0 {% elif states.sensor.outdoor_temperature.state
        | int == 92 %} 0 {% elif states.sensor.outdoor_temperature.state | int ==
        93 %} 0 {% elif states.sensor.outdoor_temperature.state | int == 94 %} 0 {%
        elif states.sensor.outdoor_temperature.state | int == 95 %} 0 {% elif states.sensor.outdoor_temperature.state
        | int == 96 %} 0 {% elif states.sensor.outdoor_temperature.state | int ==
        97 %} 0 {% elif states.sensor.outdoor_temperature.state | int == 98 %} 0 {%
        elif states.sensor.outdoor_temperature.state | int == 99 %} 0 {% elif states.sensor.outdoor_temperature.state
        | int >= 100 %} 0 {% else %} 113 {% endif %}

        '

hi I have tried your code and get the error " Message malformed: extra keys not allowed @ data[‘0’] " any ideas what might be causing it?

Yaml is very sensitive to indentations and needing spaces vs tabs. I would check to ensure the cut/paste doesn’t have any tabs for the indentation and is using spaces. I find that using Notepad++ is great for doing that. Someone else might have a better suggestion on it, but that is the only thing I can think of that could get altered when doing a cut and paste.

yes I used notpad++ to change the entities, I have even just pasted you code into my automation wiithouit changing anything, still the same. The only thing that looks out of place to me (but i am not a coder so really have no idea) is at the end of each section in your example the ’ has big gaps from the end of the text?

I’m not sure if this will help, but I clipped that section out of my automations.yaml and put it on my webserver. You can download it from there or cut/paste.

https://www.weather-station.org/ha/weather-temp-light-yaml.txt

@ MarkHofmann11
Hope you don’t mind…
I refactored your code to this:

- alias: map_temperature_to_light_output
  trigger:
    platform: state
    entity_id: sensor.outdoor_temperature
  action:
    - service: light.turn_on
      target:
        entity_id: light.weather_light
      data_template:
        rgb_color:
          - >
            {% set red = states('sensor.outdoor_temperature') | int %}
            {% set mapping = {
            0: 255, 1: 255, 2: 232, 3: 209, 4: 184, 5: 161, 6: 138, 7: 115, 8: 89, 9: 66,
            10: 43, 11: 20, 12: 18, 13: 15, 14: 13, 15: 13, 16: 10, 17: 8, 18: 5, 19: 3,
            20: 0, 21: 0, 22: 0, 23: 0, 24: 0, 25: 0, 26: 0, 27: 0, 28: 0, 29: 0,
            30: 0, 31: 0, 32: 25, 33: 50, 34: 75, 35: 103, 36: 126, 37: 155, 38: 178, 39: 206,
            40: 228, 41: 255, 42: 250, 43: 245, 44: 242, 45: 237, 46: 232, 47: 227, 48: 222, 49: 219,
            50: 214, 51: 209, 52: 214, 53: 219, 54: 222, 55: 227, 56: 232, 57: 237, 58: 242, 59: 245,
            60: 250, 61: 255, 62: 255, 63: 255, 64: 255, 65: 255, 66: 255, 67: 255, 68: 255, 69: 255,
            70: 255, 71: 255, 72: 247, 73: 238, 74: 230, 75: 221, 76: 213, 77: 204, 78: 200, 79: 191,
            80: 183, 81: 174, 82: 162, 83: 149, 84: 136, 85: 119, 86: 106, 87: 94, 88: 81, 89: 68,
            90: 55, 91: 43, 92: 38, 93: 34, 94: 30, 95: 21, 96: 17, 97: 13, 98: 9, 100: 0
            } %}
            {{ mapping.get(red, 43) }}
          - >
            {% set green = states('sensor.outdoor_temperature') | int %}
            {% set mapping = {
            0: 255, 1: 255, 2: 232, 3: 209, 4: 184, 5: 161, 6: 138, 7: 115, 8: 89, 9: 66,
            10: 43, 11: 20, 12: 18, 13: 15, 14: 13, 15: 13, 16: 10, 17: 8, 18: 5, 19: 3,
            20: 0, 21: 0, 22: 0, 23: 0, 24: 0, 25: 0, 26: 0, 27: 0, 28: 0, 29: 0,
            30: 0, 31: 0, 32: 25, 33: 50, 34: 75, 35: 103, 36: 126, 37: 155, 38: 178, 39: 206,
            40: 228, 41: 255, 42: 250, 43: 245, 44: 242, 45: 237, 46: 232, 47: 227, 48: 222, 49: 219,
            50: 214, 51: 209, 52: 214, 53: 219, 55: 227, 56: 232, 57: 237, 58: 242, 59: 245,
            60: 250, 61: 255, 62: 255, 63: 255, 64: 255, 65: 255, 66: 255, 67: 255, 68: 255, 69: 255,
            70: 255, 71: 255, 72: 247, 73: 238, 74: 230, 75: 221, 76: 213, 77: 204, 78: 200, 79: 191,
            80: 183, 81: 174, 82: 162, 83: 149, 85: 119, 86: 106, 87: 94, 88: 81, 89: 68,
            90: 55, 91: 43, 92: 38, 93: 34, 94: 30, 95: 21, 96: 17, 97: 13, 98: 9, 99: 4, 100: 0
            } %}
            {{ mapping.get(green, 255) }}
          - >
            {% set blue = states('sensor.outdoor_temperature') | int %}
            {% set mapping = {
            0: 255, 1: 255, 2: 244, 3: 234, 4: 222, 5: 211, 6: 202, 7: 190, 8: 178, 9: 167,
            10: 156, 11: 146, 12: 158, 13: 169, 14: 179, 15: 191, 16: 200, 17: 212, 18: 222, 19: 232,
            20: 245, 21: 255, 22: 255, 23: 255, 24: 255, 25: 255, 26: 255, 27: 255, 28: 255, 29: 255,
            30: 255, 31: 255, 32: 252, 33: 250, 34: 250, 35: 247, 36: 245, 37: 245, 38: 242, 39: 242,
            40: 240, 41: 238, 42: 217, 43: 198, 44: 182, 45: 161, 46: 143, 47: 122, 48: 101, 49: 83,
            50: 66, 51: 46, 52: 41, 53: 36, 54: 31, 55: 28, 56: 23, 57: 18, 58: 13, 59: 8,
            60: 5, 61: 0, 62: 0, 63: 0, 64: 0, 65: 0, 66: 0, 67: 0, 68: 0, 69: 0,
            70: 0, 71: 0, 72: 0, 73: 0, 74: 0, 75: 0, 76: 0, 77: 0, 78: 0, 79: 0,
            80: 0, 81: 0, 82: 0, 83: 0, 84: 0, 85: 0, 86: 0, 87: 0, 88: 0, 89: 0,
            90: 0, 91: 0, 92: 0, 93: 0, 94: 0, 95: 0, 96: 0, 97: 0, 98: 0, 99: 0, 100: 0
            } %}
            {{ mapping.get(blue, 113) }}
1 Like

Almost the same, my rework doesn’t do Minus Zero values. ATM

Stumbled across this post and had to try it. I ran into the same “message malformed” issue and spent way too long trying to resolve it. Here’s what I did:

  1. Adjusted the sensor and entity names using Notepad++
  2. Copied all of the YAML into ( YAMLlint - The YAML Validator) and ensured it was valid.
  3. Pasted the code into automations.yaml at the end (I have Visual Code Studio connected to my HA, but you can also do this through File Editor).
  4. Ran a Configuration Check via Developer Tools - all YAML valid
  5. Reloaded all YAML configs via Developer Tools
  6. Tested by setting the state of the sensor using Developer tools > States. Success!

My problem seemed to be using the automation editor in HA - even when using Edit in YAML. Hope this helps someone…spent too many hours on a cold snowy day figuring this out (as a HA YAML noob!).