Sonoff ZBMINIR2 driver

I think that I understand what happens now.

After switching to Detach(ed) Relay Mode, and after closing or opening the external switch, Sonoff is sending a notification command, that expects an acknowledgment from the Zigbee coordinator (the hub). As HE is not sending an acknowledge, the device makes two retries and automatically switches into a fall-back mode. That's why on the next change of the switch status change, the relay toggles it's state - this is an emergency/fallback logic when the hub is not operational for some reason.

The bad news is that this command acknowledgment ( 'ZCL default response') must be sent on system level, not from a custom driver... This is currently a problem even at Home Asssistant ZHA and the Detached Relay mode doesn't work there also, only Z2M handles it properly (and Sonoff hubs, of course).

I will try one last workaround, and there is a 50/50 chance of success.