Automation - light Color change with weather forecast

Hi,

I’m trying to get a RGB to change color based on weather forecast.
I’m using Openweather and a BRUH RGB light on ESP8266 controlled via MQTT.
my automation code is having an error and I’m stuck without a clue

2017-07-14 19:35:04 ERROR (MainThread) [homeassistant.core] Invalid service data for light.turn_on: None for dictionary value @ data[‘rgb_color’]. Got ‘{% if is_state(“sensor.openw_forecast”, “Clear”) %}[0,0,255] {%-elif is_state(“sensor.openw_forecast”, “Clouds”) %}[0,255,0] {%-elif is_state(“sensor.openw_forecast”, “Rain”) %}[255,0,0] {%-elif is_state(“sensor.openw_forecast”, “Snow”) %}[255,0,255] {% endif %}\n’’

my automation code is:

  • alias: ‘galo’
    trigger:
    platform: state
    entity_id: sensor.openw_forecast
    action:
    • service: light.turn_on
      data:
      entity_id: light.bed_rgb_light
      brightness: 500
      rgb_color: >
      {% if is_state(“sensor.openw_forecast”, “Clear”) %}[0,0,255]
      {%-elif is_state(“sensor.openw_forecast”, “Clouds”) %}[0,255,0]
      {%-elif is_state(“sensor.openw_forecast”, “Rain”) %}[255,0,0]
      {%-elif is_state(“sensor.openw_forecast”, “Snow”) %}[255,0,255]
      {% endif %}

Any hint that could give me a help ?

you need to use data_template in place of data. I am not good enough with templatig to check your template though.

tried that and now gives a diferent error but not working as well

new error with data_template

2017-07-14 20:15:53 ERROR (MainThread) [homeassistant.core] Invalid service data for light.turn_on: None for dictionary value @ data[‘rgb_color’]. Got ‘[0,0,255]’

changing the rgb_color to rgb as on BRUH code for the ESP , gives also error:

2017-07-14 20:23:10 ERROR (MainThread) [homeassistant.core] Invalid service data for light.turn_on: extra keys not allowed @ data[‘rgb’]. Got ‘[0,0,255]’

any thoughts ? I’m sure there is someone using color automations but i’m clued.

thank you in advance,

I’m doing something that sounds similar to what you’re after, but less elegantly, and only hitting one condition. I’ve got an LED small strip on an ESP8266 with the BRUH code in it behind the TV in my gym as an ambient light. It turns on to a solid color at 4:50. At 4:51, if the predicted maximum rain intensity is over 0.01, it switches to the fire animation, then at 7:15 it turns off.

####Turn off Morning LED
  - alias: "Morning LED off"
    initial_state: True
    hide_entity: False
    trigger:
      platform: time
      at: '07:15'
    action:      
      service: homeassistant.turn_off
      entity_id: light.test_leds
    ## Turn on Morning LED each morning
  - alias: "Morning LED on Solid"
    initial_state: True
    hide_entity: False
    trigger:
      platform: time
      at: '04:50'
    action:      
      service: homeassistant.turn_on
      entity_id: light.test_leds
    ## If rainfall is predicted, set Morning LED to animated mode
  - alias: "Morning LED fire - high predicted precipitation"
    initial_state: True
    hide_entity: False
    trigger:
      platform: time
      at: '04:51'
    condition:
      condition: numeric_state
      entity_id: sensor.dark_sky_daily_max_precip_intensity
      above: 0.01
    action:      
      - service: mqtt.publish
        data_template:
          topic: "test/mqttstrip/seteffect"
          payload: "Fire"
      - service: mqtt.publish
        data_template:
          topic: "test/mqttstrip/setanimationspeed"
          payload: 11
2 Likes

Hi,
thank you for the tip on using mqtt payload
I’ve recreated but it now put led always to zero =black

i put trough light switch any color on the led, and when calling the PAYLOAD , the led goes black .

  • alias: ‘galo’
    trigger:
    platform: state
    entity_id: sensor.openw_forecast
    action:
    • service: mqtt.publish
      data_template:
      topic: “bed/rgb1/rgb/set”
      payload: >
      {% if is_state(“sensor.openw_forecast”, “Clear”) %} {“color”: {“r”: 0, “g”: 0, “b”: 255}}
      {%-elif is_state(“sensor.openw_forecast”, “Clouds”) %} {“color”: {“r”: 0, “g”: 255, “b”: 0}}
      {%-elif is_state(“sensor.openw_forecast”, “Rain”) %} {“color”: {“r”: 255, “g”: 0, “b”: 0}}
      {%-elif is_state(“sensor.openw_forecast”, “Snow”) %} {“color”: {“r”: 0, “g”: 255, “b”: 255}}
      {% endif %}

?? any obvious in the code ? … i dont get any error on the log

Can you paste your template into the template dev tool to see what it returns?

??? sorry . I’m kind of new to HA, dont use the DEV tool until now …

Open the side panel (click the three lines in the upper left).

Click the page with a folded corner and the < > symbol in it.

Delete what is there. It’s just an example.

Paste your template in and it will render the result. It’s a fantastic tool to develop templates and test before updating the config.

done . first time I used … :blush: will use now on

the result is

  • alias: ‘galo’
    trigger:
    platform: state
    entity_id: sensor.openw_forecast
    action:
    • service: mqtt.publish
      data_template:
      topic: “bed/rgb1/rgb/set”
      payload: >
      {“color”: {“r”: 0, “g”: 0, “b”: 255}}

the current forecast for my location is Clear , it match but no light on the led

HI,
thank you for the guidance. It’s now working as it should :slight_smile:
the forecast the weather and updates the RGB led.
the final code needed to change as the mqtt topic was incorrect
working version is:

  • alias: ‘galo’
    trigger:
    platform: state
    entity_id: sensor.openw_forecast
    action:
    • service: mqtt.publish
      data_template:
      topic: “bed/rgb1/rgb/set”
      payload: >
      {% if is_state(“sensor.openw_forecast”, “Clear”) %} {“color”: { 0, 0, 255}}
      {%-elif is_state(“sensor.openw_forecast”, “Clouds”) %} {“color”: { 0, 255, 0}}
      {%-elif is_state(“sensor.openw_forecast”, “Rain”) %} {“color”: {255, 0, 0}}
      {%-elif is_state(“sensor.openw_forecast”, “Snow”) %} {“color”: {"0, 255, 255}}
      {% endif %}

thank you for the help.
BTW : there is a old fashioned way to see colors for the weather based on a quimical substance that when painted it changed colors as blue good weather and pink it would rain.
now i have the weather for tomorrow :slight_smile:

3 Likes