One brightness scale for 2 lights with different brightneses

Hi,
How to make set_level field in template light with brightness scale, what will set brightness for one lamp, if it less 128 and for another lamp, if is more 128? I try to do something this:

set_level:
  service: light.turn_on
  data_template:
  entity_id: >
    {% if brightness > 127 %}
      light.first_lamp
    {% else %}
      light.second_lamp
    {% endif %}
  brightness: >
    {% if brightness > 127 %}
       "{{ (1 + (brightness - 128) * 254 / 127) | int }}"
    {% else %}
       "{{ (1 + (brightness - 1) * 254 / 126) | int }}"
    {% endif %}

but it is not works. I want combine 3 different entities of Yeelight ceiling lamp (light, nightlight and ambilight) to one RGBWW template light. Help me please!