Please take note that this design is connected to Mains Power ...
If you don't know how dangerous it can be, do NOT try to replicate this design. MAINS can be letal...
This being said, here is how you can control any incandescent light or electrical fan with your favorite ESP8266 over internet :
This schematics is showing only the "power part" of the design
Basically R1, R2 and D1 feed an optocoupler with AC signal clamped at 0.6V by D1 and the opto LED.
Thus it produces a square signal crossing 0V when the Mains itself is at 0V. This signal is output on the isolated side of the optocoupler and is sent to the ESP8266.
ESP8266 is then computing a delay to switch on the MOC during a very short pulse. Doing this enables the triac to switch on only during a short fraction of the 50Hz (or 60Hz) period. Thehigher the delay the more the light is dimmed.
Here is an example showing an almost full brightness (most of the power is kept "ON")
And now a video explaining and showing all this :
JP