Servo lock push button?

Trying to make a simple servo lock with a trigger button using esphome.
Using the code below I can turn on and off the lock from HA but the button on esphome only turns the lock on. Its not acting like a push button switch???
Im still a beginner with yaml code but I tried copying from others and docs and this is what I came up with. I was actually surprised nobody tried doing this already.

esphome:
  name: front_door_lock_servo
  platform: ESP8266
  board: nodemcuv2

wifi:
  ssid: "*"
  password: ""

# Enable logging
logger:

# Enable Home Assistant API
api:

ota:

# Example configuration entry
servo:
  - id: my_servo
    output: pwm_output

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

switch:
  - platform: template
    icon: "mdi:lock"
    name: "Front Door Lock"
    id: ser
    turn_on_action:
    - servo.write:
            id: my_servo
            level: 100.0%
    turn_off_action:
    - servo.write:
            id: my_servo
            level: -0.0% 

binary_sensor:
  - platform: gpio
    pin:
      number: D0
      mode: INPUT_PULLUP
      inverted: True
    name: "on off"
    on_press:
      then:
        - switch.toggle: ser

Try adding a debouncing filter to the button.

Tried it. Didnt help my situation. Is there something wrong with my code?

Did you get this sorted out? I have similar problem with a template switch which won’t toggle state, only turns on every time it’s toggled. Bug?

I never solved this. In fact I stopped working on this project because of this.I thought maybe im doin something wrong with the code.

Try using optimistic: true in your template switch. It doesn’t know its state because nothing is telling it that.