Hey everyone! I’m trying to set up an automation where my outdoor lights change color based on the current weather. I found some helpful tips online, but I’m running into an error when I try to run the automation. Let me walk you through what I’ve done so far and where I’m getting stuck.
First, I created an automation that checks the current weather forecast using the weather.home entity. I set up conditions to match different weather conditions like rainy, sunny, cloudy, etc. Each condition is supposed to trigger a specific color change on my outdoor lights. Here’s the automation I came up with:
yaml
- id: “1705835746525”
alias: Weather Light
variables:
weather:
rainy: color: blue
sunny: color: yellow
clear-night: color: navy
cloudy: color: maroon
fog: color: yellowgreen
partlycloudy: color: indianred
windy: color: darkorange
snowy: color: green
snowy-rainy: color: limegreen
pouring: color: teal
lightning: color: red
hail: color: aquamarine
windy-variant: color: lightsalmon
lightning-rainy: color: crimson
current_weather: “{{ state_attr(‘weather.home’, ‘forecast’) }}”
trigger:
platform: state
entity_id: weather.home
condition:
condition: template
value_template: “{{ current_weather in weather }}”
action:- service: light.turn_on
data:
color_name: “{{ weather[current_weather].color }}”
target:
entity_id: light.outdoor_light_level_light_color_on_off
- service: light.turn_on
When I run this automation, I get an error that says: Error rendering data template: UndefinedError: dict object has no element [{'condition': 'partlycloudy', 'datetime': '2023-10-17T10:00:00+00:00', 'wind_bearing': 83.3, 'temperature': 13.3, 'templow': 8.0, 'wind_speed': 18.4, 'precipitation': 0.0, 'humidity': 59}, {'condition': 'cloudy', 'datetime': '2023-10-18T10:00:00+00:00', 'wind_bearing': 90.8, 'temperature': 16.7, 'templow': 7.0, 'wind_speed': 22.0, 'precipitation': 9.4, 'humidity': 58}, {'condition': 'cloudy', 'datetime': '2023-10-19T10:00:00+00:00', 'wind_bearing': 194.6, 'temperature': 20.2, 'templow': 13.3, 'wind_speed': 23.0, 'precipitation': 8.9, 'humidity': 78}, {'condition': 'rainy', 'datetime': '2023-10-20T10:00:00+00:00', 'wind_bearing': 65.5, 'temperature': 14.6, 'templow': 6.2, 'wind_speed': 28.4, 'precipitation': 16.0, 'humidity': 79}, {'condition': 'rainy', 'datetime': '2023-10-21T10:00:00+00:00', 'wind_bearing': 89.0, 'temperature': 7.1, 'templow': 4.5, 'wind_speed': 25.6, 'precipitation': 18.9, 'humidity': 93}, {'condition': 'partlycloudy', 'datetime': '2023-10-22T10:00:00+00:00', 'wind_bearing': 245.5, 'temperature': 11.2, 'templow': 5.4, 'wind_speed': 22.7, 'precipitation': 0.2, 'humidity': 72}]
It looks like the error is happening in the light.turn_on step. I’m not sure why it’s having trouble rendering the template. Does anyone have any ideas on how to fix this? I really want to get this working so my lights automatically change colors based on the weather!
I’d greatly appreciate any help or suggestions you can provide. Thanks in advance!