Making a smart light switch

20

5

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

Danya02

Posted 2016-12-10T23:24:43.677

Reputation: 104

2The first option seems to be the coolest option.10 Replies 2016-12-12T18:33:40.090

Answers

8

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

Sean Houlihane

Posted 2016-12-10T23:24:43.677

Reputation: 7 357

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 2016-12-11T13:15:46.150

Best edit the question, that does constrain you quite a lot with current components, I think.Sean Houlihane 2016-12-11T13:35:15.747

1Thinking 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)Sean Houlihane 2016-12-11T13:55:23.183

7

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.

Bence Kaulics

Posted 2016-12-10T23:24:43.677

Reputation: 4 291

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 2016-12-12T18:05:20.913

@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.Bence Kaulics 2016-12-12T18:40:58.810

1The 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.John Deters 2016-12-27T17:03:39.920

@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.Bence Kaulics 2016-12-27T17:13:17.117

3

I believe your original statement may be flawed.

The reason I can't use relays is that I also need the switches to be switchable manually

Why not just get a relay with a manual override?

Here is one available from honeywell.

SeanJ

Posted 2016-12-10T23:24:43.677

Reputation: 679

@SeanJ Did you get any alternatives for the same? If so, can you please share?SE_User 2017-02-02T13:14:49.823

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 2016-12-13T09:15:27.410

1But the manual override disables the relay altogether.leon.valencia 2016-12-15T09:34:01.803

@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 2016-12-15T10:11:18.453