I installed a Sonoff Basic R4 with Esphome firmware and used their “magic switch mode” for quite a while successfully.
Magic switch mode works by capturing power outage from switch for some milliseconds.
However now I have installed a hybrid solar inverter (Deye) and all Sonoffs in magic switch mode are randomly swiching on and off every few minutes. Probably the inverter makes enough power disruptions doing its magic to trigger the magic switch input.
If anyone does not have a solution, I’ll leave it here as a warning for others.
I think any capacitor that will smooth the power enough will also kill the magic switch fuctionality which relies on a 4ms-5ms cut from switch in my case.