Help with Complex Motion Sensor Automation

- conditions:
          - condition: trigger
            id: movement in bedroom
        sequence:
          - service: timer.cancel
            data: {}
            target:
              entity_id: timer.light_timer
          - service: timer.cancel
            data: {}
            target:
              entity_id: timer.light_timer_2
          - service: light.turn_on
            data:
              brightness_pct: 100
            target:
              device_id: 448dbb6c28ee71252cc037a4eddede35
      - conditions:
          - condition: trigger
            id: timer finished
        sequence:
          - service: light.turn_on
            data:
              brightness_pct: 50
            target:
              device_id: 448dbb6c28ee71252cc037a4eddede35

I have code like that above but instead of hardcoded value of 100% and 50% I want yo use value stored in input_number.bedroom_lights_brigtness and half of that value.

So before the lights is dimmed I need to read brightness of that light, sotre into helper and dim it to half of that brightness.
When motion is detected I need to restore brightness to the value stored in that helper.

Hi Martin,

I haven’t used it myself as I have hardcodwd values but there is a service called: scene: create. It’s function is to create a temporary scene with the brightness/color of your light.

If you use this, just before the lights will dim, you can then re-apply it to restore the original brightness.

Please give it a try in the developer tools to understand how it works. Then you can apply it in your automation via a call service

Thanks.
I was reading about this service, but if I understand it correctly, it might help me to restore lights to the state before dimming.

But still I need to read actuall brightness of the lights so I can calculate half of it and set brightness to that calculated value.

EDIT: I am slowly getting there, this is the proper syntax to set brighness to the value of input helper

data:
  brightness_pct: "{{ states('input_number.bedroom_lights_brigtness') | int }}"

And this is how to set input value to actuall brightness

- service: input_number.set_value
  data:
    value: >-
      {{ (states.light.bedroom.attributes.brightness/255*100)|round(0) }}
    target:
      entity_id: input_number.bedroom_lights_brigtness

Only thing left to figure out is how to store the initial brightness before the automation even starts, otherwise on motion it will restore light to brightness level stored in the helper on previous run.

One solution could be to run separate trigger every time brightness of those lights changes that will store actuall brightness into input helper. But this will also rewrite my stored value even when the brightness is changed within the original automation.

Any idea how to overcome this?