ESPHome Relay (ESP01) issue

Hello,

I’ve been using these relays for a long time without issues but for some reason they stop to work with the latest versions of ESPHome.

Working version: 2023.10.6
Tested versions not working: 2023.12.9 and 2024.2.1 (latest)

As soon is flashed and after reboot, the device no longer connect to the network.

Here is the yaml of my lab unit:

esphome:
  name: relaytests
  friendly_name: 5V Test Relay

esp8266:
  board: esp01_1m

# Enable logging
logger:

# Enable Home Assistant API
api:
#  encryption:
#    key: "1ANVsBGqK0tS4tzZp3A+9O+imxnsUpt4VlkzL0vEwPY="

ota:
  password: "8913647f894e957b22a1214251fbf791"

wifi:
  domain: .lan
  ssid: !secret wifi_ssid
  password: !secret wifi_password

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

captive_portal:

# Enable Web server.
web_server:
  port: 80

# Sync time with Home Assistant.
time:
  - platform: homeassistant
    id: homeassistant_time

# Sensors with general information.
sensor:
  # Uptime sensor used in the following formatted uptime sensor
  - platform: uptime
    name: Uptime
    id: relay_tests_uptime
#    internal: true
    update_interval: 600s

  # WiFi Signal sensor.
  - platform: wifi_signal
    name: WiFi Signal
    update_interval: 600s

# Text sensors with general information.
text_sensor:
  # Expose ESPHome version as sensor.
  - platform: version
    name: FW Version

binary_sensor:
 - platform: status
   name: "Status"

# Exposed switches.
switch:
  # Switch to restart the  relay.
  - platform: restart
    name: Restart

  # Switch to turn on/off the relay.
  - platform: gpio
    id: relay
    name: ""
    pin:
     number: 0
     inverted: true
        

Thank you very much.

Did you go look to see if this is a known issue and been reported already? Sometimes you can find older threads where someone else had this issue after updating and the solution is in the thread. Did you look at the changelog prior to updating to see if there were any breaking changes listed that might effect you?

Its not connecting to the network, so what is the reason it gave you in the logs? Also you do realize these have a small amount of memory and of you keep applying updates that do absolutely nothing for that board who just sits there and toggles 1 relay, you’re going to quickly run into not enough memory issues. Dont apply updates that you dont need.

Other than the problem your having and posting your config, what have you tried already? Where have you looked for answers?

Yes, I’ve search I didn’t found nothing reported. Also looked to the changes on the ESPhome releases and didn’t spot nothing but there a lot of changes which I assume that don’t know exactly what they mean or if can be related.
The code is available here:

As you said, this is a very basic code that enable one gpio pin to switch a relay so maybe it is not hard for an expert find the problem.
Last, since the ESP01 doesn’t connect to the network I don’t see any logs after the update. I can try remove some parts of the code and check if the ESP01 stops the bricking stage.

I understand it’s not connected and therefore there is no log output. What does the log output say when you try to flash the board again?

are you able to access the board from any method? Does it show up in your router? can you access it via web_server? What makes you sure it’s a wifi/api problem and not a hardware malfunction? Hook that sucker up to your pc and open a serial log

I have seen other threads about those last 2 versions (2023.12.x and 2024.2.x) having similar problems. So there are other threads.

I’ve searched and so far didn’t found nothing that can fix thr problem. On these devices I’ll stay with the 2023.10.6 for now.

You could try to remove the webportal component from your YAML, the webportal is using a lot of memory.

Do mean the flash memory or ram memory? Beacuse i don’t see any increase on the bin file when compiling with the latest version.

So your able to flash it successfully? So what part isnt working?

Perhaps he serial flashed.

I guess… idk, im kind of worn out playing guessing games.

If he serial flashed then he should be able to collect logs via serial for it, which would give a lot more information about what’s going on.

1 Like

@Joao-Sousa-71 How did you flash the ESP?

To clarify. When it was working with (2023.10.6) I’ve flash through ESPHOM (and using the browser) also flash. As soon it is flashed with the new version it bricks. To recovery the ESP-01 I have use espflasher (usb -serial) but with the later versions the logs do not show nothing like the ESP doesn’t boot. If I flash with the older version then it starts to work again. I also test with another ESP01s and I have the same behavior.

You can use ESPHome Flasher or Balena Etcher to flash the ESP. I’ve never been able to flash using the browser to ESPHome.

To test your ESP, use Arduino to flash espblink found in the example sketches.

The ESPs are ok and they work flawlessly with the version 2023.10.6 and previous. The first time that I’ve to flash them I use ESPHome-flasher with ftdi usb uart adapter. As long the firmware is bellow 500k then can be flashed OTA either using the ESPhome dashboard or through the webpage or the device.
When something goes wrong then the usb adapter jumps again. I’m almost sure there is a bug in the later versions of ESPhome but since the ESP seem do not boot I’m struggling to provide any logs to evidence the issue.

Try a simple yaml file. No sensors or switches.

Also, remove domain: .lan

I haven’t ever seen anyone use the domain key, and I wonder if your router is having an issue resolving homeassistant.lan.

I have the same thingie. This compiles:

# https://devices.esphome.io/devices/ESP-01S-1-channel-relay
# https://templates.blakadder.com/ESP-01S-Relay-v5.html
substitutions:
  friendly_name: 'Relay'
  device_name: 'relay'
  project_base: 'ESP'
  project_name: '01S'
  project_version: '1-c'
  device_description: 'ESP-01S 5V 1-channel relay' # https://www.aliexpress.com/item/10000360282300.html

# ESP8266 5V WiFi relay
# The relay has COM+NO+NC exposed.
# Working voltage: DC 5V
# Relay Load: 10A 250VAC 10A 125VAC 10A 30VDC 10A 28VDC.
# Load: 10A/250VAC 10A/30VDC, the relay pull 100,000 times

# PINS: 0, 1, 2, 3

esphome:
  name: $device_name
  friendly_name: $friendly_name
  comment: $device_description
  project:
    name: ${project_base}.${project_name}
    version: $project_version

esp8266:
  board: esp01_1m

packages:
  device_base: !include common/device.base.yaml

logger:
  baud_rate: 0 # because led is pin 2

#   binary_sensor:
#     - platform: gpio
#       pin:
#         number: 3
#   #      inverted: true
#       id: ${device_name}_button
#       name: None
#       device_class: power
#       on_multi_click:
#       - timing: !include common/click/single.yaml
#         then:
#           - switch.toggle: ${device_name}_relay
#       - timing: !include common/click/hold-5.yaml
#         then:
#           - switch.toggle: ${device_name}_inching
#       - timing: !include common/click/hold-10.yaml
#         then:
#           - lambda: |-
#               ESP_LOGW("button", "restart");        
#           - button.press: ${device_name}_restart
#   #    entity_category: diagnostic    
#   #    on_press: 
#   #      - switch.toggle: ${device_name}_relay

switch:
  - platform: template
    name: Inching
    id: ${device_name}_inching
    icon: mdi:pipe
    entity_category: config
    restore_mode: ALWAYS_OFF
    turn_on_action:
      then:
        - light.turn_on:
            id: ${device_name}_led
            effect: Inching
    turn_off_action:
      then:
        - light.turn_off: ${device_name}_led

  - platform: gpio
    name: None
    id: ${device_name}_relay
    icon: mdi:electric-switch
    pin: 
      number: 0 # GPIO0
      inverted: true
    restore_mode: ALWAYS_OFF
    on_turn_on:
      - if:
          condition:
            switch.is_off: ${device_name}_inching
          then:
            - lambda: |-
                ESP_LOGD("switch", "keep");
          else:
            - lambda: |-
                ESP_LOGD("switch", "inching");            
            - delay: !lambda "return id(${device_name}_delay).state * 1000;" # milliseconds
            - switch.turn_off: ${device_name}_relay

number:
  - platform: template
    id: ${device_name}_delay
    name: Inching time
    icon: mdi:timer-stop-outline
    entity_category: config
    unit_of_measurement: s
    mode: auto
    optimistic: true
    restore_value: true
    min_value: 0.5
    max_value: 10
    step: 0.5
    initial_value: 1

output: 
  - platform: esp8266_pwm
    pin: 
      number: 2
      inverted: true
    id: ${device_name}_light_output

light:
  - platform: monochromatic #status_led
    output: ${device_name}_light_output
    name: Led
    id: ${device_name}_led
#    pin: 
#      number: 2
#      inverted: true    
    entity_category: diagnostic
    icon: mdi:led-outline
    disabled_by_default: true
    effects:    
      - pulse:      
      - pulse:
          name: Fast
          transition_length: 0.5s
          update_interval: 0.5s          

edit:

@Joao-Sousa-71 yes, it uploads as well.

I added this as well just in case, because using unsafe pins:

esp8266:
  board: esp01_1m
  restore_from_flash: false
  early_pin_init: false # Specifies whether pins should be initialised as early as possible to known values. Recommended value is false where switches are involved, as these will toggle when updating the firmware or when restarting the device. Defaults to true.
  framework:
    version: latest
1 Like

Then now you see someone :grin:

I use it; i find mDNS too unreliable, so i use my own domain internally (which happens to be the same as my external domain) works like a charm (i can access all my esp devices with devicename.domain.mine)

1 Like