Binary sensor and 5V connected state

How to create a binary sensor that will show the 5V connection to the charger. (state on / off)
I would probably need a wiring diagram and a yaml code. Can you advise?
well thank you

What charger?

I have already solved this by connecting a 2N2222 transistor

emitter - ESP gpio D3
base - usb 5V DC
collector - usb GND

YAML

#POWER SENSOR
binary_sensor:
  - platform: gpio
    pin:
      number: D3
      inverted: true
    name: "${friendly_name} Charger"
    device_class: power
    id: chargerbattery

I hope you’re also using a current limiting resistor on the base, and that USB GND is the same as ESP GND.

Who knows, this thread has been a waste of time because the OP doesn’t give useful information.

1 Like