I have been working on a home automation project lately. It is complete to the extent of switch control and getting the readings of temperature, humidity. I am using a Raspberry Pi 3 as MQTT broker. It is running Node-Red and Mosca. At the client side, I am using ESP8266, wired up with relays and sensors. Also, I have a mobile app build on the ionic framework. Moreover, I have used two-way switches in order to maintain the connection with physical wall switches so that appliances can still be controlled if something breaks down. After completing all this, I was wondering to install it in my home. So I started a bit of research for being on a safe side as my plan was to play with MAINS now.

Recently, I got to know about solid state relays and they seem to be a lot better than the one I am using. So far, I have used normal relays. Like this. However, I see a problem with solid state relays. It has two ports at the output(COM & NO).

  1. How can I add a two-way switch to SSR in order to make it accessible from wall-mounted switches as well as the mobile app?

I was also thinking to add a dimmer to adjust the brightness of lights and speed of a fan. For which I found TRIAC as the solution. I got how it works but still, I could not just understand the TRIAC completely.

  1. Does TRIAC replace a relay?

I am planning to use this relay board with this dimmer.

Moreover, I was looking around for adding a surveillance option using IP cam but could not find anything fruitful. If anyone could post some references for that too, it would be of great help.

Any other suggestions apart from my questions would also be appreciated.

  • 1
    A TRIAC does not replace a relay. See How Dimmer Switches Work. Solid state relays do have power limitations so one question is how much power will the equipment you are switching draw? Dec 14, 2017 at 12:41
  • 1
    There is a bulb you could consider buying (it makes everything a lot easier for you). It works on WiFi and there is no need for any bridge (like with Philips Hue). You can switch it off like a regular bulb by cutting the electricity and it will work again when you turn it on. But you can control it with Alexa, IFTTT or anything you might find out connecting to it (depending on how much effort you put in it. (1/3) Dec 14, 2017 at 18:21
  • 1
    I prefer this because you can make any color and use it with the already installed system (I have made a system almost like you with a Raspberry Pi 3 as the main unit, app on phone and an Alexa Echo to use my voice but all connected to the main RPI). I just made the connection between the RPI and the bulb via IFTTT and then it worked like a charm. Here is an example on the bulb if you want to invest in that: lifx.com/products/lifx I have a dimmer for some of my lamps and them a LiFx bulb in some others. And in your case the dimmer is of course needed for the fan. (2/3) Dec 14, 2017 at 18:21
  • 1
    The LiFx bulb can be dimmed from 100%-1% and switched between (if I recall it right) 16.000.000 colors (if that is interesting for you) and a variety of beautiful white and yellow nuances. (3/3) Dec 14, 2017 at 18:21
  • 1
    While this is a great site for your question, if you don't get an answer, especially after offering a bonus, you might want to consider hardwarerecs.stackexchange.com Or even asking AdaFruit if you plan to buy from them (or any other supplier fo your choice)
    – Mawg
    Dec 15, 2017 at 7:32

2 Answers 2


Although the two questions in one look initially like a bad idea, actually they look like they are addressing one similar topic. I'll skip over the scary topic of working with mains (especially in hard-wired enclosures which add new failure modes and access hazards).

Your 'hardwired backup' strategy makes sense, as in you should plan for WiFi to go down, and for your RP3 to fail catastrophically. You could easily be days away from being able to re-build the system. What is less clear is if you should plan for redundancy in the case of an endpoint crash. Sure the endpoint is powered - is it mains powered, and do you care about the lights coming back on after a brown-out?

The reason this is important is the operation of a 2-way switch. In the classic stairway/hall configuration, there are two 'live' lines, and a change-over switch at each end. This allows both ends to invert the current state. However, this may not be the best 'override' mode, and crucially would require your electronic switch to remain active in the event of a failure.

Once you accept this, there are three possibilities:

  1. Operate the electronic and mechanical switches in parallel, providing OR logic. Light is on if A or B is switched on, so you can force the light on but not kill it.

  2. Use two SSR switches for the electronic switch, and a 2-way mechanical switch. There is no need to worry about switching overlap (given the way the switches implement XOR) but if the electronics fail, the light will remain off.

  3. Assume the endpoint electronics are reliable enough that you can tolerate single luminaire failures (just not a total network loss), and implement the 2-way switch control in the HW/SW of the endpoint. Then the mechanical switch becomes a local input to be combined with the RF input.

Assuming that you pick option 3, you only need a single SSR which can act as the mains voltage control element. You also have the possibility to use a dimmer circuit rather than an on-off switch.

In this context, a dimmer circuit does almost look as a drop-in replacement for an SSR. A triac alone does not make a dimmer, you need a small amount of additional circuitry. A triac will also not always give the expected results with some LED drivers (the power-supply can act as a non-linear load). Comparing on-off and dimmer functions you might also see that a dimmer can work in-line on the live wire, but that shouldn't be important here since your electronics need live and return to generate a local power rail.


A TRIAC can replace a relay. Both have their own advantages and disadvantages. If you only want ON/OFF states, a relay is easy to use and a cheaper option but if you want to dim your lights or control the speed of fan then a TRIAC is what you need. Also, you will need a comparatively bigger heat sink if you use a TRIAC. Check TRIAC vs Relay on the Electronics site for a more detailed comparison.

  • 1
    Whilst this is true, I don't think it actually helps the OP to answer his questions, it just confirms he is on the right track. Dec 15, 2017 at 13:07

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.