Automating 3-way Switch Shelly + Home Assistant: Part 1 – Wiring

I had replaced my plain old bulbs with WiZ light bulbs in my hallway. The bulbs were originally controlled by a gang of 5 switches. Initially I had replaced the 1st and last switches with tp-link Kasa HS210 3-way smart switches. This was fine until I wanted to add a motion sensor and also change the bulbs’ settings (change mode based on time of day etc). It turns out controlling smart bulbs with smart switches is not a good idea, one cant change bulb settings when not powered and changing them while powered creates delay, moreover the automation logic gets complicated. The better option to have plain old switches and add a smart relay between them and the light bulbs. The key is to decouple the switch and the power to the light bulbs and have the switch(s) be inputs to the automation. This allows the light bulbs to be constantly powered and be controlled the switch(s) and other smart controls.

Shelly 1 (I have the gen. 1) is a perfect fit for what I wanted to achieve. I replaced the smart switches with plain old 3-way ones (I did initially leave them in, but it’s an overkill I think) and added the Shelly 1 between the end switch and the light bulbs.

Wiring

!!! WARNING: Please be careful if you plan to do this on your own, playing with electricity is very dangerous, always turnoff power at the panel before attempting anything and ensure all connections are secure and tidy. It’s advisable to ask a certified electrician to help !!!

Shelly 1 has 5 terminal. The Line and Neutral terminals power the internal electronics and need to be connected at all times. This requires that there is are line and neutral wires coming in to the junction box where the Shelly 1 is to be installed. In many cases there may only be the traveler and the load wires in the junction box, as was the case with mine. I had to splice and fish the line and neutral wires from a nearby wall socket, but you may be have better luck! I disconnected the load wire from the 3-way switch (typically connected to the black terminal/screw in the US) and connected it to the O terminal on Shelly 1. I connected a wire between the switch’s load terminal (the black one) and Shelly SW terminal. Finally I connected the I and L terminals to line wire I had fished and then N the neutral wire I had fished.

The way this works is that there is a relay between I & O terminals and this relay is controlled by Shelly 1’s electronic based on software commands or the SW terminal. The default mode of operation has the SW terminal logically connected to the relay control, this means that the switch directly controls the power to the light bulbs connected to Shelly 1. This can be overridden by setting the button setting in Shelly 1 to ‘detached’.

Configuration

I used the Shelly app on on my iPhone to discover and setup Shelly 1. Pretty straight forward. I typically assign a static address to all my WiFi smart home devices, this allows me to group and manage them better, I did this from my UDM console. I did the rest of the setup using the browser.

The important setting changes I made was to set SETTINGS > BUTTON TYPE to Detached Switch.

Shelly 1 Button Type Setting

changed the name and set cloud mode off, but these are optional. Left the rest of it as is.

A better Home Network using UDM

Over the past few years I have accumulated a good number of Smart Home / Home Automation devices to add to the the usual PCs, tablets and phones. The list not includes streaming players, smart TVs and a host of lights, power switches & sockets, fans, camera and all kinds of sensors (the list goes on). Each of these is a potential entry point into a home network. This poses two challenges, one, security and two, management.

I objective was to separate / isolate devices, allow only what need to connect to connect. The approach I wanted to go with is to separate the devices into their own networks (a.k.a. vlans) computers, tablets, phones and storage in one, streaming devices like TVs, Roku, Alexas, that are always connected in another, Smart Home / IoT devices in yet another and finally one for the guests. The IoT devices can actually be split into those that need connect to the internet that those that don’t (more on this later).

Most home use WiFi routers I’ve come across support at most two networks — Home and Guest. Moreover in the quest to make it easy to use, many dumb things down to a level that makes it virtually impossible to do anything. Case in point — Google WiFi, there is no way to configure the network using a computer, one has to fiddle with an app (try setting static IP addresses for 150 devices on a phone app Google!)

I looked around and settled on the UDM (Unifi Dream Machine). One because it’s built on Linux and two because it is a ‘prosumer’ class device, in that it has allows one to build a custom home network with relative ease out of the box. It comes in two versions the UDM and the UDM pro. The UDM is an all-in-one solution that has the gateway, router, 4 port switch and a WiFi access point rolled into one. The UDM pro doesn’t have a WiFi Access point and is a 1U rack mountable device with an 8 port switch.

The price on Unifi’s web store (when I bought it over a year ago) for the UDM is $299 and the UDM pro is going for $379.

The non-pro UDM is a good option for a less complex setup that is mostly WiFi based. The pro version is more suitable for installations that have servers hosting virtual machines, NASes, wired WiFi access points etc (probably a future blog topic). Both support meshing. With the Unifi ecosystem one can have both a wired and wireless uplink (i.e. connection from the access point back to the internet router).

I went with the non-pro version because it was an all-in-on. I have it in a mesh with a couple of UniFi BeaconHD to extend coverage across the basement, 1st & 2nd floors I have a managed 8 port PoE switch for my wired devices like the NUC that hosts VMs and the Qnap NAS. One of the PoE ports connects to and powers the AC Lite AP.

This setup is a work in progress. I probably could have gone with the UDM pro in the 1st place given that I ended up getting an 8 port switch any way, the combined cost of the UDM and the switch is more than the cost of the UDM pro. I didn’t choose the UDM pro in the first place was to avoid the hassle of running an ethernet cable to the 1st & 2nd floor (I ran some, but gave-up after trying debug network speed issues thanks to my less than pro wiring and crimping skills!).