ESP8266 stops working after losing wifi connection

Hello

I have an ESP8266 D1 Wemos mini with a pretty bad wifi connection (-70dB) that controls a simple relay.

An automation in HASSIO controls the ESP8266, after which the code on the ESP8266 holds pin GPIO5 high for 2 minutes so that the relay remains closed for 2 minutes. After 2 minutes the GPIO5 goes low again.

The principle behind this is that when the WiFi connection is lost, the ESP8266 executes the code without further problems. However, the opposite seems to be true, when the WiFi connection is lost, the relay switches back open. The WiFi connection regularly drops after 10 or 30 seconds after the relay is closed. Sometimes not at all.

Question 1:
Is my view correct that the ESP8266 can continue to execute its own code without a WiFi connection?

Question 2:
If the answer to question 1 is yes.
The fact that the WiFi connection drops and the relay switches back to open, which would also happen in the event of a power failure. Can the cause be found in the hardware?

Q1 = No… If you are using HA to run the automation then you need wi-fi as you said your ESP8266 is connected via wi-fi.

Best thing to do is get better wi-fi but adding more Access points or moving something to get better connection.

Yes, it can, but only with the proper configuration as @blacky eluded to.

Take a look at both the Wifi Component and the API Component, they both have a default reboot_timeout.

-70db is the threshold for problems w/ ESP’s, consider using MQTT instead of the API if you are disconnected for long periods. And getting an ESP w/ an external antenna(?).

Yes this is possible.

First: -70dB is far from “bad connection”. I have quite some modules going down to -95 and working perfectly. I’d check router settings… (bad settings, bad router, a lot of interference…)

But, essential things are best made inside esp module, NOT with HA automation. This way all will work even without wifi, while an automation in HA just can’t work if module is not connected to HA (kinda logical, right?). I have IR detector, which controls light in main entrance. All is done inside esp module, nothing in HA.

The reboot_timout is 15min by default and because when the wifi connection is lost the connection will immediately recover, I don’t think it will have anything to do with that.

The code that switches the relay back open after 2min has been processed via ESPhome and could normally work completely on the ESP8266 independently, but am I wrong here? (See code below).


captive_portal:

switch:
  - platform: gpio
    name: "Irrigatie_algemeen"
    id: irrigatie_algemeen
    pin: 5
    on_turn_on:
      then:
        - script.execute: script_irrigatie
     
script:
  - id: script_irrigatie
    then:
      - delay: 120s
      - switch.turn_off: irrigatie_algemeen

I have excactly the same problems… Did you find a solution?

Thanks!

You must live in a very radio quiet area with a very low noise floor at 2.4GHz. This is the accepted advice:

https://www.metageek.com/training/resources/wifi-signal-strength-basics/

EDIT: necroposting brought this into my feed :roll_eyes:. I did not look at the date that was posted, apologies.

1 Like

No worries :wink:

The problem is not the Strength of the wifi. Normally it’s working fine.
But I was gone for a few days, and on the first day my AccessPoint crashed. And that stopped my ESP is managing my AWHP, which therefore also stopped. So I came back in a freezing cold house, just because a AP crashed.

I would like to see that in the situation the Wifi fails, a ESP just runs the code it has…

Thanks!

You need to disable the reboot timeout as per this post: ESP8266 stops working after losing wifi connection - #3 by crlogic

FYI
If I remember correctly it was a hardware problem in the end, as soon as the relay was activated the D1 mini lost its power. A capacitor over V+ and GND was the solution. No more problems since then.

Yeah, it’s a standalone house, not in the center of town, far from any big apartment buildings etc…
I guess that some role plays quality of router, too.

1 Like

Thanks! I also read this:

Do Automations Work Without a Network Connection
This is a common question and the answer is YES! All automations you define in ESPHome are executed on the microcontroller itself and will continue to work even if the Wi-Fi network is down or the MQTT server is not reachable.

There is one caveat though: ESPHome will automatically reboot periodically if no connection is made to its API. This helps in the event that there is an issue in the device’s network stack preventing it from being reachable on the network. You can adjust this behavior (or even disable automatic rebooting) using the reboot_timeout option in any of the following components:

WiFi Component

Native API Component

MQTT Client Component

Beware, however, that disabling the reboot timeout(s) effectively disables the reboot watchdog, so you will need to power-cycle the device if it proves to be/remain unreachable on the network.

After setting the “reboot_timeout: 0s” for the three components the problem is solved…