Primary and Secondary Lights

This is my first attempt with blueprints. I use it with my bathroom lights. I have the main light and the mirror light and use this to turn on the primary(main) light when the secondary(mirror) is turned on and turn off the secondary(mirror) light when the primary(main) is turned off.

blueprint:
  name: Synchronize Primary and Secondary Lights
  description: Turn on the primary light when the secondary is turned on and turn off the secondary light when the primary is turned off.
  domain: automation
  input:
    primary_light:
      name: Main light
      description: This is the primary light, will be turned on when the secondary light is turned on.
      selector:
        target:
          entity:
            domain: light
    secondary_light:
      name: Mirror light
      description: This is the secondary light, will be turned off when the primary light is turned off.
      selector:
        target:
          entity:
            domain: light

trigger:
  - platform: state
    entity_id: !input primary_light
    to: "on"
  - platform: state
    entity_id: !input secondary_light
    to: "off"

action:
  choose:
    - conditions:
        - condition: template
          value_template: "{{ trigger.to_state.state == 'on' }}"
      sequence:
        - service: light.turn_on
          entity_id: !input secondary_light
    - conditions:
        - condition: template
          value_template: "{{ trigger.to_state.state == 'off' }}"
      sequence:
        - service: light.turn_off
          entity_id: !input primary_light
  default: []
1 Like

Typo, it’s not sincronize, it’s synchronize. Also you could use templating for the service (light.turn_(on/off) instead of choose.

2 Likes

FWIW, another possibility is the Light Group integration. It allows you to create a “master light” that controls a group of lights (including setting brightness and color for all applicable lights). It’s not identical to your automation but represents another way to keep lights synchronized.

2 Likes

By mistake the primary and secondary lights where swapped.
Where is the correct version:

blueprint:
  name: Synchronize Primary and Secondary Lights
  description: Turn on the primary light when the secondary is turned on and turn off the secondary light when the primary is turned off.
  domain: automation
  input:
    primary_light:
      name: Main light
      description: This is the primary light, will be turned on when the secondary light is turned on.
      selector:
        target:
          entity:
            domain: light
    secondary_light:
      name: Mirror light
      description: This is the secondary light, will be turned off when the primary light is turned off.
      selector:
        target:
          entity:
            domain: light

trigger:
  - platform: state
    entity_id: !input secondary_light
    to: "on"
  - platform: state
    entity_id: !input primary_light
    to: "off"

action:
  choose:
    - conditions:
        - condition: template
          value_template: "{{ trigger.to_state.state == 'on' }}"
      sequence:
        - service: light.turn_on
          entity_id: !input primary_light
    - conditions:
        - condition: template
          value_template: "{{ trigger.to_state.state == 'off' }}"
      sequence:
        - service: light.turn_off
          entity_id: !input secondary_light
  default: []

@KTibow thanks for the typo correction. My portuguese spell checker as a live of its own. :blush:

Referring to the latest version of the blueprint, if the secondary light is turned off, or the primary light is turned on, the automation will not be triggered, so the two lights will not be synchronized.

2 Likes

Does this blueprint work for anyone because it doesn’t work for me. I used it to select two light entities and the Log reports the following:

Logger: homeassistant.components.automation
Source: components/automation/init.py:517
Integration: Automation (documentation, issues)
First occurred: 11:09:48 AM (1 occurrences)
Last logged: 11:09:48 AM

Blueprint Synchronize Primary and Secondary Lights generated invalid automation with inputs OrderedDict([(‘primary_light’, OrderedDict([(‘entity_id’, ‘light.floor_lamp’)])), (‘secondary_light’, OrderedDict([(‘entity_id’, ‘light.hue_color_lamp_4’)]))]): not a valid value for dictionary value @ data[‘action’][0][‘choose’][0][‘sequence’][0][‘entity_id’]. Got None

The blueprint defines two inputs using the target selector. Shouldn’t the automation refer to the target?

1 Like

@123 You are right the selector should be an entity selector not a target selector.

The name of the blueprint should not be synchronize. Its probably misleading.

The purpose of this automation is to have a primary and a secondary lights in the same room when it doesn’t make sense to have only the secondary light on. Like in the bathroom with the main light (celling) and the mirror light. When you turn on the mirror light the automation turns on the main light. When you turn off the main light the automation turns off the mirror light. Just this.

Like this is working fine for me

blueprint:
  name: Synchronize Primary and Secondary Lights
  description: Turn on the primary light when the secondary is turned on and turn off the secondary light when the primary is turned off.
  domain: automation
  input:
    primary_light:
      name: Main light
      description: This is the primary light, will be turned on when the secondary light is turned on.
      selector:
        entity:
          domain: light
    secondary_light:
      name: Mirror light
      description: This is the secondary light, will be turned off when the primary light is turned off.
      selector:
        entity:
          domain: light

trigger:
  - platform: state
    entity_id: !input secondary_light
    to: "on"
  - platform: state
    entity_id: !input primary_light
    to: "off"

action:
  choose:
    - conditions:
        - condition: template
          value_template: "{{ trigger.to_state.state == 'on' }}"
      sequence:
        - service: light.turn_on
          entity_id: !input primary_light
    - conditions:
        - condition: template
          value_template: "{{ trigger.to_state.state == 'off' }}"
      sequence:
        - service: light.turn_off
          entity_id: !input secondary_light
  default: []

Primary and Secondary where a bit mixed up…
Trigger should reflect primary light only,
and actions only act on secondary (mirror)
This works better :wink:

blueprint:
  name: Synchronize Primary and Secondary Lights
  description: Turn on the primary light when the secondary is turned on and turn off the secondary light when the primary is turned off.
  domain: automation
  input:
    primary_light:
      name: Main light
      description: This is the primary light, will be turned on when the secondary light is turned on.
      selector:
        entity:
          domain: light
    secondary_light:
      name: Mirror light
      description: This is the secondary light, will be turned off when the primary light is turned off.
      selector:
        entity:
          domain: light

trigger:
  - platform: state
    entity_id: !input primary_light
    to: "on"
  - platform: state
    entity_id: !input primary_light
    to: "off"

action:
  choose:
    - conditions:
        - condition: template
          value_template: "{{ trigger.to_state.state == 'on' }}"
      sequence:
        - service: light.turn_on
          entity_id: !input secondary_light
    - conditions:
        - condition: template
          value_template: "{{ trigger.to_state.state == 'off' }}"
      sequence:
        - service: light.turn_off
          entity_id: !input secondary_light
  default: []

When I have time, I will extend this to include brightness (dimmer) :wink:

You missed something.
The primary light should also be turned off when the secondary light is turned off.

That is possible, but i don’t have need for that at this moment…
Maybe i should call it master/slave instead :yum:

But i will work on this, first to incorporate brightness changes :yum:

Hmm
Brightness doesn’t seem to work alongside this automation.

But this will do both on/off on primary/secondary as suggested by you:

blueprint:
  name: Synchronize Primary and Secondary Lights
  description: Turn on the primary light when the secondary is turned on and turn off the secondary light when the primary is turned off and vise versa.
  domain: automation
  input:
    primary_light:
      name: Main light
      description: This is the primary light, will be turned on/off when the secondary light is turned on/off.
      selector:
        entity:
          domain: light
    secondary_light:
      name: Mirror light
      description: This is the secondary light, will be turned on/off when the primary light is turned on/off.
      selector:
        entity:
          domain: light

trigger:
  - platform: state
    entity_id: !input primary_light
    to: "on"
  - platform: state
    entity_id: !input primary_light
    to: "off"
  - platform: state
    entity_id: !input secondary_light
    to: "on"
  - platform: state
    entity_id: !input secondary_light
    to: "off"

action:
  choose:
    - conditions:
        - condition: template
          value_template: "{{ trigger.to_state.state == 'on' }}"
      sequence:
        - service: light.turn_on
          entity_id: !input primary_light
          entity_id: !input secondary_light
    - conditions:
        - condition: template
          value_template: "{{ trigger.to_state.state == 'off' }}"
      sequence:
        - service: light.turn_off
          entity_id: !input primary_light
          entity_id: !input secondary_light
  default: []

And couldn’t get brightness to work within the same automation, however it works when used stand-alone :face_with_raised_eyebrow:

blueprint:
  name: Follow brightness of master on slave
  description: Follow brightness of master on slave
  domain: automation
  input:
    primary_light:
      name: Main light
      description: This is the primary light, the master of brightness.
      selector:
        entity:
          domain: light
    secondary_light:
      name: Mirror light
      description: This is the secondary light, the slave for brightness.
      selector:
        entity:
          domain: light

trigger:
  - platform: state
    entity_id: !input primary_light
    attribute: brightness

action:
  - service: light.turn_on
    entity_id: !input secondary_light
    data:
      brightness: '{{ trigger.to_state.attributes.brightness }}'