Please help on lambda function

I have the following code on my esphome yaml file:

globals:
   - id: servo_level
     type: float
     restore_value: no
     initial_value: '0'

api:
  services:
    - service: control_servo
      variables:
        level: float
      then:
        - servo.write:
            id: blind_1_servo
            level: !lambda 'return level / 100.0;'
        - lambda: 'id(servo_level) = level;'    
        - delay: 1000ms
        - servo.detach: blind_1_servo   
sensor:
  - platform: template
    name: "${devicename_friendly} Servo Value"
    update_interval: 60s
    lambda: |- 
      return servo_level; 
       

I am getting the following error:

src/main.cpp:304:14: error: could not convert ‘servo_level’ from ‘esphome::globals::GlobalsComponent*’ to ‘esphome::optional’

Thanks for your help!

I solved this by changing the code as follows:

api:
  services:
    - service: control_servo
      variables:
        level: float
      then:
        - servo.write:
            id: blind_1_servo
            level: !lambda 'return level / 100.0;'
        
        - lambda: 'id(servo_value).publish_state(level);'
        - delay: 1000ms
        - servo.detach: blind_1_servo   

sensor:
  
  - platform: template
    name: "${devicename_friendly} Servo Value"
    id: servo_value
    update_interval: 60s