I am currently building and installing a home automation system. I have currently configured centralized audio system with ceiling mounted speakers in each room with a raspberry pi in each room.

I want to now start controlling the Lights and possibly the wall sockets with these raspberry pi. I have found a lot of information about using mechanical relays to switch lights on and off, which is what I want to do. But I want to maintain the normal switching functionality.

One way I can do this is by interfacing each switch back to the raspberry pi and letting the mechanical relay do all the work. If possible i would like to avoid this.

What I am asking is there a way to configure the normal switch to function as a master, that not be affected by the relay state to switch the light on and off. Below is a diagram (not very good) to demonstrate what im talking about.

Diagram Of idea

4 Answers 4


It sounds like you are wanting to wire the wall switch and the relay as a three-way switch arrangement. This way, if the relay has the light turned on, flipping the wall switch will turn it off, and vice versa. You could wire a single-pole double-throw relay to work as a 3-way switch, and install a 3-way switch in the wall (if it isn't already a 3-way switch). Borrowing your artwork:

enter image description here

While this should work, there could be an issue with the RPi not knowing whether it is turning the light on or off. That's because every time you flip the wall switch, you will be reversing the relay's ON/OFF state. That issue might or might not matter to you. If it does matter, you could add a sensor to allow the RPi to detect whether the light is on or not. Note: this could be done using a light sensor, or using a current detector on the wire leading to the relay. A voltage detector at the relay could also allow the Pi to read the on/off state, but I would use opto-isolators in the voltage detection circuit to ensure that 120v/220v cannot ever reach the Pi!

An advantage to the three-way switch wiring approach is that, when it comes time to move out (or you just want to disable the RPi system for any reason), you can simply replace the relays with jumper wires. The wall switches will simply work as before without any other changes or rewiring. If you want to get really fancy: you could run wires from the relay to an "override" switch hidden in a closet - so that even if the relay goes bad (or the Pi goes berserk!) you can flip the override switch thereby shorting across the relay, returning total control to the wall switch.

  • Thankyou this solution will be most likely the best for my situation. As its easily removed and can be installed with oit affecting the physical switching plus adding more switches for larger rooms is easy.
    – thomascrha
    Commented Jul 22, 2014 at 12:45
  • I wouldn't object to this answer being accepted. Maybe I'll then have almost enough brownie points to add comments :-) Commented Jul 22, 2014 at 17:06

To make things easier with less high voltage wires is the have the Relay at the actual wall switch.

Then all you need to do is pull thin wires like Ethernet style to the Pi.

  1. 2 Wires -The wall switch when changed will signal the Pi
  2. 1 Wire - The Pi will trigger the Relay at the wall switch 3 ^^^ - THe same same wire for any other way to turn on/off the switch

To explain a bit more...

  • So essentially you will turn the wall plate into a low power (3v or 5v) switch that is connected to the Pi. You have to pull a few new wires but they can be very thing because its just signal wire.
  • The high power you wire to the relay inside the switch box (hopefully you have space) this is to avoid taking out the wires and rerouting. It already works from there so use that space.
  • You just run 1 wire (common GND form other wire) from the Pi that will switch the relay. Possibly you need 5v and some kind of transistor to do this on the Pi side.

The downside is that every single socket and switch will need at least 3 new wires and that is allot of GPIO's

Alternative: You can make wireless 433mhz with relays instead. They can leach power from the 220/110volt lines and trigger the relay when it gets a signal. You can use tinyAVR MCU that are cheap as chips for IO control and cheap as chips radio receiver, which is a wire and some kind of ballast.


I would avoid building your own components and consider using an established (and UL-listed) solution that you can manage with your Pi. You could replace your existing wall switches with (for example) Insteon switches, and use software like Openhab to manage them. The switches still have local control, and Openhab can tell what state they're in and turn them on/off or adjust dim levels. In addition to Insteon, you can look into UPB and Z-Wave controlled switches; each of these systems has their advocates.

The one downside is that these switches generally require a neutral wire in addition to the hot that is switched. Depending on the age of your house and the habits of the electricians that wired it, you may or may not have that wire available.

This doesn't have quite as much DIY mojo as what you are planning, but it avoids the (small) risks associated with switching high-voltage with non-conventional devices.


for your own Jarvis look up jasper for the raspberry pi add some code for the Belkin wemo switches and you can say

you : jasper turn TV on

jasper : OK turning the TV on

there is a bit of a delay because these switches are meant to be controlled with an android or iPhone over the network but there is a python API avaliable

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.