Setting up two lights to turn on and match each others brightness?

I have two light switches in a room that control two separate lights. I want to setup an automation that will turn on the other light to the same brightness level as the light that is turned on. So, if either of the switches are turned on to a specific brightness level, the other light switch will turn on and match it, and visa versa.

Additionally have it setup so that the brightness between the two switches is always synced regardless of which switch the brightness is changed on.

I’m a newb, and I don’t even really know where to start. Any help with the syntax on this?

Thanks!

Here you go…

sensor:
  - platform: template
    sensors:
      brightness_test:
        friendly_name: "Brightness Test"
        value_template: '{{ states.light.test_lamp_1.attributes.brightness }}'
        
#
automation:
  - id: 'brightness test'
    alias: brightness test
    trigger:
      - platform: state
        entity_id: sensor.brightness_test
    action:
      - service: light.turn_on
        entity_id: light.test_lamp_2
      - delay: '00:00:03'
      - service: light.turn_on
        entity_id: light.test_lamp_2
        data_template:
          brightness: '{{ states.sensor.brightness_test.state }}
1 Like

THese two automations should do it without the extra sensor. It has a trigger that watches for a state change and if the change is different than the current brightness of the other light, it will update the other light.

I haven’t checked the syntax so there may be errors but this should give you some guidance.

alias: "light1 > light2"
trigger:
  platform: state
  entity_id: light.light1
condition:
  condition: template
  value_template: "{{ not is_state_attr('light.light1_level', 'brightness', states.light.light2_level.attributes.brightness ) }}"
action:
  service: light.turn_on
  data_template:
    entity_id: input_slider.playbar_volume
    value: "{{ trigger.to_state.attributes.brightness }}"


alias: "light2 > light1"
trigger:
  platform: state
  entity_id: light.light2
condition:
  condition: template
  value_template: "{{ not is_state_attr('light.light2_level', 'brightness', states.light.light1_level.attributes.brightness ) }}"
action:
  service: light.turn_on
  data_template:
    entity_id: input_slider.playbar_volume
    value: "{{ trigger.to_state.attributes.brightness }}"

I’m looking for this but with color included.

Is adding a color option just as easy?

Hey, this is what I ended up setting up that is currently working for brightness:

- id: '1589816799447'
  alias: Cabinet Brightness 1 to 2
  description: ''
  trigger:
  - entity_id: light.kitchen_under_cabinet_1
    platform: state
  condition: []
  action:
  - delay: 00:00:01
  - data_template:
      brightness: '{{ states.sensor.brightness_cabinet1.state }}'
    entity_id: light.kitchen_under_cabinet_2
    service: light.turn_on

And then another one going the other direction. The automation is using two sensors I created in the config for the brightness values, like this…

sensor:
  - platform: template
    sensors:
      brightness_cabinet1:
        friendly_name: "Brightness Cabinet 1"
        value_template: '{{ states.light.kitchen_under_cabinet_1.attributes.brightness }}'
  - platform: template
    sensors:
      brightness_cabinet2:
        friendly_name: "Brightness Cabinet 2"
        value_template: '{{ states.light.kitchen_under_cabinet_2.attributes.brightness }}'

I’m no expert, but I imagine you could just create two more sensors for the rgb value of each of the lights, like this…

sensor:
  - platform: template
    sensors:
      rgb_cabinet1:
        friendly_name: "RGB Cabinet 1"
        value_template: '{{ states.light.kitchen_under_cabinet_1.attributes.rgb_color }}'
  - platform: template
    sensors:
      rgb_cabinet2:
        friendly_name: "RGB Cabinet 2"
        value_template: '{{ states.light.kitchen_under_cabinet_2.attributes.rgb_color }}'

And add in another line under the data_template for the RGB value in the automation, like this…


- data_template:
      brightness: '{{ states.sensor.brightness_cabinet1.state }}'
      rgb_color: '{{ states.sensor.rgb_cabinet1.state }}'
    entity_id: light.kitchen_under_cabinet_2
    service: light.turn_on

Like, I said, I’m no expert with this, and I have no way to test this because I don’t have any lights that can change color, but give it a try!

1 Like

Ok thanks!

I came across this post doing a google search. The example by @Ted_Gore does not work because rgb_color expects a list and his code will return a string. Thankfully, we can overcome this limitation by breaking each color out like this:

data_template:
  brightness: '{{ states.light.hallway_light_1.attributes.brightness }}'
  rgb_color: 
  - '{{ states.light.hallway_light_1.attributes.rgb_color[0] }}'
  - '{{ states.light.hallway_light_1.attributes.rgb_color[1] }}'
  - '{{ states.light.hallway_light_1.attributes.rgb_color[2] }}'

For anyone fighting this like I was, I’m using a sensor that outputs in percentage. The lights I’m using take brightness on a scale of 0-255. Here’s what I used that worked (please note the conversion to float, then multiply by 2.55):

alias: Kitchen Cabinets Brightness
description: ''
trigger:
  - platform: state
    entity_id: sensor.kitchen_periodic_lights
action:
  - service: light.turn_on
    entity_id: light.kitchen_cabinets_right
    data_template:
      brightness: '{{ states.sensor.kitchen_periodic_lights.state|float * 2.55 }}'
  - service: light.turn_on
    entity_id: light.kitchen_cabinets_left
    data_template:
      brightness: '{{ states.sensor.kitchen_periodic_lights.state|float * 2.55 }}'
  - service: light.turn_on
    entity_id: light.kitchen_cabinets_coffee
    data_template:
      brightness: '{{ states.sensor.kitchen_periodic_lights.state|float * 2.55 }}'
mode: restart

I’m using the latest automation/sensors, and for me it is working on turning the lights and setting the brightness, but it’s not working when turning off the lights.

Hi, just in case somebody bumps into this topic. This is a working code with newer syntax

alias: light 1 --> 2
description: ''
trigger:
  - platform: state
    entity_id: light.light1
condition:
  - condition: template
    value_template: >
      {{ not is_state_attr('light.light1', 'brightness',
      states.light.light2.attributes.brightness ) }}
action:
  - choose:
      - conditions:
          - condition: state
            entity_id: light.light1
            state: 'off'
        sequence:
          - service: light.turn_off
            target:
              entity_id: light.light2
      - conditions:
          - condition: state
            entity_id: light.light1
            state: 'on'
        sequence:
          - service: light.turn_on
            target:
              entity_id: light.light2
            data:
              brightness: '{{ trigger.to_state.attributes.brightness }}'
    default: []
mode: single
3 Likes

Hi

It’s possible to do it for RBG and Brightness at the same time and on/off… here is the full script

Hope it helps

alias: Sync light
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 }}'
3 Likes

Or you can simply create 2 entities of type “light switch”, then create an entity of type “light group” with those:

add this to your configuration.yaml:

light: !include lights.yaml

create a lights.yaml file and add this:

  - platform: switch
    name: officelamp1
    entity_id: switch.officelamp1

  - platform: switch
    name: officelamp2
    entity_id: switch.officelamp2

  - platform: group
    name: office_all_lights
    entities:
    - light.officelamp1
    - light.officelamp2

and then just use that new entity “office_all_lights” as a normal light. Both lights will be perfectly in sync.

See doc here:
https://www.home-assistant.io/integrations/light.group/
https://www.home-assistant.io/integrations/light.switch

1 Like

Template Light > light automations.

Mind was blown when I found out about it.

This works beautifully. Thank you.

Very new to HA… I added this automation to my setup, however, I noticed that if changing the state/brightness via the physical switch there is a very long delay between when the second entity updates. Via HA app is almost instant. Any way to resolve this?