Sonoff Basic with reed switch

Hello community!
Can you please help me with ESPhome built-in automation on Sonoff Basic with reed switch.

The goal is next:
I have a closet, there is a reed switch on the door. When the door opens, the light turns on, when it closes, it turns off accordingly (this was already implemented on Tasmota)
I also have a cat that can open doors, but haven’t learned how to close doors yet:(, so it is advisable that the light turns off if the door is open for more than i.e. 5 minutes.
I tried many options, nothing worked, I broke my head.
Hope for your help, THANKS!

We can’t help you without seeing your esphome config. Correctly formatted as in point 11 here.

here is code. reed switch connected to gpio3

esphome:
  name: shkaf-r
  platform: ESP8266
  board: esp8285

# Enable logging
logger:

# Enable Home Assistant API
api:

ota:
  password: "709ddaaac7b7cea91adac4e0836210cb"

wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_password

  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "Shkaf-R Fallback Hotspot"
    password: "KrDIzD4Q5RLQ"

captive_portal:

binary_sensor:
  - platform: gpio
    pin:
      number: GPIO3
      mode: INPUT_PULLUP
      inverted: false
    name: "Шкаф Правая"
    id: sensor_shkaf_r
    device_class: door

output:
  - platform: gpio
    pin: GPIO12
    id: relay_1
        
light:
  - platform: binary
    name: "Шкаф Правая"
    output: relay_1
    id: light_shkaf_r
    
status_led:
  pin:
    number: GPIO13
    inverted: yes

Try this:

binary_sensor:
  - platform: gpio
    pin:
      number: GPIO3
      mode: INPUT_PULLUP
      inverted: false
    name: "Шкаф Правая"
    id: sensor_shkaf_r
    device_class: door
    on_press:
      then:
        - light.turn_on: light_shkaf_r
        - delay: 300s
        - light.turn_off: light_shkaf_r
    on_release:
      then:
        - light.turn_off: light_shkaf_r

Relay constantly clicking when the door is open

Your binary sensor could be picking up noise. How long are the cables to the reed switch?

30cm, on tasmota it works flawlessly.

Guys, no ideas how to realise that on esphome?
here is working one sample on tasmota

Found solution, main thing is delay in filter settings.
Maybe it will be useful to someone

esphome:
  name: shkaf-l
  platform: ESP8266
  board: esp01_1m

# Enable logging
logger:

# Enable Home Assistant API
api:

ota:
  password: "xxx"

wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_password
  fast_connect: on

  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "Shkaf-L Fallback Hotspot"
    password: "xxxx"

captive_portal:

binary_sensor:
  - platform: gpio
    pin:
      number: GPIO3
      mode: INPUT_PULLUP
      inverted: false
    name: "Шкаф Левая"
    id: sensor_shkaf_l
    device_class: door
    filters:
      - delayed_on_off: 100ms
    on_state:
      then:
        - if:
            condition:
              - binary_sensor.is_on: sensor_shkaf_l
            then:
              - light.turn_on: light_shkaf_l
              - delay: 300s
              - light.turn_off: light_shkaf_l
        - if:
            condition:
              - binary_sensor.is_off: sensor_shkaf_l
            then:
              - light.turn_off: light_shkaf_l

output:
  - platform: gpio
    pin: GPIO12
    id: relay_1
        
light:
  - platform: binary
    name: "Шкаф Левая"
    output: relay_1
    id: light_shkaf_l
    
status_led:
  pin:
    number: GPIO13
    inverted: yes