Hello,
I would like to make an automation to change the color of a light, depending on openweather forecast condition.
At this moment I am trying to make a script because it’s easyer to test it.
So far my script looks like this:
meteo_light_test:
alias: Meteo Light Test
sequence:
- service: light.turn_on
data_template: >
{% if is_state('sensor.openweathermap_forecast_condition', 'clear') %}
{% set d = {'rgb_color':[250,250,210]} %}
{% elif is_state('sensor.openweathermap_forecast_condition', 'clouds') %}
{% set d = {'rgb_color':[135,206,235] } %}
{% elif is_state('sensor.openweathermap_forecast_condition', 'snowy-rainy') %}
{% set d = {'rgb_color':[215,215,245] } %}
{% elif is_state('sensor.openweathermap_forecast_condition', 'rain') %}
{% set d = {'rgb_color':[30,144,255] } %}
{% elif is_state('sensor.openweathermap_forecast_condition', 'snow') %}
{% set d = {'rgb_color':[245,245,245] } %} {% else %}
{% set d = {'rgb_color':[0,245,0] } %}
{% endif %}
{{ d }}
entity_id: light.living_room_spotlight
mode: single
During constant modifications, I managed to turn the light on with it, but the color was bright white (now it’s not even working at all anymore).
I am not sure what I am doing wrong.
Any help or suggestions welcomed.
Some time ago I did something very similar that adjusts my light color in the morning according to the traffic situation.
However, I used a Python script because it was easier for me to understand than the jinja2 templates in Homeassistant Scripts. I only have a script and an automation that calls it up in the morning.
The corrected code works like a charm
It’s good to know that data_template not needed. I got a lot of errors because of that.
Now I need to write the automation and will post the resulting script (if it’s working )
Same for me.
jinja2 templates, specially if I would like to figure out something complicated would be not to understandable for me either.
Thanks for sharing you python script
Actually 8 am at weekdays and 9 am at weekend but I had to test it somehow.
It was a bit confusing for me to start the conditioning with “OR” but I learned the lesson and I feel will be able to do way more after some accommodation time.
Thanks, i have another entitiy name: weather.home instead of sensor.openweathermap_forecast_condition. It seems to work for now! Lets wait till the weather changes to see what it does