ESP-01 Relay board configuration

In case anyone struggles with the ESP-01 based relays like I did, here’s the configuration I found to be successful.

Here’s the item:
esp01

First, if you have a problem flashing these, check out my other post about that:
Flashing ESP-01 - Permission Error 13

I decided to post this final form as I feel like even though there’s a lot of information out there, for me it was very hard to find since I didn’t know what to look for (i.e. baud rate).

Here’s the working configuration:

esphome:
  name: boiler
  platform: ESP8266
  board: esp01_1m

wifi:
  ssid: "xxxxx"
  password: "xxxxx"

  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "xxxxx"
    password: "xxxxx"

captive_portal:

# Enable logging
logger:
  hardware_uart: UART1

# Enable Home Assistant API
api:
  password: "password"

ota:
  password: "password"

web_server:
  port: 80

uart:
  baud_rate: 9600
  tx_pin: GPIO1
  rx_pin: GPIO3

switch:
  - platform: gpio
    name: "Boiler relay"
    id: "relay"

    pin: GPIO4 # using ESP module LED
    inverted: false
    on_turn_on:
      - uart.write: [0x0a0, 0x01, 0x01,0x0a2]
    on_turn_off:
      - uart.write: [0x0a0, 0x01, 0x00,0x0a1]
4 Likes

Oh thanks, this helps a lot! Resale site did mention baud rate but now I understand the use!

1 Like

Oh much thanks! I was so naive to guess that the relay is controlled by low/high voltage from GPIO0/2. Then I realized it has a STC15F104-SOP8 MCU on the board.

In case if anyone needs the diagram of the board

2 Likes

Hello,
I tried to use the configuration in above. But it is still the relay not responding to the switch and the LED on the board continuously blinking.
Do you know what is the root cause of the issue?

Oh wow, thank you!
Maybe now I’ll fix my broken one :slight_smile:

Sorry for bumping, but for mine the MCU’s factory flashed code on mine seems broken and all it does is twitching the relay (and the red LED onboard) repeatedly after powering up. I did the following to have the ESP-01S control it directly, in case anyone want that:

  1. Remove the MCU
  2. Bridge the number 6 and 7 pin of the MCU solder pad
  3. Swap R3 and R4 (the 3.3V output by ESP-01S is not enough to drive the transistor fully on with 10K in series and 4.7K to ground, but it works fine if 4.7K in series and 10K to ground instead, so swapping is the simplest solution without needing any more SMD resistors)

Looks like this after modding:

Then you just disable the serial port in ESPHome config, and control the relay using GPIO3 (U0RXD).

logger:
  baud_rate: 0

switch:
  - platform: gpio
    id: relay
    pin: GPIO3

Mine is also like this, I didn’t really found any solution so I ripped the MCU off