mrpinapple
(Mrpinapple)
January 6, 2018, 11:08pm
1
Hi guys!
inspired by this thread: Automation - light Color change with weather forecast
I am trying to change the color of my IKEA lights according to the openweathermap forecast. The YAML files are valid but somehow the code doesnt work. Plz help me out.
automation:
alias: 'Wetter Vorhersage Automatisierung'
hide_entity: False
initial_state: 'on'
trigger:
- platform: state
entity_id: sensor.owm_forecast
condition:
- condition: state
entity_id: input_boolean.weather_forecast_status
state: 'on'
action:
service: light.turn_on
entity_id: light.stehlampe_rgb
data_template:
>
{%- if is_state('sensor.owm_forecast', 'Clear') -%}
brightness: 255
rgb_color: ['250','250','210']
{%-elif is_state('sensor.owm_forecast', 'Clouds') -%}
brightness: 255
rgb_color: ['135','206','235']
{%-elif is_state('sensor.owm_forecast', 'Rain') -%}
brightness: 255
rgb_color: ['30','144','255']
{%-elif is_state('sensor.owm_forecast', 'Snow') -%}
brightness: 255
rgb_color: ['245','245','245']
{%- endif %}
I changed the code a bit. HA loads up now and all the input sliders are there BUT it does not trigger the color change:
alias: "Wetter Vorhersage Automatisierung"
hide_entity: False
initial_state: 'off'
trigger:
- platform: state
entity_id: sensor.owm_forecast
condition:
- condition: state
entity_id: input_boolean.weather_forecast_status
state: 'on'
action:
- service: light.turn_on
entity_id: light.stehlampe_rgb
data_template:
brightness: 254
rgb_color: >-
{% if states.sensor.owm_forecast.state == 'Clear' %}
['250','250','210']
{% elif states.sensor.owm_forecast.state == 'Clouds' %}
['135','206','235']
{% elif states.sensor.owm_forecast.state == 'Rain' %}
['30','144','255']
{% elif states.sensor.owm_forecast.state == 'Snow' %}
['245','245','245']
{% endif %}
mrpinapple
(Mrpinapple)
January 10, 2018, 9:13am
3
I narrowed it down to the last line, where something with the spacing is going wrong (i guess). If i put the if clause in one line the results in the “templates testing tab” are looking good BUT HA does not boot up with this config. Please help me out
alias: "Wetter Vorhersage Automatisierung"
hide_entity: False
initial_state: 'off'
trigger:
- platform: state
entity_id: sensor.owm_forecast
condition:
- condition: state
entity_id: input_boolean.weather_forecast_status
state: 'on'
action:
- service: light.turn_on
entity_id: light.stehlampe_rgb
data_template:
brightness: 254
rgb_color: - {% if states.sensor.owm_forecast.state == 'Clear' %}['250','250','210']{% elif states.sensor.owm_forecast.state == 'Clouds' %}['135','206','235']{% elif states.sensor.owm_forecast.state == 'Rain' %}['30','144','255']{% elif states.sensor.owm_forecast.state == 'Snow' %}['245','245','245']{% endif %}
mrpinapple
(Mrpinapple)
January 10, 2018, 1:30pm
4
Giving up. My last try was this
alias: Wetter Vorhersage Automatisierung
hide_entity: False
initial_state: 'off'
trigger:
- platform: state
entity_id: sensor.owm_forecast
condition:
- condition: state
entity_id: input_boolean.weather_forecast_status
state: 'on'
action:
- service: light.turn_on
entity_id: light.stehlampe_rgb
data_template:
{% if is_state("sensor.owm_forecast", "Clear") -%}
rgb_color: 250,250,210
brightness: 255
{% elif is_state("sensor.owm_forecast", "Clouds") -%}
rgb_color: 135,206,235
brightness: 255
{% elif is_state("sensor.owm_forecast", "Rain") -%}
rgb_color: 30,144,255
brightness: 255
{% elif is_state("sensor.owm_forecast", "Snow") -%}
rgb_color: 245,245,245
brightness: 255
{%- endif %}
The whole yaml stuff is confusing as hell. Escpecially mixing stuff up with a framework like jinja2…
DvD77
(Daniel)
January 16, 2018, 12:58pm
6
I am not a yaml expert but when I paste your code in ATOM with a YAML checker then it gives an error, I marked where the error starts in the above code with “!!”
I think the error is in your templating, check this link:
1 Like
mrpinapple
(Mrpinapple)
January 16, 2018, 2:17pm
7
thank you, sadly I already know this - and as far as i know, i am following every templating rule
sjee
January 16, 2018, 2:45pm
8
You’re code doesn’t validate in the “Template” tab. Try this;
{% if is_state('sensor.owm_forecast', 'Clear') -%}
rgb_color: 250,250,210
brightness: 255
{% elif is_state('sensor.owm_forecast', 'Clouds') -%}
rgb_color: 135,206,235
brightness: 255
{% elif is_state('sensor.owm_forecast', 'Rain') -%}
rgb_color: 30,144,255
brightness: 255
{% elif is_state('sensor.owm_forecast', 'Snow') -%}
rgb_color: 245,245,245
brightness: 255
{%- endif %}
1 Like
mrpinapple
(Mrpinapple)
January 16, 2018, 5:01pm
9
sjee:
{% if is_state(‘sensor.owm_forecast’, ‘Clear’) -%}
rgb_color: 250,250,210
brightness: 255
{% elif is_state(‘sensor.owm_forecast’, ‘Clouds’) -%}
rgb_color: 135,206,235
brightness: 255
{% elif is_state(‘sensor.owm_forecast’, ‘Rain’) -%}
rgb_color: 30,144,255
brightness: 255
{% elif is_state(‘sensor.owm_forecast’, ‘Snow’) -%}
rgb_color: 245,245,245
brightness: 255
{%- endif %}
thanks but sadly this isnt a valid yaml…
YAML Validators will not parse the first line but the “template” tester of HA shows the result i want.
Brings me to an Idea, does the code have to be valid reagarding “standard yaml” or jinja2?
sjee
January 16, 2018, 6:23pm
10
Yaml and Jinja2 are two different things. Jinja2 is templating, Yaml is formatting. Your template did not comply to Jinja2. Now it does. If it passed the HA template testing but your automation still doesn’t work you should check the (yaml) formatting.
1 Like
mrpinapple
(Mrpinapple)
January 17, 2018, 3:41pm
11
Thanks to you guys a made some improvements. No I am having a problem. If I go single line like this
data_template:
rgb_color: -'{% if is_state('sensor.owm_forecast', 'Clear') -%}250,250,210{% elif is_state('sensor.owm_forecast', 'Clouds') -%}135,206,235{% elif is_state('sensor.owm_forecast', 'Rain') -%}30,144,255{% elif is_state('sensor.owm_forecast', 'Snow') -%}245,245,245{%- endif %}'
I get:
Invalid service data for light.turn_on: None for dictionary value @ data['rgb_color']. Got "-'245,245,245'"
How do I get rid of - and " in the parsed code?
If i go multi-line the color codes are one line below the rgb_color and therefore not working…
mrpinapple
(Mrpinapple)
January 18, 2018, 1:25pm
12
found another topic tackling this bug:
Hello.
Firstly I would like to say this is my first post to these forums, g’day from down under
I have been quite happily using HASS for a few months now & would like to say thank you so very much to both the devs & community for such a great project even at the 0.23 stage it is at now. I have high hopes for the future of HASS & hope I will in some way be able to help it & fellow users along the way.
Along with a heap of DIY ESP8266 & Arduino devices, milights, chromecasts, 433MHz alar…
sadly none of the solutions work for me
petro
(Petro)
January 25, 2018, 8:11pm
14
rgb_color: expects a list of integers: [ 0, 0, 0 ]. From the looks of this thread, the closest you got was a list of strings: [ ‘0’,‘0’,‘0’ ].
So try:
data_template:
rgb_color: -'{% if is_state('sensor.owm_forecast', 'Clear') -%}[250,250,210]{% elif is_state('sensor.owm_forecast', 'Clouds') -%}[135,206,235]{% elif is_state('sensor.owm_forecast', 'Rain') -%}[30,144,255]{% elif is_state('sensor.owm_forecast', 'Snow') -%}[245,245,245]{%- endif %}'
1 Like
miguelromao
(Miguel Romao)
January 25, 2018, 11:51pm
15
as for advice on debugging, I would suggest to check results on mqtt dev of your HA , but at the same time, to “see” the mqtt BUS messages, i’ve installed a windows mqtt client (using MQTT.fx ), subscribing all topics.
1 Like
mrpinapple
(Mrpinapple)
January 27, 2018, 10:53am
16
thank you but the output equals:
rgb_color: -'[30,144,255]'
which is which doesnt work because of the - and the ‘’
petro
(Petro)
January 27, 2018, 4:20pm
17
try:
data_template:
rgb_color: >
{% if is_state('sensor.owm_forecast', 'Clear') %}
[250,250,210]
{% elif is_state('sensor.owm_forecast', 'Clouds') %}
[135,206,235]
{% elif is_state('sensor.owm_forecast', 'Rain') %}
[30,144,255]
{% elif is_state('sensor.owm_forecast', 'Snow') %}
[245,245,245]
{% endif %}
I saw a bunch of -%} and {%- all over the place in your syntax. I’ve never had to use that. I’m also not familiar with what those do. They may be needed, but give this a whirl without them.
1 Like
mrpinapple
(Mrpinapple)
January 29, 2018, 3:24pm
18
Results in…
Invalid service data for light.turn_on: None for dictionary value @ data['rgb_color']. Got '[135,206,235]'
…like most “multi line attempts” on this.
petro
(Petro)
January 29, 2018, 8:27pm
19
Do we know the normal shape of the dictionary for changing the color? What would a normal template look like without it being dynamic?
Try:
data_template:
{% if is_state('sensor.owm_forecast', 'Clear') %}
{'rgb_color':[250,250,210] }
{% elif is_state('sensor.owm_forecast', 'Clouds') %}
{'rgb_color':[135,206,235] }
{% elif is_state('sensor.owm_forecast', 'Rain') %}
{'rgb_color':[30,144,255] }
{% elif is_state('sensor.owm_forecast', 'Snow') %}
{'rgb_color':[245,245,245] }
{% endif %}
That will return a dictionary, which is what the ‘data’ template requires.
1 Like
Wesley2004
(Wesley Van Doren)
February 1, 2018, 7:09am
20
I have same problems!
I want to change rgb color depending on time.
Use almost same code but it gives me the same error messages.
1 Like