Help with automation: Linking 2 bulbs' attributes

Hello everyone,

I’m trying to link 2 bulbs to eachothers attributes, starting with brightness (1 is a simulated bulb, the other a wifi bulb).
The idea is when one of the 2 changes brightness, the other get its brightness updated.
However it doesn’t seem to work… Both bulbs won’t update. What am I missing here?

- alias: Bedroom brightness link
  initial_state: 'on'
  trigger:
    - platform: template
      value_template: '{{ states.light.slaapkamer.attributes.brightness }}'
    - platform: template
      value_template: '{{ states.light.bedroom_light.attributes.brightness }}'   
  condition:
    - condition: template
      value_template: '{{ not is_state_attr("light.slaapkamer", "brightness", "(states.light.bedroom_light.attributes.brightness)") }}'
  action:
    - service: light.turn_on
      data_template:
        entity_id: >-
          {% if ('trigger.entity_id.attributes.friendly_name' == 'Slaapkamer') %}
            light.bedroom_light
          {% else %}
            light.slaapkamer
          {% endif %}
        brightness: >-
          {% if ('trigger.entity_id.attributes.friendly_name' == 'Slaapkamer') %}
            {{ states.light.bedroom_light.attributes.brightness }}
          {% else %}
            {{ states.light.slaapkamer.attributes.brightness }}
          {% endif %}

Anyone have an idea, please? :blush:

Try simple state triggers, no to or from and then a condition check to see if the brightness has changed. Right now you’re not doing any comparison in the trigger, so it’ll never be true or false.

  trigger:
    - platform: state
      entity_id: light.slaapkamer
    - platform: state
      entity_id: light.bedroom_light   
  condition:
    - condition: template
      value_template: '{{ trigger.to_state.attributes.brightness != trigger.from_state.attributes.brightness }}'
  action:
1 Like

Doesn’t that also perform the action when the lights turn off?
And it’s possible the state doesn’t change, only the attributes. The lights are already on, but only brightness is changing.

Worth reading the state trigger docs:

Triggers when the state of a given entity changes. If only entity_id is given trigger will activate for all state changes, even if only state attributes change

The condition I wrote will cover any change in brightness, which probably will include turning the light on or off. I’ve never tested it though, because I’ve never needed that kind of automation.

Yes, you were right. Thanks!