HA ESPhome Sonoff devices fail to come up after power cycling

I am in the process of converting my home light switches to Sonoff Basic modules running under Home Assistant with an ESPhome integration.
To install more Sonoff units I turned off some breakers, did my install, turned the power back on and three of the previously working Sonoff modules no longer showed up on the wifi network. I ran into this situation once before and to fix the issue required reprogramming the Sonoff.
I am wondering if this is a known problem with Sonoff’s because this is not workable for normal operation.
The problem doesn’t seem to be HA related since the Sonoff’s don’t show up on the network and HA can’t deal with them.
There are two possible reasons that I can see - either there is a deep down fault with Sonoff’s that I have not seen anywhere in my searches or the device programming is overwritten due to the power cycle combined with the reprogramming button being active due to tight quarters.
I remove the Sonoff pcb out of the housing and stuff it into my own housing that fits into a regular switch box. I use a capacitive switch connected to 3.3V, grnd and the Sonoff ‘K_P’ terminal. I do not use the ‘Key’ terminal. Once the capacitive switch is connected, the normal Sonoff switch seems to be disabled but there is a possibility that the switch is activated due to wires (for the capacitive switch) physically pushing the switch enough to activate it.

Anyway, the current situation doesn’t work but before I physically shorten the long pushbutton shaft on the Sonoff, I would like to see if other people have run into these problems.

Oh, the capacitive switch basically grounds the ‘K_P’ line when the switch is activated.

I do not know what the difference is between the ‘K_P’ terminal and the ‘Key’ terminal. If anyone knows more info, I would like to know the difference.

I don’t know if the problem I am seeing is related to yours, but with the latest updates to ESPHome, I have having a lot of issues with devices not reconnecting after uploading. I am trying to get a Shelly 2.5 running for a project. When I flash tasmota on it, it connects up to the network with no issues. I am able to upload different versions of tasmota and reboot with the device coming right back online. I upload a compiled binary for ESPHome and sometime the device will connect up. But after uploading a new image, my router shows it assigns the IP address to the device, but the device never responds to a ping. After loading up tasmota again, it comes back on the network with no problems. I am thinking there is something in the latest version of ESPHome that is the problem.

Thanks for your reply. An interesting observation! I have never used a Shelly or Tasmota but my issue happened for the first time a couple of HA versions back. I can’t comment on which version ESPhome was at the time.

I have a different theory at this point - it still needs proper testing though.
I found mention that a local switch hooked up to the ‘Key’ terminal (GPIO2) causes a lot of issues as the line toggles on power up and can throw the Sonoff into one of it’s alternate programming modes. This apparently bricks the device until reprogrammed which is exactly what I have noticed.
I have moved my local switch to GPIO3 (RX on the 4 pin programming header) and supposedly this should improve things.
I must say I am a bit hesitant to do a power cycle because it did take a bit of time to remove all previously installed (in wall switch boxes) Sonoff’s, reprogrammed them and re-install them. I will be playing with mains wiring tomorrow and will turn off some breakers … we will see what happens when I turn them back on.

Finally hard the guts to turn off the breakers. Yes folks, the issue is GPIO2 … don’t use it for the local on/off toggle!