Please check sonoff-tasmota, it’s supporting lot of things beside sonoff devices, details in I was using this firmware together with MagicHome and on bare esp12 modules. Works great!