Wemos D1 Mini + 5V relay + 220V AC control, help heeded

Hi All,

I have Wemos D1 Mini I ant to use to control an extractor fan in my bathroom.
Unfortunately, I’m more on a software side and not proficient when it comes down to electronics.

Currently I have 2 problems I don’t know how to resolve properly:

  1. I want to switch on/off a relay to control the fan. I have the following ESPHome code and it works fine
    switch:
    • platform: gpio
      name: “Relay”
      pin: D4

but if I connect the relay to GND and D4, it doesn’t switch if I toggle it on/off via HA fronted (and I think the blue LED is off when I switch it on). It’s just a 5V relay without any board (extracted it from dead Sonoff 5V, works fine even with 3.3V PSU), I connected it directly to the Mini.
What is the right way to connect a relay to Mini?
I tried this relay with a board, but it a strange “Low level trigger” one with 3 pins - GND, VCC and IN. I compiled my esphome code with inverted: true, but it doesn’t help - the relay stays on despite having just 48 mV on the IN pin. It switches off only if I shorten GND and IN, but doesn’t react to HA fronted switch as expected.

  1. I want the Mini to react somehow when there is 220V AC applied to an extra wire I have (it comes from a wall switch). I use ESPHome binary_sensor:
    binary_sensor:
    • platform: gpio
      name: “button”
      pin:
      number: D3 # 18/GPIO0/D3
      inverted: True
      mode: INPUT_PULLUP

It works when I connect D3 to GND.
The question is how schematically to do the same when I have 220V AC?

Any help is greatly appreciated.

Hi,
Did you every get this resolved? I’m troubleshooting d1_mini with similar relay and experiencing same problems.

~Bryan