I have a Raspberry Pi driving a home automation system. I have connected a bunch of lights to the network. The GPIOs of the Pi connect to a relay board that switch the lights on and off. What I need is failsafe + alternative switches. These switches need to work even if the Pi fails, and they need to be usable when the system is operational (in 3 way switch, Pi switch XOR manual switch = bulb state fashion).

What is the best/standard solution for this? Three way switches would work, but then the Pi loses the state of the devices. I could get the state of the lamps by setting up a DC adapter in parallel to the bulb input, effectively measuring voltage which could feed back to the Pi telling me the true state of the bulb.

  • \$\begingroup\$ Why not interface the RPi with a system that maintains state separately, such as X-10? \$\endgroup\$ Commented Jul 31, 2014 at 2:21
  • \$\begingroup\$ Look at 3-way light switch diagrams. And then just replace one light switch with your relay. \$\endgroup\$
    – Passerby
    Commented Jul 31, 2014 at 3:48
  • \$\begingroup\$ @Passerby Three way switches would work, but then the raspi loses the state of the devices. In that case I cannot give a switch OFF all lights command. \$\endgroup\$ Commented Jul 31, 2014 at 4:13
  • \$\begingroup\$ Why not save state in a serial flash chip? Dirt cheap and an easy interface. Aside from that I would use something more robust than a Pi. There is some new lower cost DIN rail ARM setups that are perfect for this. \$\endgroup\$ Commented Jul 31, 2014 at 6:00
  • \$\begingroup\$ @C.TowneSpringer How would I get the state in your idea? \$\endgroup\$ Commented Jul 31, 2014 at 6:07

1 Answer 1


You could use light sensors giving feedback to the rPi about its state. Or use some small value resistors (sense resistors) to tell the rPi if there is current flowing to the lamps. Hall effect sensors on a lead to the lamps could also detect current without the power loss that a sense resistor would incur. Each of these could determine state. In software, you could control the relays depending on the desired state versus the detected state.

The alternative power could be provided by a normally closed relay whos coil is powered from the rPi's power. If that was lost, the NC relays could introduce power to the lamps from an alternate feed(backup). When the pi came back online, it would then OPEN the NC relays now letting you KNOW the state of the bulbs is OFF and the rPi would continue on its original program. A single pole switch in line with the backup relay and the bulb would allow you to manually control power.

  • \$\begingroup\$ the hall effect sensors have analog outputs for measuring current. Any way to make it give a digital on/off output? \$\endgroup\$ Commented Jul 31, 2014 at 15:51

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.