Dimming an LED... a new attempt

Could someone please help me out of this mess???

output:
  - platform: esp8266_pwm
    id: output_esp8266_pwm_1
    pin: GPIO15

light:
  - platform: monochromatic
    name: Monochromatic Light
    id: light_monochromatic_1
    output: output_esp8266_pwm_1

        #Rotary 1 LED1
sensor:
  - platform: rotary_encoder
    name: Rotary Encoder Sensor 1
    id: sensor_rotary_encoder_1
    pin_a:
      number: GPIO12
      inverted: true
      mode:
        input: true
        pullup: true
    pin_b:
      number: GPIO13
      inverted: true
      mode:
        input: true
        pullup: true
    on_clockwise:
      - then:
          - logger.log: clockwise
          - light.dim_relative:
              id: light_monochromatic_1
              relative_brightness: +5%
          - globals.set:
              id: dimmer1
              value: dimmer1 + 5

    on_anticlockwise:
      - then:
          - logger.log: anticklockwise
          - light.dim_relative:
              id: light_monochromatic_1
              relative_brightness: -5%
          - globals.set:
              id: dimmer1
              value: dimmer1 - 5
          
globals:
  - id: dimmer1
    type: int

I think i ran into the woods and could’nt find out…
Turning the rotary should increase/ decrease the value of the variable and set the Light Level (LED).
First step of my first project…
The other attempts can be seen via my Profile

Thanks and have a nice sunday

So what happens (and what doesn’t)? What you get on esphome logs?

Had to kick off globals.set but then it works.

[21:27:56.975][D][main:530]: clockwise
[21:27:56.975][V][light:082]: 'Monochromatic Light' Setting:
[21:27:56.978][V][light:095]:   State: ON
[21:27:56.979][V][light:070]:   Brightness: 5%
[21:27:56.979][V][light:133]:   Transition length: 1.0s
[21:27:56.992][V][sensor:077]: 'Rotary Encoder Sensor 1': Received new state 1.000000
[21:27:56.992][V][sensor:125]: 'Rotary Encoder Sensor 1' >> 1 steps
[21:27:58.567][D][main:530]: clockwise
[21:27:58.567][V][light:082]: 'Monochromatic Light' Setting:
[21:27:58.567][V][light:070]:   Brightness: 10%
[21:27:58.588][V][light:133]:   Transition length: 1.0s
[21:27:58.589][V][sensor:077]: 'Rotary Encoder Sensor 1': Received new state 2.000000
[21:27:58.589][V][sensor:125]: 'Rotary Encoder Sensor 1' >> 2 steps
[21:28:00.044][D][main:540]: anticklockwise
[21:28:00.045][V][light:082]: 'Monochromatic Light' Setting:
[21:28:00.045][V][light:070]:   Brightness: 5%
[21:28:00.055][V][light:133]:   Transition length: 1.0s
[21:28:00.055][V][sensor:077]: 'Rotary Encoder Sensor 1': Received new state 1.000000
[21:28:00.056][V][sensor:125]: 'Rotary Encoder Sensor 1' >> 1 steps
[21:28:01.070][D][main:540]: anticklockwise
[21:28:01.070][V][light:082]: 'Monochromatic Light' Setting:
[21:28:01.070][V][light:095]:   State: OFF
[21:28:01.096][V][light:070]:   Brightness: 0%
[21:28:01.096][V][light:133]:   Transition length: 1.0s
[21:28:01.096][V][sensor:077]: 'Rotary Encoder Sensor 1': Received new state 0.000000
[21:28:01.101][V][sensor:125]: 'Rotary Encoder Sensor 1' >> 0 steps

The Brightness increases and decreases but how do i store the value because i need to switch the light on and off via the push button and restore the previous brightness.

Afaik light should retain the brightness between on and off.
Do you mean you cut power of the Esp?