Automatic interval update change does not work

Hello,
I want to adjust the interval update of my HC-SR04 ultrasonic sensor as soon as my garage door opens.
My two limit switches should serve as triggers.
As soon as both have the status “on” the update interval should be 125ms, otherwise only 60s.
I created the following script in ESPHome.

However, the “update_interval_slow” always remains active.
I would be very happy to receive suggestions and help

substitutions:
  update_interval_fast: 125ms
  update_interval_slow: 60s

sensor: 
  - platform: ultrasonic
    id: distance_sensor
    trigger_pin: GPIO5
    echo_pin: GPIO4
    name: "Ultrasonic_Sensor"
    update_interval: ${update_interval_slow}
    internal: true
    timeout: 2.5m
    accuracy_decimals: 2
    unit_of_measurement: 'm'
    # filters:
    filters:
      - lambda: return x;
      - filter_out: nan
      - median:
          window_size: 5
          send_every: 5
          send_first_at: 1
      - calibrate_linear: 
        - 0.0 -> 2.0
        - 2.0 -> 0.0
    # zeigt im Dashboard den Status des Garagentor Öffnungsgrads in %
  - platform: template
    id: level
    name: Status_Garagentor
    update_interval: ${update_interval_slow}
    unit_of_measurement: '%'
    lambda: |-
      auto r = (id(distance_sensor).state) * 50 ;
      if (r > 99) return 100;
      if (r < 0.3) return 0;
      return r;
      
binary_sensor:
  - platform: homeassistant
    name: "Tor auf"
    id: sensor_oben
    entity_id: input_sensor.garagentor_sensor_auf_window
    internal: true  

  - platform: homeassistant
    name: "Tor ZU"
    id: sensor_unten
    entity_id: input_sensor.shelly_garage_magnetschalter_switch_100_input
    internal: true     

interval:
  - interval: ${update_interval_fast}
    then:
      - if:
         condition:
          - lambda: 'return id(sensor_oben).state;'
          - lambda: 'return id(sensor_unten).state;'
         then:
            - component.update: distance_sensor
            - component.update: level 

A good resource for ESPHome questions is the ESPHome Discord.

Indentation for condition: is incorrect.

So what you get on your logs from interval component when your suspected conditions trigger?

What are you trying to accomplish with this setup? Maybe there are better ways…

Here is how I make dynamic update intervals or you could do dynamic delays etc.

esphome:
  name: dynamic_update_interval
  on_boot: 
    priority: -100
    then:
      - logger.log: "Setting Update Interval"
      - component.resume: 
          id: bright
          update_interval: !lambda |-
            int time = id(update_delay).state*1000;
            return time;
      - component.update: 
          id: bright


time: 
  - platform: homeassistant
    id: homeassistant_time

sensor:
  - platform: adc
    pin: 17
    name: "Bedroom Brightness"
    unit_of_measurement: lux
    id: bright    
    filters:
      - lambda: |-
          return (x / 10000.0) * 20000000.0;    
    update_interval: 10s

number:
  - platform: template
    id: update_delay
    name: "Dynamic Update Interval"
    max_value: 9000
    min_value: 5
    initial_value: "5"
    unit_of_measurement: " Seconds"
    step: 1
    optimistic: True
    mode: box
    on_value: 
      then:
        - component.resume:
            id: bright
            update_interval: !lambda |-
              int time = id(update_delay).state*1000;
              return time;