If you want to squeeze it all onto one board, you could consider using a much smaller version of the ESP32 like this one:
These are very competitively priced and I have started using them instead of the D1 mini, which is available as ESP8266 and pin compatible as ESP32 too (with a slightly larger board size).
I have used different pins though.
Note the use of a screw terminal with 5.08mm pin spacing. The 3mm are a little small for 240V IMHO.