Help Needed: Sonoff S20 Plugs Restarting Every ~4 Hours After Home Assistant & ESPHome Update

I’m facing a challenging issue with my Sonoff S20 smart plugs, which are operating on ESPHome. These devices were functioning flawlessly until a recent update to my Home Assistant setup.

Background: I decided to completely overhaul my Home Assistant system. In this process, I smoothly migrated my Z-Wave and ESPHome configurations. However, post-update, I’ve been encountering a major problem.

Issue: After updating the firmware on my ESPHome devices, I had to switch from using an API password to an API key. Since making this change, my Sonoff S20 plugs have begun restarting approximately every 4 hours. They default to their ‘off’ state after each restart, which is my preferred setting, but the frequency of these restarts is quite bothersome.

Here are the details of my current setup:

Home Assistant Info:

  • Core: 2024.1.3
  • Supervisor: 2023.12.1
  • Operating System: 11.4
  • Frontend: 20240104.0

ESPHome Info:

  • Version: 2023.12.6

Request for Assistance: I am unsure if the switch to an API key is related to this issue, but it’s a major change that coincides with these problems. Has anyone else experienced similar behavior with their smart plugs or ESPHome devices after an update? Any advice or potential solutions would be greatly appreciated.

Here is one of the plugs configs.

esphome:
  name: sonoff-plug5
  friendly_name: sonoff-plug5

esp8266:
  board: esp01_1m

# Enable logging
logger:

# Enable Home Assistant API
api:
  encryption:
    key: !secret api_key

ota:
  password: !secret ota_pass

wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_pass
  power_save_mode: none
  
binary_sensor:
  - platform: gpio
    pin:
      number: GPIO0
      mode: INPUT_PULLUP
      inverted: True
    name: "Sonoff S20 5 Button"
    on_press:
      - switch.toggle: relay
  - platform: status
    name: "Sonoff S20 5 Status"

switch:
  - platform: gpio
    name: "Sonoff S20 5 Relay"
    pin: GPIO12
    id: relay

output:
# Register the green LED as a dimmable output ....
  - platform: esp8266_pwm
    id: s20_green_led
    pin:
      number: GPIO13
      inverted: True

light:
# ... and then make a light out of it.
  - platform: monochromatic
    name: "Sonoff S20 5 Green LED"
    output: s20_green_led
    
sensor:
  - platform: wifi_signal
    name: "Sonoff S20 5 RSSI"
    update_interval: 30s

I’m eager to find a solution that doesn’t involve rolling back the updates, as the rest of my smart home system is performing optimally with the new versions of Home Assistant and ESPHome.

Thank you very much in advance for your help and insights!

A log from a esphome node should tell us the restart reason. You can also use the debug component to get the last reset reason conveniently into HA.

Other thing worth trying upfront that only takes a minute would be to delete a troublesome esphome node (doesn’t delete any history or anything) and then just add it again to see if it improves …

1 Like

Thanks I’ll get the debug component up and running and report back. Unfortunately I wish it was just one troublesome node. It’s all of the Sonoff S20 plugs, I’ve got 8 of them running ESPHome.

Alright so added in the debug and got the following reason for restart:

[19:18:50][D][debug:076]: ESPHome version 2023.12.8
[19:18:50][D][debug:080]: Free Heap Size: 20272 bytes
[19:18:50][D][debug:108]: Flash Chip: Size=1024kB Speed=40MHz Mode=DOUT
[19:18:50][D][debug:323]: Chip ID: 0x00A4BCDA
[19:18:50][D][debug:324]: SDK Version: 2.2.2-dev(38a443e)
[19:18:50][D][debug:325]: Core Version: 3.0.2
[19:18:50][D][debug:326]: Boot Version=31 Mode=1
[19:18:50][D][debug:327]: CPU Frequency: 80
[19:18:50][D][debug:328]: Flash Chip ID=0x0014405E
[19:18:50][D][debug:329]: Reset Reason: Exception
[19:18:50][D][debug:330]: Reset Info: Fatal exception:29 flag:2 (Exception) epc1:0x4000df64 epc2:0x00000000 epc3:0x00000000 excvaddr:0x00000000 depc:0x00000000
[19:18:50][D][text_sensor:064]: 'Device Info': Sending state '2023.12.8|Flash: 1024kB Speed:40MHz Mode:DOUT|Chip: 0x00a4bcda|SDK: 2.2.2-dev(38a443e)|Core: 3.0.2|Boot: 31|Mode: 1|CPU: 80|Flash: 0x0014405e|Reset: Exception|Fatal exception:29 flag:2 (Exception) epc1:0x4000df64 epc2:0x00000000 epc3:0x00000000 excvaddr:0'
[19:18:50][D][text_sensor:064]: 'Reset Reason': Sending state 'Exception'
[19:18:54][D][sensor:093]: 'Heap Free': Sending state 23568.00000 B with 0 decimals of accuracy
[19:18:54][D][sensor:093]: 'Heap Max Block': Sending state 16856.00000 B with 0 decimals of accuracy
[19:18:54][D][sensor:093]: 'Heap Fragmentation': Sending state 20.00000 % with 1 decimals of accuracy
[19:18:54][D][sensor:093]: 'Loop Time': Sending state 193.00000 ms with 0 decimals of accuracy
[19:18:56][D][api:102]: Accepted 10.10.30.204
[19:18:56][W][api.connection:091]: : Socket operation failed: BAD_INDICATOR errno=11

Here is the current config with debug settings:

esphome:
  name: sonoff-plug5
  friendly_name: sonoff-plug5

esp8266:
  board: esp01_1m

# Enable logging - Added debug 2024-01-20
logger:
  level: debug

# Enable Home Assistant API
api:
  encryption:
    key: !secret api_key

ota:
  password: !secret ota_pass

wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_pass
  power_save_mode: none
  
binary_sensor:
  - platform: gpio
    pin:
      number: GPIO0
      mode: INPUT_PULLUP
      inverted: True
    name: "Sonoff S20 5 Button"
    on_press:
      - switch.toggle: relay
  - platform: status
    name: "Sonoff S20 5 Status"

switch:
  - platform: gpio
    name: "Sonoff S20 5 Relay"
    pin: GPIO12
    id: relay

output:
# Register the green LED as a dimmable output ....
  - platform: esp8266_pwm
    id: s20_green_led
    pin:
      number: GPIO13
      inverted: True

light:
# ... and then make a light out of it.
  - platform: monochromatic
    name: "Sonoff S20 5 Green LED"
    output: s20_green_led
    
sensor:
  - platform: wifi_signal
    name: "Sonoff S20 5 RSSI"
    update_interval: 30s
# Added following 2024-01-20 for debugging purposes
  - platform: debug
    free:
      name: "Heap Free"
    fragmentation:
      name: "Heap Fragmentation"
    block:
      name: "Heap Max Block"
    loop_time:
      name: "Loop Time"

text_sensor:
  - platform: debug
    device:
      name: "Device Info"
    reset_reason:
      name: "Reset Reason"

debug:
  update_interval: 5s

Tried commenting everything except the relay and debug from the config of the S20 plug and got the same exception restart. I have been able to find some posts about this being an memory leak type error, but have not found anyway to fix it yet.

Yes, sounds like some fundamental - not user serviceable error indeeed! I suggest open an issue over at the esphome github to properly get this investigated.

Yourself can still try to change the arduino framework version used - maybe you can ship around this error…

I may just jump over to tasmota, I’m doing some testing today.

So the end solution was to dump ESP Home on these Sonoff S20 plugs and go with Tasmota. Everything has been running stable this week with no unplanned restarts. I am a fan of ESP Home and may try switching them back in the future. I’ll post if I find anything on this issue.