ADC driving the PWM - solved

Dears,

I am getting a bit crazy: I connected phototransistor to GPIO39 (ESP32) and it works - I can see values in HA from 0 to 4095:

  - platform: adc
    pin: 39
    name: $hostname light
    id: light_sensor
    unit_of_measurement: ""
    device_class: ""
    update_interval: 3s
    attenuation: 11db
    raw: true
    accuracy_decimals: 0

then I connected LED to GPIO25 and I want to control it via PWM:

output:
  - platform: ledc
    pin: GPIO25
    id: green_pin
    frequency: "19531Hz"

But now, since my ADC returns values 0 to 4095 and my PWM expects 0 to 4095 I need to say something like this inside ADC:

    on_raw_value:
      then:
       - output.set_level:
          id: green_pin
          level: 10%

my problem is: instead of hardcoded level 10% I want “level: get_value_from_ADC”
I think I am missing small bit here but I am stuck here - would you help me please?

thx

I think I found it:

    raw: true
    accuracy_decimals: 0
    on_raw_value:
      then:
      - output.set_level:
          id: green_pin
          level: !lambda "return (x/4095);"