crocket wrote: ↑
Wed Apr 17, 2019 4:06 am
I want to control a lamp with Raspberry Pi and a relay. However, I want a single power line to provide power for Raspberry Pi and the lamp.
How can I do that? In other words, I want to construct a WiFi lamp with Raspberry Pi, a relay, and a lamp.
If this is a table lamp and you have access to both the UNSWITCHED active and neutral wires, then you can splice in a small power supply to supply the RPI. The RPI relay then switches downstream of the power supply mains input. As said by others, make sure its an appropriate power supply and the mains wiring is done safely and correctly.
If its a built in ceiling light and wall switch then it gets complicated. Often (but not always) the wall switch just has the active wire and no neutral wire. In these situations its impossible to feed a standard power supply with running a neutral wire to the wall switch location. The neutral wire is found at the light socket, but to save cost, its rarely run down the wall to the switch.
Parasitic power supplies and HA smart wall switches are emerging, that will operate on just the active wire. But building one is a very complex task.
Consider using a WiFi or Phillips Hue style smart Bulb, and talking to it from the RPI directly or via IFTTT.