Yeelight bulb unavailable when dimming

Hi

I’m using a STYRBAR remote to control a Yeelight bulb with Zigbee2Mqtt and this blueprint: Controller - IKEA E2001/E2002 STYRBAR Remote control | Awesome HA Blueprints

The problem I was having is that the bulb throttles requests at very low rate, so things like the long press up and down, change the brightness by a few percent, then the bulb goes offline briefly.

So I created 2 scripts one for up and one for down that I can reuse in my blueprint

alias: Yeelight Dimmer Up
mode: single
icon: mdi:lightbulb-on-50
sequence:
  - variables:
      counter: 0
  - repeat:
      while:
        - condition: template
          value_template: "{{ counter < 10 }}"
      sequence:
        - service: light.turn_on
          metadata: {}
          data:
            brightness_step_pct: 10
            transition: 1
          target:
            entity_id: "{{ entity_id }}"
        - delay:
            seconds: 1
        - variables:
            counter: "{{ counter + 1 }}"
alias: Yeelight Dimmer Down
mode: single
icon: mdi:lightbulb-on-50
sequence:
  - variables:
      counter: 0
  - repeat:
      while:
        - condition: template
          value_template: "{{ counter < 10 }}"
      sequence:
        - service: light.turn_on
          metadata: {}
          data:
            brightness_step_pct: -10
            transition: 1
          target:
            entity_id: "{{ entity_id }}"
        - delay:
            seconds: 1
        - variables:
            counter: "{{ counter + 1 }}"

I then call it from on the long press like the up is as below

service: script.turn_on
data:
  variables:
    entity_id: light.breakfast_bar_lamp
target:
  entity_id: script.yeelight_dimmer_up

And then the up release

service: script.turn_off
data:
  variables:
    entity_id: light.breakfast_bar_lamp
target:
  entity_id: script.yeelight_dimmer_up

(I do the same for the down button calling the yeelight_dimmer_down script)

However the result is my light carries on increasing or decreasing to 100% or 0%

Even weirder still, is that if I long press up, release, long press down, release my light just flashes on and off in a strange rhythmic pulse.

Can anyone help me out of this funk?

Cheers

Andy

This seems to do the trick

alias: Yeelight Dimmer Up
mode: single
icon: mdi:lightbulb-on-50
fields:
  entitiy_id:
    name: entitiy_id
    description: The entity ID of your bulb
    example: light.your_light
    required: true
  button_state:
    name: button_state
    description: The entity ID of the input_text helper for your button state
    example: input_text.your_button_state
    required: true
sequence:
  - variables:
      counter: 0
  - repeat:
      while:
        - condition: template
          value_template: "{{ counter < 10 and 'brightness_move_up' in states(button_state) }}"
      sequence:
        - service: light.turn_on
          metadata: {}
          data:
            brightness_step_pct: 10
            transition: 1
          target:
            entity_id: "{{ entity_id }}"
        - delay:
            seconds: 1
        - variables:
            counter: "{{ counter + 1 }}"