Sadly none of the codes work yet.
…Aaaannnd OWM just changed their API, so there are more than 4 Conditions now.
So you don’t know what changing rgb in a data section would look like without using a data_template and just using yaml?
Example, for a IOS notification, the data shape looks like this in yaml:
- service: nofity.ios_phone
data:
push:
badge: 5
So if i were to make a data template as a dictionary, it would look like this:
data_template: “{“push”:{“badge”:5}}”
If you can show me the actual shape of the yaml, i can help you make a data_template that works.
thank you for your help.
action:
- service: light.turn_on
entity_id: light.stehlampe_rgb
data:
rgb_color: [30,144,255]
this works without any problems.
odd, then a data_template like this should work:
{“rgb_color”:[30,144,255]}
try this:
data_template: >
{% if is_state('sensor.owm_forecast', 'Clear') %}
{% set d = {'rgb_color':[250,250,210]} %}
{% elif is_state('sensor.owm_forecast', 'Clouds') %}
{% set d = {'rgb_color':[135,206,235] } %}
{% elif is_state('sensor.owm_forecast', 'Rain') %}
{% set d = {'rgb_color':[30,144,255] } %}
{% elif is_state('sensor.owm_forecast', 'Snow') %}
{% set d = {'rgb_color':[245,245,245] } %}
{% endif %}
{{ d }}
Sorry but this fails at config validation
I might be wrong on this but the template might be
"{“rgb_color”:[30,144,255]}"
because in your example it was:
data_template: “{“push”:{“badge”:5}}”
How did you test if it’s valid?
The template works fine, just tested it. If it fails yamllint this is due to the syntax. As mentioned before these are two different things.
I got you there.
According to yamlint petros code is valid.
HA inbuild config validator says the file doesnt work
using the template tester, this works fine in my system:
{% if is_state('sensor.yweather_condition', 'Snow') %}
{% set x = {'rgb_color':[1,2,3]} %}
{% endif %}
{{ x }}
I’m not sure why its not working for you. What is the error?
The data template in my example has a different dictionary shape than yours. Thats why it looks different:
This:
- service: nofity.ios_phone
data:
push:
badge: 5
translates to this dictionary shape:
{“push”:{“badge”:5}}
This:
action:
- service: light.turn_on
entity_id: light.stehlampe_rgb
data:
rgb_color: [30,144,255]
translates to:
{“rgb_color”:[30,144,255]}
- action: ?
- data_template: ?
rgb_color: [source /config/automations.yaml:65]
- <homeassistant.helpers.template.Template object at 0x73af2d70>
- <homeassistant.helpers.template.Template object at 0x73af2ed0>
- <homeassistant.helpers.template.Template object at 0x73aebeb0>
transition: <homeassistant.helpers.template.Template object at 0x73af2db0>
entity_id: ?
can you paste your yaml? That error doesn’t help at all.
input_boolean:
weather_forecast_status:
initial: 'on'
automation:
- 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') %}
{% set d = {'rgb_color':[250,250,210]} %}
{% elif is_state('sensor.owm_forecast', 'Clouds') %}
{% set d = {'rgb_color':[135,206,235] } %}
{% elif is_state('sensor.owm_forecast', 'Rain') %}
{% set d = {'rgb_color':[30,144,255] } %}
{% elif is_state('sensor.owm_forecast', 'Snow') %}
{% set d = {'rgb_color':[245,245,245] } %}
{% endif %}
{{ d }}
Try this. Added an else clause at the end incase its none of those scenarios so that it has a data template.
input_boolean:
weather_forecast_status:
initial: 'on'
automation:
- 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') %}
{% set d = {'rgb_color':[250,250,210]} %}
{% elif is_state('sensor.owm_forecast', 'Clouds') %}
{% set d = {'rgb_color':[135,206,235] } %}
{% elif is_state('sensor.owm_forecast', 'Rain') %}
{% set d = {'rgb_color':[30,144,255] } %}
{% elif is_state('sensor.owm_forecast', 'Snow') %}
{% set d = {'rgb_color':[245,245,245] } %}
{% else %}
{% set d = {'rgb_color':[0,0,0] } %}
{% endif %}
{{ d }}
thank you so far really glad you are putting time into it. Inbuilt config validator shows me this (hope it helps):
[automation]: expected a dictionary for dictionary value @ data['action'][0]['data_template']. Got None. (See /config/configuration.yaml, line 77). Please check the docs at https://home-assistant.io/components/automation/
I’m not sure, that doesn’t make sense because it always returns a dictionary.
I donno… try:
input_boolean:
weather_forecast_status:
initial: 'on'
automation:
- 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') %}
{{ dict(rgb_color=[250,250,210]) }}
{% elif is_state('sensor.owm_forecast', 'Clouds') %}
{{ dict(rgb_color=[135,206,235]) }}
{% elif is_state('sensor.owm_forecast', 'Rain') %}
{{ dict(rgb_color=[30,144,255]) }}
{% elif is_state('sensor.owm_forecast', 'Snow') %}
{{ dict(rgb_color=[245,245,245]) }}
{% else %}
{{ dict(rgb_color=[0,0,0]) }}
{% endif %}
If this doesn’t work then I don’t know what will.
sorry - no luck. inbuild validator throws an error
Hi guys,
I-ve it working with code below , but its implemented in BRUH multisensor and other mqtt light as well
note that trigger for showing the "weather color " is movement but IF then ELSE is the same , plus with some new states from OpenWeather API
- alias: ‘sensor.mq_pir turn_on light.galo_tempo motion_detected’
trigger:
platform: state
entity_id: sensor.mq_pir
to: ‘motion detected’
action:
- service: mqtt.publish
data_template:
topic: “bruh/mqsen/set”
payload: >
{% if is_state(“sensor.openw_forecast”, “Clear”) %} {“state”: “ON”, “brightness”: 254, “color”: {“r”: 0, “g”: 0,“b”: 250}}
{% elif is_state(“sensor.openw_forecast”, “clear sky”) %} {“state”: “ON”, “brightness”: 254, “color”: {“r”: 0, “g”: 0,“b”: 250}}
{%-elif is_state(“sensor.openw_forecast”, “broken clouds”) %} {“state”: “ON”, “brightness”: 254, “color”: {“r”: 0, “g”: 100,“b”: 250}}
{%-elif is_state(“sensor.openw_forecast”, “Clouds”) %} {“state”: “ON”, “brightness”: 254, “color”: {“r”: 0, “g”: 250,“b”: 0}}
{%-elif is_state(“sensor.openw_forecast”, “Rain”) %} {“state”: “ON”, “brightness”: 254, “color”: {“r”: 250, “g”: 0,“b”: 0}}
{%-elif is_state(“sensor.openw_forecast”, “light rain”) %} {“state”: “ON”, “brightness”: 254, “color”: {“r”: 150, “g”: 100,“b”: 0}}
{%-elif is_state(“sensor.openw_forecast”, “Snow”) %} {“state”: “ON”, “brightness”: 254, “color”: {“r”: 0, “g”: 250,“b”: 250}}
{% endif %}
… I would recommend a MQTT client , with subscrition to all mqtt topics, aiming to troubleshooting the wrong code …
I too have been struggling with this error
Invalid service data for light.turn_on: None for dictionary value @ data['rgb_color']. Got "-'245,245,245'"
all day, trying to get my hue lights to turn on more blue if the weather is cold, in the morning. I just couldn’t get the template to pass the correct info for xy_color.
I’ve managed to bodge it by calling a scene instead. I created 3 scenes (ice / medium / hot)…
- name: KitchenIce
entities:
light.kitchen_strip:
state: on
xy_color: [0.2309,0.2889]
- name: KitchenMed
entities:
light.kitchen_strip:
state: on
xy_color: [0.3542,0.362]
- name: KitchenHot
entities:
light.kitchen_strip:
state: on
xy_color: [0.4949,0.4202]
Then, I call the scene depending on how cold the met office sensor is.
- id: WeekdayMorningLightBoost
alias: Weekday Morning Light Boost
trigger:
platform: time
at: '06:55:00'
condition:
condition: time
weekday:
- mon
- tue
- wed
- thu
- fri
action:
service: scene.turn_on
data_template:
entity_id: >-
{%- if states.sensor.met_office_temperature.state|int >= 10 -%}
scene.kitchenhot
{%- elif states.sensor.met_office_temperature.state|int <= 2 -%}
scene.kitchenice
{%- else -%}
scene.kitchenmed
{%- endif -%}
I’m a complete beginner, but through trial and error, and googling all day, this seems to be working for me.
ps. Is there a guide somewhere as to what >- means, and the difference between {% and {%- ??