ESP-01 5v Relay board problems ESPhome

Hey,

I got some booards form aliexpress like in this picuture, they should be ESP-01 and not ESP-01S
ESP8266-01_Wifi_Relay_Module

So to the main topic, i flashed esphome to the board, connected it to wifi, adopted it in esphome and used the following code

esphome:
  name: esphome-web-3faa17
  friendly_name: ESPHome Web 3faa17

esp8266:
  board: esp01_1m

# Enable logging
logger:
  baud_rate: 0

# Enable Home Assistant API
api:
  encryption:
    key: "###"

ota:


wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_password

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

captive_portal:

# Enable logging

web_server:
  port: 80

uart:
  baud_rate: 9600
  tx_pin: GPIO3
  debug:


switch:
  - platform: template
    id: relay1
    name: "relay1 switch"
    turn_on_action:
      - uart.write: [0xA0, 0x01, 0x01, 0xA2]
      - switch.template.publish:
          id: relay1
          state: ON
    turn_off_action:
      - uart.write: [0xA0, 0x01, 0x00, 0xA1]
      - switch.template.publish:
          id: relay1
          state: OFF

The problem is that after toggeling to on the relay switches on and back off affter a short time (not exact every time but around 0.5 to 1 sec), i tried using esp8266:
board: esp01 insted ot esp01_1m but the flash is low and cannot upload via ota, i tried using diffrent GPIO pins but to no success, using diffrent baud_rate dosent work eather, im powering it with 5v as when i use 3.3v it dosent boot (Powering it to the relay board and not the ESP itself).

Also the relay is SRD-05VDC-SL-C and on the relay board has only 4 pins to connect from left to right 5V RX TX GND

Anyone got an idea where the problem can be and how to fix it?

For starters - get rid of this and see if it makes a difference:

web_server:
  port: 80

The ESP may be struggling to run the web server.

See the following warning on the Web Server page:

Please note that enabling this component will take up a lot of memory and may decrease stability, especially on ESP8266.

The ESP-01 has 1mb of flash RAM, the ESP-01S has 4mb. Otherwise they are identical.

See if this post helps.

Today I tryed to remove the web server, but to no new effect, the relay still switches on for an second or so an turns off.

web_server:
  port: 80

The mentioned dost was my main guide, but unfortunatlly it dosent work for me, as for the ESP, i orderd the ESP-01 not the 01S

I don’t know if this will help, but this is my code …

  devicename: cathose
  upper_devicename: Cat Hose
  static_ip: 
  ssid:

esphome:
  name: $devicename

esp8266:
  board: esp01_1m

wifi:
  networks: 
    - ssid: $ssid
      password: !secret wifi_password

  manual_ip:
    static_ip: $static_ip
    gateway:
    subnet:
    dns1:
    dns2:

  ap:
    ssid: $upper_devicename
    password: !secret wifi_password

#  use_address: $devicename.local

web_server:
  port: 80

logger:

api:
  encryption:
    key: 

ota:
  password: !secret ota_password

captive_portal:

switch:
  - platform: gpio
    pin: GPIO0
    name: "${upper_devicename} Relay"
    id: valve
    on_turn_on:
      - delay: 10000ms
      - switch.turn_off: valve

I found the fix, and is as simple as it gets… So I was using an usb to serial adapter to power the relay as am testing it, turns out it dosen’t provide enough power wen the relay is switched on, so that is the reason why it turned off after an second or so, when i used phone charger for power it’s all good. Thank you for your sugesstions.

1 Like