In this guide, you will learn to build DIY smart switches that you can control using an app, web browser, or voice commands via an Alexa smart speaker, such as Echo dot. You may also password-protect these DIY smart switches for added security and prevent unwanted users from accessing or controlling them even when connected to your local Wi-Fi network.

You can further integrate these DIY smart switches with Home Assistant or HomeKit to add automation based on time of the day or data received from other compatible smart sensors that you may have installed in your home or office.

Why Build DIY Smart Switches?

Although you can buy smart switches online that work out of the box, integrates with Alexa and Google Assistant, etc., most lack manual control or override, meaning you can only switch them ON/OFF using the app. This makes it inconvenient for many users, especially old family members or someone who is not tech-savvy.

However, the ones that come with manual override control cost you extra bucks. More importantly, these switches also require you to sign up and share your data with their cloud servers. Every time you switch on or off the device, the information is logged and travels through the manufacturer’s cloud server. This also slows down the response time, and it won’t work if the internet is down.

However, when you build one yourself, your activities are not recorded or logged anywhere. It’s local, faster, and works irrespective of internet access. Thus, if you consider privacy, follow this guide and "Do It Yourself."

Your devices and activity data are completely local and not recorded or logged if you don’t use it with Alexa or Apple Homekit. Integrating the DIY smart switches and sensors with these services allows you to control your devices from the internet at the cost of sharing the activity data.

Steps to Build DIY Smart Switches

Follow the instructions below to build your DIY smart switches and deploy them to control various appliances.

Things You Will Need

  • A NodeMCU, ESP-01, or D1 Mini board.
  • A relay module. Depending on how many switches you want to automate, you can purchase a single, double, quad, or higher channel relay module. You may also build a solid-state relay by yourself.
  • A 220V to 5V Hi-Link or similar power supply module. You may also use a micro USB to supply a 5V power supply.
  • A micro USB cable.
  • A 3D printed case to enclose all components (optional). You may also use any generic box that fits the DIY smart switch.

If you want to use ESP-01, then also purchase additional components mentioned below:

  • A Micro USB module.
  • A 5V to 3.3V voltage regulator.
  • A CH301 module to flash the firmware.
  • A general PCB to solder these components.

Step 1: Flash the Firmware

To build a smart switch compatible with Alexa and other home automation software, we will use the Tasmota firmware. It’s a tried and tested firmware that works reliably with ESP8266 boards, such as NodeMCU, ESP01, D1 mini, etc. We are currently using them in a production environment to control various appliances, such as lights, fans, water pumps, TV, etc., for the past 3-months without any issues or complaints.

flashing tasmota firmware on esp8266 nodemcu d1 mini
  1. Download the Tasmotizer tool and the Tasmota.bin firmware file.
  2. Launch Tasmotizer and connect the NodeMCU or D1 Mini to your PC using the Micro USB Cable.
  3. Select the COM port and click Browse to select the Tasmota.bin firmware file.
  4. Click Tasmotize and wait for the flash process to complete.
  5. After Flashing, click Send Config.
  6. Enter the WiFi SSID and password and click Send Config.
  7. The device will connect to your WiFi network.
  8. Click Get IP to view the IP address and copy it.

That's it. Now, you can move on to configuring the smart switch.

Step 2: Configure the Switch

Open a web browser window on your PC and enter the copied IP address. This will open the Tasmota web page. Now, follow the steps below:

configure the diy smart wifi switch settings tasmota web
  1. Click Configuration> Configure Module.
  2. Choose Generic (0) from the Module Type drop-down and click Save.
  3. The device will restart and auto-reload the web page. Click Configuration> Configure Module.
  4. Select Relay 1 in GPIO4 and Switch 1 on GPIO5 and click Save.
  5. After the restart, you will see a toggle switch to turn On or Off. This will control a single channel relay. To build a smart switch with more than one channel relay, you need to choose Relay 2, Relay 3, Relay 4 and Switch 2, Switch 3, and Switch 4 in the GPIOs.
add more relays manual control diy smart switch

Once done, save the changes and disconnect the USB cable.

Step 3: Connect the Relay Module to the Board

Refer to the following diagram to interface the relay module with the NodeMCU or D1 Mini using a jumper or DuPont wires. You can power this using any 5V smartphone adapter and micro USB power supply.

connecting relay module with nodemcu

If you are using a 220V to 5V power supply module, the connections are as follows,

connecting relay module power supply 220v 5v nodemcu

Step 4: Switch On and Test

Once everything is connected, you can supply the power to turn on the DIY smart switch. Once on, visit the same IP address and use the switch to turn it on/off. The relay should switch on/off as you press the toggle switch on the web page.

We recommend assigning a static IP to your device via DHCP IP reservation in your router setting. This will keep the IP same always.

If the test is successful, you may enclose it in a 3D-printed case. You can find many of these cases on Thingiverse based on the relay module you have used.

Step 5: Enable WeMo Switch Emulation for Alexa Integration

You can emulate your smart switch as Philips Hue or WeMo device, natively compatible with Alexa. The steps are as follows:

  1. Open the Tasmota web page using the device IP address and click Configuration> Configure Other.
  2. Tick the Belkin WeMo single device option and then click Save. If you are using two or more channel relay modules, enable Philips Hue multi-device emulation.
enable belkin wemo or philips hue emulation for alexa support

Step 6: Add Smart DIY Switch to Alexa

Configuring your new DIY smart switch with Alexa is a fairly easy process. Here's what you need to do:

  1. On your Alexa app, go to Devices and tap on the + icon at the top
  2. Choose Add Device.
  3. Select Switch > Other and then click Discover Devices.
  4. Wait for the process to complete. It will take approximately 2 minutes.

You may also ask Echo or Alexa-enabled smart speaker—Alexa, discover devices. This will automatically find your smart DIY switch and list it under the Device. You can now control this DIY smart switch using a voice command or the Alexa app. Just make sure both devices are connected to the same network.

Further, you can automate your home or office by installing such DIY switches and using the Alexa routine. Here’s a detailed guide on setting up home automation using Alexa App.

Alternatively, if you want to keep your activities private, set up a Home Assistant server for home automation. It will also enable you to use the Smart DIY switches with Apple HomeKit or Eve app on iOS, iPadOS, and macOS devices.

Smart Home With Added Privacy

DIY smart switches do not require you to sign up for any service. It’s completely local and thus, does not record or log your activity data anywhere. And instead of relying on Alexa for home automation, you can set up a local Home Assistant server, add your DIY or purchased smart switches, and control them all from one dashboard.

You may also create multiple rooms, group devices, and add automation without worrying about your data. Everything works locally, and your data never leaves your premises.