I have a little project on the go - I’m using two bulbs, #1 displays the temperature forecast in terms of weather chart colours and #2 displays different colours for conditions.
For example. Sunny produces yellow/orange. Cloudy produces off white, rain produces blue etc.
I have the temperature colours changing as expected:
but the forecast automation isn’t changing as expected.
service: light.turn_on
target:
entity_id: light.hue_go_1_4
data_template:
brightness_pct: 60
transition: 10
hs_color: >
{% set forecast = state_attr('weather.home', 'forecast') | lower %} {% set
hue = 0 %} {% if 'partlycloudy' in forecast %}
{% set hue = 195 %}
{% elif 'sunny' in forecast or 'sun' in forecast or 'mostlysunny' in
forecast or 'mostly sunny' in forecast %}
{% set hue = 60 %}
{% elif 'cloudy' in forecast %}
{% set hue = 220 %}
{% elif 'mostlycloudy' in forecast %}
{% set hue = 195 %}
{% elif 'rainy' in forecast or 'rain' in forecast or 'heavyrain' in forecast
or 'thunderstorms' in forecast %}
{% set hue = 240 %}
{% endif %} {% if 'partlycloudy' in forecast or 'cloudy' in forecast or
'mostlycloudy' in forecast or 'fog' in forecast %}
{% set saturation = 15 %}
{% else %}
{% set saturation = 100 %}
{% endif %} {{ hue }}, {{ saturation }}
Is it obvious to anyone else where I have gone wrong?
cheers.
The temperature works for me too (glad it’s working for you).
It’s the 2nd one I’m having trouble with. I’m trying Met office to see if that works
service: light.turn_on
target:
entity_id: light.hue_go_1_4
data_template:
brightness_pct: 60
transition: 10
hs_color: >
{% set forecast = state_attr('weather.met_office_saltdean_beach_3_hourly', 'forecast') | lower %} {% set
hue = 0 %} {% if 'partlycloudy' in forecast %}
{% set hue = 195 %}
{% elif 'sunny' in forecast or 'sun' in forecast or 'mostlysunny' in
forecast or 'mostly sunny' in forecast %}
{% set hue = 60 %}
{% elif 'cloudy' in forecast %}
{% set hue = 220 %}
{% elif 'mostlycloudy' in forecast %}
{% set hue = 195 %}
{% elif 'rainy' in forecast or 'rain' in forecast or 'heavyrain' in forecast
or 'thunderstorms' in forecast %}
{% set hue = 240 %}
{% endif %} {% if 'partlycloudy' in forecast or 'cloudy' in forecast or
'mostlycloudy' in forecast or 'fog' in forecast %}
{% set saturation = 15 %}
{% else %}
{% set saturation = 100 %}
{% endif %} {{ hue }}, {{ saturation }}
OK, I think you need an {% else %} statement for forecast as mine is `Lightning, rainy’ right now which isn’t covered in your code.
{% if 'partlycloudy' in forecast %} {% set hue = 195 %}
{% elif 'sunny' in forecast or 'sun' in forecast or 'mostlysunny' in forecast or 'mostly sunny' in forecast %} {% set hue = 60 %}
{% elif 'cloudy' in forecast %} {% set hue = 220 %}
{% elif 'mostlycloudy' in forecast %} {% set hue = 195 %}
{% elif 'rainy' in forecast or 'rain' in forecast or 'heavyrain' in forecast or 'thunderstorms' in forecast %} {% set hue = 240 %}
{% else %} {% set hue = <xxx> %}
^
{% endif %}
The forecast attribute contains a list value. Each item in the list is a dictionary containing several keys including a condition key. That’s the one whose value can be rainy, sunny, etc.
To get the value of the first item’s (zeroth index position) condition key, you would do this:
service: light.turn_on
target:
entity_id: light.hue_go_1_4
data:
brightness_pct: 60
transition: 10
hs_color: >
{% set forecast = state_attr('weather.home', 'forecast')[0].condition | lower %}
{% set hue = 0 %}
{% if 'partlycloudy' in forecast %}
{% set hue = 195 %}
{% elif 'sunny' in forecast or 'sun' in forecast or 'mostlysunny' in
forecast or 'mostly sunny' in forecast %}
{% set hue = 60 %}
{% elif 'cloudy' in forecast %}
{% set hue = 220 %}
{% elif 'mostlycloudy' in forecast %}
{% set hue = 195 %}
{% elif 'rainy' in forecast or 'rain' in forecast or 'heavyrain' in forecast
or 'thunderstorms' in forecast %}
{% set hue = 240 %}
{% endif %} {% if 'partlycloudy' in forecast or 'cloudy' in forecast or
'mostlycloudy' in forecast or 'fog' in forecast %}
{% set saturation = 15 %}
{% else %}
{% set saturation = 100 %}
{% endif %}
[{{ hue }}, {{ saturation }}]
I’ve just changed it to the met office and now the light is Yellow to represent the Sun as it’s nice and sunny here atm. Looking good! Hopefully this is going to work. I appreciate your help!