I want to make a home automation system, and I need some computer-controllable switches. The reason I can't use relays is that I also need the switches to be switchable manually and not programmatically (because I don't want the light to get stuck in whatever status it's in at the moment when the program controlling the switches is going to crash). However, I am not sure what is the canonical way to make something like that.

The options I've thought of so far:

  • A regular switch with a servo duct-taped onto the back
  • A switch connected to a microcontroller (like an Arduino) that inverts the signal every time the switch is toggled
  • A switch that sends messages to the microcontroller connected to the lamp telling it to inverse the state of the output
  • 2
    The first option seems to be the coolest option.
    – 10 Replies
    Dec 12 '16 at 18:33

By far the easiest route is to buy an exisiting product here which is sufficiently open that you can use a standard RF module to control them.

This is equivalent to having an MCU and switch integrated (so gives you good autonomy) and also avoids any problems with the appearance or safety of the result. You are of course then stuck with the manuracturer's on-air protocol unless you try and reverse engineer their firmware on the switches (which are probably going to be heavily cost optimised).

If you use the LightWaveRF switches, all you need is a £1 433 MHz transmit module, and an arduino or similar to send the protocol described here. These switches handle all the mains isolation, and provide capacitive touch controls on the switch. You can also use the standard remote control to provide inputs to your control hub if you use a receive module. Since there are several channels available, you could use the remote to provide input to the hub, and use the hub to relay the commands on a 2nd channel.

433 MHz modules are simple to repurpose because the RF protocol is insecure. Anything more sophisticated leaves you at the mercy of the manufacturer unless the firmware is open

  • That's a good idea, but I'd prefer something with dual communication, such that I can programmatically change and get status of the switch.
    – Danya02
    Dec 11 '16 at 13:15
  • Best edit the question, that does constrain you quite a lot with current components, I think. Dec 11 '16 at 13:35
  • 1
    Thinking more, you can do this if you generally send requests to the hub, and have that relay them. Edited the answer (and I've seen this done with a R-pi) Dec 11 '16 at 13:55

If you want a totally independent switch in case of the microcontroller fails, then you can hook-up an XOR gate for two inputs. The relay will be off when both inputs are the same, and on if the inputs are different. The two inputs are:

  1. Regular switch for manual control.
  2. Output from an MCU for automatic or remote control.

The circuit:

enter image description here

Normally the switch should be open (input B is low just like on the image above) and the N-FET is driven by the MCU pin. When the MCU pin is low, then the XOR gate outputs low because the inputs match(both low) and the relay will be turned off. When the MCU pin is high, the relay will be turned on because the inputs are different.

Now if the MCU crashes and its pin stucks in a state, then there are two cases:

  1. MCU pin stucks in high state and the relay remains turned on. In this case switch will give you an ability to control the relay as follows. If the switch is open then the relay will turned on, and if the switch is closed the relay will turned off.
  2. The MCU pin stucks in low state. In this case an open switch will turn off the relay and a closed will turn it on.

Here is a simulation so you can check the mechanism yourself. The GPIO pin of the MCU can be controlled remotely via Bluetooth, WiFi or the already mentioned 433 MHz module or other suitable technology.

Update requested by OP:

List of 2 inputs XOR gates available at Farnell for example. Here is a particular one from Texas Instruments also available at Farnell.

Some remarks about safety. If you decide to switch mains voltage then it is recommended to switch the hot mains wire rather than the neutral.

The best would be to use an SPDT relay to make sure and switch hot and neutral as well.

enter image description here

Instead of a MOSFET you could use an opto-isolator to isolate the digital circuit and the manual switch from the relay and mains.

Always use proper sealing, do not let open bare metal surfaces. Keep in my that dealing with mains voltage is always highly dangerous.

  • I think this might work, as it's more electric and less electronic. I still need to test this, though. For starters, figuring out where to get an XOR gate as a physical package and not as a metaphorical concept in electrical CAD programs would be nice.
    – Danya02
    Dec 12 '16 at 18:05
  • @Danya02 Good point, I have updated the question and added a list of XOR gates from Farnell. Also searching through logic IC/gates at Digikey or Mouser would result similar lists. Dec 12 '16 at 18:40
  • 1
    The main problem with this circuit is usability. The switch needs to be a physical toggle but the electrical state of the device doesn't follow the physical position. So walking into a dark room, you may expect to flip the switch "up" to turn the light on, but that's not the case here. That's why home automation switches are usually momentary contact devices, and have physical return-to-neutral-position switches. Leviton uses a push-on/push-off toggle scheme, Jasco uses a push-top-on/push-bottom-off rocker, Lutron has a push-top-on/push-bottom-off flat panel, etc. Dec 27 '16 at 17:03
  • @John Deters Yes that is a drawback, also the problem exists. For example you have a stair lighting, and there is a switch at the bottom and at the top, you have to toggle. Also it is just a simple solution, more compex and sophisticated ones can be created if one takes the time. Dec 27 '16 at 17:13

I believe your original statement may be flawed.


Why not just get a relay with a manual override?

Here is one available from honeywell.

  • This was my original idea, but I couldn't find any of those near me. Also, I didn't want to have to manually switch the relay into auto mode after finishing using the manual one.
    – Danya02
    Dec 13 '16 at 9:15
  • 1
    But the manual override disables the relay altogether. Dec 15 '16 at 9:34
  • @lynx0123 that's the functionality the OP is looking for " that I also need the switches to be switchable manually and not programmatically (because I don't want the light to get stuck in whatever status it's in at the moment when the program controlling the switches is going to crash)" I'll come up with some alternatives later today.
    – SeanJ
    Dec 15 '16 at 10:11

A XOR circuit or this somewhat will implement your requirement! enter image description here

  • It work like staircase switches to toggle the bulb from both sides. I am using 2 SN74LVC1G3157DBVR chips. IO1 will connect with a switch, IO2 connect to Pic I/O pin.
  • The only thing that I could not control is to know state of the relay so status of the load is not known to the attached Microcontroller.

enter image description here

Your Answer

