I what a senor that tells me if door is open/ closed

i need some help in my code above i want it to show state. If the door is open closed i can see the state now, but its not changing, i just get :Entity not available: binary_sensor.gate_open_sensor

I am not good a coding at all, how can if creat that?

Regard


api:
  encryption:
    key: "LSZ50fLgaQpUXh0hlvTGhKhMHxalgyAc6R/rYst+oaY="
  services:
    - service: control_servos
      variables:
        level: float
      then:
        - servo.write:
            id: servo_right
            level: !lambda 'return level / 100.0;'
        
        - servo.write:
            id: servo_left
            level: !lambda 'return level / -100.0;'
            


ota:
  password: "!secret esp_api_pass"

# Sync time with Home Assistant.
time:
  - platform: homeassistant
    id: homeassistant_time
    
globals:
  - id: garage_door
    type: bool
    restore_value: false
    initial_value: 'false'

binary_sensor:
  - platform: gpio
    pin: D8
    name: "Gate open sensor"
    device_class: opening
    on_press:
      - switch.turn_off: control_servos_switch
    on_release:
      - switch.turn_on: control_servos_switch

switch:
  - platform: template
    name: "Control both servos"
    id: control_servos_switch
    restore_state: false

    turn_on_action:
      - servo.write:
         id: servo_right
         level: 100%
      - servo.write:
         id: servo_left
         level: -100%
      - globals.set:
          id: garage_door
          value: 'true'
      
    turn_off_action:
      - servo.write:
         id: servo_right
         level: -10%
      - servo.write:
         id: servo_left
         level: 10%
      - globals.set:
          id: garage_door
          value: 'false'
    lambda: |-
      return id(garage_door);

servo:
  - id: servo_right
    output: pwm_output_right
    restore: true

  - id: servo_left
    output: pwm_output_left
    restore: true


output:
  - platform: esp8266_pwm
    id: pwm_output_right
    pin: D4
    frequency: 50 Hz

  - platform: esp8266_pwm
    id: pwm_output_left
    pin: D3
    frequency: 50 Hz

i need some help in my code above i want it to show state. If the door is open closed i can see the state now, but its not changing, i just get :Entity not available: binary_sensor.gate_open_sensor

I am not good a coding at all, how can if creat that?

Regard