In principle it works, but it always ‘toggles’ after it is de-energised. You could say it’s not bad now, but if I want to build a gate control, for example, the gate always opens or closes after a reboot of the ESP.
I once experimented with HAA and there was a configuration where this was not the case, which means that it should work in principle.
I hope there is a solution to this.
vg
Chris
It is unlikely that you will find a solution to what is arguably a very bad hardware design choice. There is a limit to what can be fixed in software.
There is a weak pull-up on GPIO 0 (or the esp8266 will enter flashing mode) on boot. This is a requirement of the esp8266, you cannot change that. That means on reboot, the signal goes:
from being driven LOW (normal operation relay turned off)
to reset (GPIO 0 is now an input, so weak pull-up takes effect, and it is now HIGH)
to startup (GPIO 0 becomes an output LOW)
That WILL glitch the relay. There is no SW fix for this bad HW design. For many projects a glitch doesn’t matter much. If it does for yours, you need to make sure both the HW and SW design are good for the requirements you need.
With Esp-01 it’s little bit more difficult, because it doesn’t have any rock solid (on boot) gpios exposed. You can try with GPIO0 or GPIO2, mut even those fluctuate little bit on boot.
Add this to your switch code: restore_mode: RESTORE_DEFAULT_OFF
and on esp8266:
early_pin_init: false
This design is FLAWED. It WILL glitch on reset. There is no SW fix that will solve it. See above for the reason.
If glitches are something the rest of your project can’t tolerate, you will need a better design for this portion. That means selecting a different relay board, one that has a good HW and SW design and is known to NOT glitch. This one is known to glitch. So far, no one has come up with a SW solution to a relay that is active HIGH on GPIO 0.
If the relay was active LOW, it could be possible to make it work across a reset of the esp8266. But it might have undefined behavior on first power on, as the power turns on.
If glitches matter to the design of your project, you HAVE to do a really good design. For many projects, these short glitches don’t really matter, which is why the design can be just mediocre (the bar is it “it worked the one time I tested it”).
the rest of the sentence you quoted had the necessary context.
after a reboot of the ESP.
This is EXPECTED behavior with a relay that is active HIGH on GPIO 0, which MUST be HIGH for normal boot on an esp8266.
The behavior is by design (the design is flawed if your requirements don’t allow glitching the relay on boot, and you will need a new/better design, of the HW, since this is NOT a problem than can be fixed by software.)