Help with automatiation based on current state of light

Task: configure brightness of yeelight moon lamp by aqara cube.
Now my automatation work so: when i rotate cube right, brightness increased, when i rotate left - brightness decreased.

alias: Aqara Cube Rotate (регулировка света)
trigger:
  - platform: state
    entity_id: sensor.0x158d00051e6ea6_action
    to: rotate
action:
  - service: light.turn_on
    data_template:
      entity_id: light.gostinaia_nightlight
      brightness: >-
        {{ (state_attr('light.gostinaia_nightlight', 'brightness') | int) +
        (state_attr('sensor.0x158d00051e6ea6_action', 'angle') | int) }}
mode: queued
max: 5
max_exceeded: silent

This yeelight lamp has two modes light.gostinaia_nightlight and light.gostinaia. I need tune brightness depending on condition of this lamp. Wheh turn on light.gostinaia, the cube must control only light.gostinaia, instead light.gostinaia_nightlight, and vice versa. Please help to do it.

Please use code formatting / syntax highlighting (grafik) when printing Yaml files and othe sources …