ESPhome hgowe to program a nodemcu to push an external button?

Hi, I need to push a phisical button with HASS, so I connected a GPIO of a Nodemcu with a 10KOhm to soldered to the board of the button, and it works fine with an Arduino code (I can post it if needed). Now wish to bring all my ESP in the house under ESPHOME umbrella, bnut in this case my code is not working.

Need some help please. I have to recreate a simple button press and a double button press. The single button press will close a lock, the double press will opoen a lock.

The below code works for the single press, but not the double press. What am I doing wrong?

switch:
  - platform: gpio
    pin:
      number: D0
      inverted: yes
    id: relay
  - platform: template
    name: "open_14a_office_door"
    icon: "mdi:gate"
    turn_on_action:
    - switch.turn_on: relay
    - delay: 200ms
    - switch.turn_off: relay
  - platform: template
    name: "close_14a_office_door"
    icon: "mdi:gate"
    turn_on_action:
    - switch.turn_on: relay
    - delay: 200ms
    - switch.turn_off: relay
    - delay: 500ms
    - switch.turn_on: relay
    - delay: 200ms
    - switch.turn_off: relay

Below my full code. Wish to know if I can add something that warns me when the nodemcu goes offline

I solved as below. Now I wish ESPHOME couild have a LOCK entity

esphome:
name: 14b_office_door
platform: ESP8266
board: nodemcuv2

wifi:
  ssid: "xx"
  password: "xx"
  manual_ip:
    static_ip: 192.168.1.189
    gateway: 192.168.1.239
    subnet: 255.255.255.0 
# Enable logging
logger:

# Enable Home Assistant API
api:

ota:


web_server:
  port: 80

switch:
  - platform: gpio
    pin:
      number: D0
      inverted: yes
    id: relay
  - platform: template
    name: "open_14b_office_door"
    icon: "mdi:gate"
    turn_on_action:
    - switch.turn_on: relay
    - delay: 500ms
    - switch.turn_off: relay
  - platform: template
    name: "close_14b_office_door"
    icon: "mdi:gate"
    turn_on_action:
    - switch.turn_on: relay
    - delay: 500ms
    - switch.turn_off: relay
    - delay: 100ms
    - switch.turn_on: relay
    - delay: 500ms
    - switch.turn_off: relay

sensor:
  - platform: wifi_signal
    name: "14b BLE Bridge WiFi Signal"
    update_interval: 60s
  - platform: uptime
    name: "14b BLE Bridge Uptime"

Hi! Could you please share the connection physical layout? I would like to control a light either with nodemcu or a physical button using a relay connected to nodemcu.

Thanks un advance!

Basically a Sonoff Basic, or a Shelly 1, no?
In the cookbook there is the code