Sonoff Basic R4 magic mode not compatible with a solar inverter

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.

That sounds like a AC noise problem alright.
Does it happen with different types of bulbs?

I wasn’t sure what Magic Switch Mode was, but I found this image and it explains it to me:

You could try a selection of small class-X filter capacitors and see if it improves the situation.

https://www.allaboutcircuits.com/technical-articles/safety-capacitor-class-x-and-class-y-capacitors/

A snubber capacitor would be the next test, but they typically have to be matched to the problematic frequency.

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.

Yes, this might be true.
Perhaps open a case with Sonoff as they might have seen this with other inverters or generators.