See library and schemas https://github.com/Tomat7/ACpower (1 phase, AVR and ESP32) and https://github.com/Tomat7/ACpower3 (3-phase, ESP32 only)
See also https://github.com/Tomat7/ESP32-AC-power (code of regulator with LCD, Encoder, WEB and other features)