From thehookup arduino to esphome / remote pc control and power sense

Am using awesome script created by thehookup for control pc remotely. I have 4 computers all close to each another. I don’t really know how to code using arduino so am trying to rework code to esp home.
the part am struggling with is

void powerSenseCheckIn()
{
  if (pulseIn(powerSensePin, HIGH, 300000) > 100)
  {
      client.publish("state/PC","ON", true);
  }
  else if(digitalRead(powerSensePin) == HIGH)
  {
      client.publish("state/PC","ON", true);
  }
  else
  {
      client.publish("state/PC","OFF", true);
  }
}

am tried using but didn’t work

binary_sensor:
  - platform: gpio
    pin:
      number: D2
      mode: INPUT_PULLDOWN_16
    name: "Computer Power sense"

any input would help a lot. Thanks in advance !

switch:
  - platform: gpio
    pin: D0
    id: relay
  - platform: template
    name: "Power On"
    turn_on_action:
    - switch.turn_on: relay
    - delay: 1000ms
    - switch.turn_off: relay
  - platform: template
    name: "Power Off"
    turn_on_action:
    - switch.turn_on: relay
    - delay: 1000ms
    - switch.turn_off: relay
  - platform: template
    name: "Force power off"
    turn_on_action:
    - switch.turn_on: relay
    - delay: 10000ms
    - switch.turn_off: relay

Power on , off , force switches

And i figure out problem. Problem lays that am using node mcu board and only one pins supports Pulldown D0 . if am using my code with D0 everything fine

Would you mind sharing the whole yaml? I’m going to be building one of these tomorrow, and this would be super helpful