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?
-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(?).
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).
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…
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.
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…