@ 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) }}