Mixing mains voltage with diy electronics can be FATAL! its not a good idea.. not forgetting that adding a diy device to your mains wiring will probably invalidate any insurances when it burns your house down.
Generally the solution involves a smart switch which replaces the 'olde worlde' mechanical device. there are lots of esp8266 soc based devices which can be interfaced via manufacturer supplied apps and remote servers or in many cases can be reprogrammed with your own custom or community developed firmware.
the shelly
https://shelly.cloud/ is an off the shelf product that does the job via wifi and can be interfaced with a mqtt broker you host on your pi out of the box, the itead/sonoff brand range of wifi devices are a little cheaper and can be reflashed with tasmota firmware for a fully featured iot device you can control directly via its own web interface or via a number of established protocols and control systems.
https://github.com/arendst/Sonoff-Tasmota/wiki
the problem with many of the commercial products (here in the UK) is that they require a constant mains feed while many switch box housings only contain a switched live line resulting in an always on light when a smart switch is wired into the loop ..
so Perhaps enclosing in a suitably certified safe device behind a plate and covering with something like:
https://www.aliexpress.com/item/Wall-Pa ... st=ae803_4
for circa $10 usd a sonoff RF bridge can be reprogrammed with tasmota (link above) and convert the 433mhz signals from such a switch to a wifi- mqtt topic/payload which your pi can pick up and process and issue further mqtt to control any relevant devices.