Script: wait while the brightness of bulb not equal the saved led brightness

Process of script:

  1. At the beginning of script I saved the brightness of an Ikea bulb brightness (if the bulb is off, the brightness is 0):
service: input_number.set_value
target:
  entity_id: input_number.fsz_livingroom_led_1_brightness
data:
  value: |
    {{ state_attr('light.livingroom_led_1','brightness') | int(0) }}
  1. Flashes the bulb.

  2. Resetting the saved led brightness:

service: light.turn_on
target:
  entity_id: light.livingroom_led_1','brightness
data:
  brightness: '{{ states(''input_number.fsz_livingroom_led_1_brightness'') | int }}'

Another script check the state of this script (run or not), but unfortunately the running of the script stopped before the bulb would reach its final state.

So the last step would be to wait until the bulb is in the saved state.

How can this be achieved, including off mode?

A better option, and the reason it exists - is to use the scene snapshot.

action:
  - service: scene.create
    data:
      scene_id: sc_before_flash
      snapshot_entities:
        - light.livingroom_led_1

then do anything else you want to do, change it’s colour, flash it, change it’s brightness whatever.
At the end of the script, restore it’s saved state:

  - service: scene.turn_on
    target:
      entity_id: scene.sc_before_flash

If the light was off before you started, it will now be off again.

Yes, I use creat.scene and scene.turn_on where the light is controlled by ZigBee relay.
I tried this method at normal ikea ZigBee bulbs.
Unfortunately, this process doesn’t work too. After the state of scene changes to off, the light state changes 3 times more, therefore the monitoring script doesn’t work properly (it monitorings the state of the first script).