The bottom schematic is the actual switch, it's very easy, the optocoupler
separates the digital signal and the high voltage circuit. The transistor
amplifies the signal and the TRIAC blocks all the current or passes all the
current.
After testing it I noticed it wouldn't handle inductive loads (transformer)