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

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?

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

change it to:

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

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?

He did, bloody colonials. :wink:

2 Likes

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.

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.


EDIT: 2021 + update

trigger:
  - platform: state
    entity_id: light.otherlight
action:
  - service: light.turn_on
    target:
      entity_id: light.masterbedroomdresser
    data:
      rgb_color: "{{ trigger.to_state.attributes.rgb_color }}"
4 Likes

That did it, thanks!

1 Like

Thanks for the 2021 update. Yooge!

Hi,

Just convined other post with this one to have full sync between the two lights (on/off, color and brightness)

Just update light.source and light.dest with your own ones.

Hope it helps

alias: Light sync
trigger:
  - platform: state
    entity_id: light.source
action:
  - choose:
      - conditions:
          - condition: state
            entity_id: light.source
            state: 'off'
        sequence:
          - service: light.turn_off
            target:
              entity_id: light.dest
      - conditions:
          - condition: state
            entity_id: light.source
            state: 'on'
        sequence:
          - service: light.turn_on
            target:
              entity_id: light.dest
            data:
              rgb_color: '{{ trigger.to_state.attributes.rgb_color }}'
              brightness: '{{ trigger.to_state.attributes.brightness }}'