Changing the colour of one light when the colour of another changes


#1

I have a room with Hue lights, and a yeelight light strip, I’m trying to get the yeelight to match the hue when the switch on the wall changes the colour.

So I did a bunch of research on this, and it looks like it should be possible with an automation like this:

- alias: 'Sync Bedroom Dresser Colour'
trigger:
  platform: template
  value_template: "{{ states.light.master_bedroom.attributes.rgb_color }}"
action:
  - service: light.turn_on
    entity_id:
      - light.masterbedroomdresser
    data_template:
      brightness: 255
      transition: 10
      rgb_color: [{{ states.light.master_bedroom.attributes.rgb_color}}]

However when I run this automation by hand I get the following error:
2018-09-22 19:33:45 INFO (MainThread) [homeassistant.core] Bus:Handling <Event call_service[L]: service_data=rgb_color=(255, 234, 216), entity_id=['light.masterbedroomdresser'], brightness=255, transition=10, service=turn_on, domain=light>
2018-09-22 19:33:45 ERROR (MainThread) [homeassistant.core] Invalid service data for light.turn_on: None for dictionary value @ data['rgb_color']. Got '(255, 234, 216)'

I have tried a number of ways to change those brackets into square brackets but no matter what I do HA always puts my variable inside a pair of brackets ()

Any ideas?


#2

try putting a space after rgb_color in your last line.
and learn how to spell color :slight_smile:


#3

change it to:

rgb_color: "{{ states.light.master_bedroom.attributes.rgb_color | list }}"

#4

Hi, thanks for that suggestion It gets me closer and the error is different, but result the same.

  - alias: 'Sync Bedroom Dresser Colour'
trigger:
  platform: template
  value_template: "{{ states.light.master_bedroom.attributes.rgb_color }}"
action:
  - service: light.turn_on
    entity_id:
      - light.masterbedroomdresser
    data_template:
      brightness: 255 
      transition: 10 
      rgb_color: "{{ states.light.master_bedroom.attributes.rgb_color | list }}"


2018-09-22 21:21:56 INFO (MainThread) [homeassistant.core] Bus:Handling <Event call_service[L]: service_data=rgb_color=[255, 188, 85], entity_id=['light.masterbedroomdresser'], service=turn_on, domain=light>
2018-09-22 21:21:56 ERROR (MainThread) [homeassistant.core] Invalid service data for light.turn_on: None for dictionary value @ data['rgb_color']. Got '[255, 188, 85]'

I tried it by commenting out the brightness and transition lines as well, with no joy.

Any other suggestions?


#5

He did, bloody colonials. :wink:


#6

Found it… Templates only return strings. So this is needed:

          rgb_color: 
        - "{{ states.light.master_bedroom.attributes.rgb_color[0] | int }}" 
        - "{{ states.light.master_bedroom.attributes.rgb_color[1] | int }}" 
        - "{{ states.light.master_bedroom.attributes.rgb_color[2] | int }}" 

Now to figure out how to make the automation fire when the other light changes.


#7

just trigger off state changes whenever the other light changes:

trigger:
  - platform: state
    entity_id: light.otherlight
action:
  - service: light.turn_on
    data_template:
      entity_id: light.masterbedroomdresser
      rgb_color: 
        - "{{ trigger.to_state.attributes.rgb_color[0] | int }}" 
        - "{{ trigger.to_state.attributes.rgb_color[1] | int }}" 
        - "{{ trigger.to_state.attributes.rgb_color[2] | int }}" 
  

You don’t need to specify anything else.


#8

That did it, thanks!