Recommended · for beginners
Raspberry Pi Automated lights with 8 channel relay, PIR motion sensor
Why people recommend it
A short tutorial on driving a relay from a Raspberry Pi to switch lights, adaptable to timers or sensors.
Watch for: Demonstrated at 12V; switching mains needs far more care
In their words
Here is a short YouTube tutorial that show how to handle your kind of 'problem'
thowa on raspberrypi.stackexchange.com, Mar 2016. CC BY-SA.
Sorry for the poor image quality but the youtube video showing the connection is shown here.
Prashant on raspberrypi.stackexchange.com, Jul 2019. CC BY-SA.