Have you ever wished that a switch in a room controlled a different outlet? Of course, you can go into the attic or crawl space (if possible) and reroute all the wiring.... or you can move the switched outlet just by upgrading the switch and using a smart outlet.
This is a companion article to my YouTube video, where I walk through the same basic information as provided here. You may wish to watch that video as well as reading this article.
Maybe you have a bedside lamp and the room switch controls the wall outlet on the opposite side of the bed. Or the switch controls both receptacles in the wall and you can't plug your alarm clock into the same outlet because flipping the wall switch would also shut off your clock. Previously, you had a couple of not-so-desirable options. You could run an extension cord from the switched outlet and plug your lamp (or other device) into the extension cord. Or you could take on the process of accessing the wiring above or below the room (or busting out drywall if those options aren't possible) and rewiring the entire circuit.
But by using a smart relay (or switch) and a smart plug, you can move that switched outlet to anywhere in the room (or even another room) with just some simple rewiring at the switch itself.
CAUTION! This project deals with household current. If you are uncomfortable working with electricity, wiring or are unsure of what you are doing, please hire a licensed professional.
Note: A neutral wire is required in the box where the current wall switch exists. This project will not work without the presence of a neutral line. You may wish to carefully remove the faceplate and assure the existence of a neutral before proceeding any further.
General Approach
There are a multitude of ways to implement this project, but the primary concept is that the light switch will be upgraded with a smart relay that communicates with a smart plug (outlet). Once this is complete, the smart plug can be moved anywhere and will be controlled by the wall switch.
Local Control
Both the relay/switch and the smart plug will need to be flashed with custom firmware to provide local control. Privacy issues aside, the devices need to operate locally, without relying on cloud services for the following primary reasons:
- The switch and any connected devices will continue to operate even if you have an Internet outage.
- You will never be subject to a subscription fee (having to pay a monthly or annual fee just to turn your light on).
- No reliance on another company's services that could go down, or permanently shut down, again rendering your light switch and connected devices useless.
- Speed - no noticeable delay.
Here are the measured times for those options in the video:
As you can see, the cloud version has a substantial delay, that will vary from device-to-device and from different cloud services (and other factors), a cloud service will always be slower, sometimes significantly, from a local option. While this delay probably doesn't matter much for something like a garage door, it will matter greatly with this project. You don't want to flip the wall switch and have to wait 2-3 seconds (or longer) for the light to come on!
Parts list
There are other options (although the list is becoming smaller all the time), but I have selected these as known and easily flashable devices without soldering.
USB M-F Extension Cable (optional)
Note: the above are Amazon affiliate links. While this does not affect your pricing, this blog may earn a small commission if you make a purchase.
Again, there are many ways to tackle this project. For example, if you purchase the Shelly 1PM and a Shelly Smart Outlet, these both support MQTT for local control and Tasmota firmware flashing would not be required (nor would the last three items on the above list, as these are used for the flashing process). However, automations would be required in Home Assistant to keep the relay and outlet in sync. By using Tasmota, we will have the devices communicate directly with each other and stay in sync with no Home Assistant automations required.
Again, a smart switch could be substituted for the Shelly 1PM relay, however, it would still need to be flashable. Not only are these becoming rare as manufacturers continue to "shut out" the DIY cloud (they need your data to keep their business afloat, so most do not want you to convert to local control), but in many cases it requires tearing the device apart and soldering temporary wires to pins or pads on the switch. I selected the Shelly 1PM and the Sonoff S31 Lite because they are still flashable (as of the writing of this article) without soldering.
Again, many ways to accomplish the same end result. Adapt the information provided here for your own situation.
Tasmota flashing and setup
The information provided here is current as of January 2022. Later revisions of either the hardware or Tasmota firmware may require changes to the procedures listed. Refer to the Official Tasmota Site for the most current information.
Before installing the devices, we are going to flash the custom Tasmota firmware.
If your USB-to-TTL adapter has both a 5V and 3.3V setting, assure the device is set to 3.3V!!! Failure to do so will likely damage or destroy your device.
You will also need to connect male-to-female Dupont jumpers to the VCC, GND, TXD and RXD pins on the adapter.
Note: In most cases, you are going to need to connections to GND, since many devices require that your pull the GPIO0 pin to ground on boot to put the device into programming mode. The easiest way to do this is to create a "split" Dupont cable with one female and two male ends:
Just assure that the join between wires is secure. If you think you may be flashing additional devices in the future, I'd recommend soldering this connection and securing with shrink tubing. But for a one time use, you can just twist the wire together and maybe throw a little electrical tape on the junction.
Shelly 1PM
The Shelly 1PM provides pin headers specifically for flashing the device (thanks Shelly!).
Connect the male ends of the Dupont cables from the USB to TTL adapter to the Shelly pin headers according to the above diagram:
- GND and GPIO0 connect to GND
- 3.3V connect to VCC
- RXD connect to TXD
- TXD connect to RXD
Sonoff S31 Lite
Unlike the Shelly, the needed pins to flash the device are not exposed so we have to disassemble the device. But don't worry... the device is not glued together and we only need to remove three small screws to get access.
Begin by using a small screwdriver or spudger to pop off the gray end cap. This is not glued, but use caution and work your way around the edges so as not to break off the plastic tabs that keep the cap in place.
Once the cap is removed, two plastic rails will easily slid off the top and bottom, exposing the three small screws.
Use the properly sized screwdriver to remove these three screws. My experience is that these screws are factory installed very snug, so it may take a little work removing them the first time. Just be careful not to strip the screw heads.
After the screws are removed (be careful not to lose these tiny screws), the portion with the circuit board and prongs will easily lift out of the case.
The following connections to the USB to TTL adapter are made by clamping the opposite end of the hook clip to the male end of the Dupont cable:
- VCC to VCC
- GND to GND
- RX to TXD
- TX to RXD
Flashing
Your device should NOT be connected to mains or any other power source other than the USB-to-TTL adapter. Failure to follow this will likely result in destruction of your device and possible damage to your computer! Disconnect any other power sources from the device before proceeding!
There is a wealth of information on installing, configuring and setting up Tasmota on the Official Tasmota Website, so I will only be providing a high level overview of flashing and configuring these particular devices for this use case. Refer to the official site if you need or want additional details on installing, configuring and using Tasmota.
The process for both devices are nearly identical. Once wiring connections are complete, plug the USB-to-TTL adapter into the USB port of the computer that will be used to flash the software. Remember that for the Sonoff S31, you must press and hold down the button (GPIO0) while plugging the USB-to-TTL adapter into the computer.
Once the device is plugged into the computer, a new COM port should be found. Use your computer's device manager or equivalent to identify this COM port and note it.
If you are using a Chrome-based browser, you can flash Tasmota right from your browser. Just open the browser and navigate to https://tasmota.github.io/install/
Just follow the instructions on the screen. Standard Tasmota is adequate for this project. However, if you need or want to install a different version of Tasmota or do not have a Chrome-based browser, you can manually download the desired Tasmota .bin file and use a third-party flasher. See the Getting Started section of the Tasmota website for more information.
Initial onboarding (wifi)
Once flashing is successfully completed, the device will reboot and begin broadcasting a local access point (AP) named tasmota-XXXXXX_yyyy. You may need to disconnect and reconnect the device to your computer's USB port to reset it and exit programming mode.
Use your phone or other mobile device to join the broadcasting Tasmota wifi. If you are not prompted, open a browser and navigate to 192.168.4.1.
Enter in your local wifi network SSID and password and click 'Save'. The device will reboot and attempt to join your wifi. If successful, the following information will be displayed:
Note the newly assigned IP address as you will need this in the following steps or to access Tasmota on the device at a later time to make changes or upgrades.
Configuring Tasmota for the Device
This step may be completed while the device is still connected via USB or after you've applied mains power (again, never connect the device to mains power while it is still connected to USB!).
Browse to the IP address of the device in your browser. We are going to use a template for the device that has been created and shared on a repository site. While the template is different, the process is the same for both the Shelly and Sonoff devices:
Select Configure -> Configure Other from the menu:
On the Configure Other form, we need to copy and paste the appropriate template for the device from the Tasmota device repository:
Here are links to the templates for the two devices we are using. Just use the copy button in the template box at the bottom of the page and then paste into the template box of the Tasmota form:
Shelly 1 PM: https://templates.blakadder.com/shelly_1PM.html
Sonoff S31 Lite: https://templates.blakadder.com/sonoff_S31-lite.html
Be sure to check the 'Activate' box!
Enter a meaningful device name and friendly name in the provided boxes. These should be unique across all your Tasmota devices and will be used to create the device and entity in Home Assistant if auto-discovery is enabled.
Finally click 'Save'. The device will reboot and return to the main menu. If configured properly, you should see a toggle switch to turn the device off and on. If connected to mains power, you can toggle this switch and hear the relay and/or see an indicator light on the device change. For the Shelly 1PM, you will also see energy information. If you want to use the power monitoring information from the Shelly in Home Assistant or elsewhere, you should also complete the power calibration steps. This is beyond the scope of this article (and isn't needed for this project), but you can find information on power calibration on the official Tasmota site.
If you plan in integrating or using Home Assistant/MQTT, you should also complete the information for your MQTT broker on the Configuration -> Configure MQTT page. Again, refer to the official Tasmota site for details.
I would recommend connecting your devices to mains power at this point (if you haven't already) either in their final location or in a bench test (see the Wiring section below).
Defining Device Groups
There is one final configuration step we need to take on both devices to allow them to stay in sync without the use of Home Assistant or any other automations. I
This is accomplished by putting both devices into the same "device group" in Tasmota and enabling the option. This is done via command line in the Tasmota console... but it isn't difficult or scary!
From the main Tasmota menu, select 'Console':
You will see an output of information from your device and a box to enter commands:
SetOption85 1
This will enable Device Groups on the device
DevGroupName1 your_chosen_name
By setting both devices to the same group name (substitute your_chosen_name with a meaningful name to you, such as bedside_lamp), the devices will automatically stay in sync by sending all commands received by one to the other.
That's it! Those are the only commands you must enter. After entering the commands, the device may reboot. Once done on both devices, you should be able to bring up both web interfaces in different tabs or windows in your browser and see that when you toggle one device, the other device will toggle automatically to match the state! All this is done without MQTT, Home Assistant or creating any detailed automations.
There are many, many other options, settings and best practices for Tasmota. This just covers the basic minimums to complete this project. Please refer to the official Tasmota page for much more information.
MQTT Alternative (no flashing)
If you are using Shelly devices (or other devices that support MQTT for local control), you will obviously need an MQTT broker. This can be the Home Assistant MQTT add-on or a standalone broker. You will then need to configure the devices to connect to the broker.
You must then create at least two MQTT switches in Home Assistant... one for each device.
Finally, automations will need to be created so that when one device's state changes (e.g. turned on or off), the other device should be toggled to the same state. This is beyond the scope of this particular article, but here are a few links to get you started if you are going this route:
Wiring
ASSURE ALL POWER IS OFF TO THE LOCATION WHERE YOU WILL BE MODIFYING THE SWITCH! Even if the the power appears to be off, if your switch is in a double or triple gang box, there may be other circuits were the lines are still live. Use a voltage tester, multimeter or other device to assure no power is on anywhere in the box. Note also that the wiring colors listed are the U.S. standards:
Black: Line or load
White: Neutral
Ground: Green or bare copper
(Grounds won't be shown in the following diagram, as the Shelly 1PM does not provide a ground connection. If using a smart switch with a ground wire, connect it to the other grounds in the box).
Current configuration
Your current switch should have a wiring configuration similar to the following:
You should have black wires connected to the two terminals of your switch and a common neutral in the box.
Step 1 - bypass the switch
First, remove both black wires from the switch and tie these together, using a wire nut, Wago clip or other UL approved connection. At this point, we've just bypassed the switch and the wall outlet will now always be live, like any other unswitched wall outlet.
Step 2 - Add the Shelly Relay
Now we add the Shelly 1PM relay and connect it to both the power and our previous switch. Here are the Shelly 1PM terminals and their connection:
N - Connected to the common neutrals
L1 - Connect a lead to the the two black wires we joined together in step one.
L - Connect to one terminal of the existing switch (it doesn't matter which one)
SW - Connect to the other switch terminal
O - Not used. This would normally connect to the load, but isn't used here
Once these connections are made (and the Shelly 1PM and Sonoff S31 have been put into the same device group in Tasmota - see above), the light switch will now control and toggle the power to the Sonoff S31 switch. You can move the Sonoff S31 to any other wall outlet and the switch control will go with it. Furthermore, any vacated outlet will continue to work as a standard non-switched outlet. That's all there is to it!
Switch position does not match light state
But if this bothers you, you can easily fix it by opening up the Tasmota interface to the Shelly 1PM. Use the toggle button to set the on/off state to match the switch position. As long as you do not change the state of either the Shelly relay, Sonoff S31 or use the manual button on the Sonoff S31, the switch and on/off state should remain in sync.
However, if you do use Home Assistant, the Tasmota interface or other automation to change the state of either the relay or the plug, naturally the physical position of the switch will not change. Again, this doesn't affect the functionality of the switch, just its physical position. For us, we have so many 3-way and 4-way light switches throughout our house, the switch position ('up' for on and 'down' for off) is basically meaningless... just as long as flipping the switch toggles the light. But that is a personal call and decision.
Using a Smart Light Switch instead of the Shelly 1PM relay
Again, the load (normally the brown wire on a smart switch, but check the switch documentation) will not be attached to anything. Just cap it off with a wire nut.
Everything else is identical whether using the Shelly 1PM relay or the smart switch.
You can also replace the Sonoff S31 Lite with any other smart outlet, with the same caveats about flashing.
Optional Home Assistant Automations
If you are using Home Assistant and/or MQTT, the Tasmota devices should automatically be discovered. Once you configure/accept these devices, you can use the switches in any normal automations. You can toggle either the Shelly 1PM/smart switch or the Sonoff smart outlet (or both) in your automations, and due to the Tasmota device grouping, the other device will also toggle to stay in sync. As a general rule of thumb, I use the switch for my automations and rarely reference the Sonoff unless it is a special case.
Conclusion
While this might seem like a lot of steps and work to move a switched outlet to a different location, in all actuality, after you've done it once or twice, the entire project can be done in about an hour for less than $50. Compare that to either going up in the attic or down in the crawl space to reroute the actual circuits (or as in my case from the photo at the beginning where there is a second story above and a finished basement below... which would mean tearing out the drywall and replacing/refinishing) or to hiring an electrician to reroute the circuits, this is a simply and easy way to move any switched outlet to any other outlet in the house.
Links
Supporting this blog and related YouTube channel
If you'd like to support future content on this blog and the related YouTube channel, or just say thanks for something that helped you out, you can use any of my Amazon links to make a purchase at absolutely no cost to you. Or if you prefer to say thanks directly, you can buy me a one-off cup of coffee at:
No comments:
Post a Comment
To help eliminate spam and to keep all conversations civil, submitted comments are moderated. Therefore your post may not show up immediately. Please be patient as most reviews are completed within a few hours.