Template light 'level_template' is not re-evaluated after 'set_level' is invoked


Here’s what I’m trying to achieve. I have a light fixture with three dumb bulbs connected to two zigbee relays (one relay has one bulb connected and the other has two in parallel). I’m trying to implement a light template that takes the two light entities corresponding to the relays and creates a dimmable light using a template that, depending on the brightness, switches on the first, then the second and finally both relays.

I couldn’t find any example so I set out to implement this myself and ended up with the following implementation, which for the most part works:

  - platform: template
        friendly_name: "LivingRoom"
        value_template: "{{ [states('light.livingroom1'),states('light.livingroom2')]|select('equalto','on')|first|default('off') }}"
        level_template: >
          {% if is_state('light.livingroom1','on') %}
            {% if is_state('light.livingroom2','on') %}
          {%elif is_state('light.livingroom2','on') %}
          service: light.turn_on
            entity_id: light.livingroom1,light.livingroom2
          service: light.turn_off
            entity_id: light.livingroom1,light.livingroom2
          - service: light.turn_{{'on' if brightness>0 and (brightness<=85 or brightness>170) else 'off'}}
              entity_id: light.livingroom1
          - service: light.turn_{{'on' if brightness>85 else 'off'}}
              entity_id: light.livingroom2

The problem that I have is that whenever I move the brightness slider in such a way that doesn’t trigger a state change in any of the lights, let’s say from 100% to 80%, which is both equivalent to all lights on, the sliders stays at 80% instead of springing back to 100%. In contrast, if I move it from 100% to 50%, it would switch off the one bulb and slider springs to 66%.

I also tried an experiment with the value_template and turn_on/turn_off templates. If I implement let’s say turn_off in such a way that it doesn’t change the current state of entities referenced in the value_template, what happens when I toggle the light in the UI is it toggles initially, but after a second or so, springs back to the initial(unchanged) state. This is the behavior I would expect from the brightness slider.

My question: Do you think I’ve implemented this correctly? Is there a way to work around or should I maybe open an issue in github?

@triffonovm Did you solve your problem? I have exactly the same setup, and cannot figure out how to make it work.