Just fixed an issue with an ESP8266-based smart switch running Tasmota. It began to randomly reset to factory defaults & I thought its flash memory was dying.
Turns out the manual on/off button is faulty & randomly stays 'pressed' for >40 secs & this triggers a config reset.
Fix = replace button.