To make a home smart, you need smart switches and sensors for control over Wi-Fi, RF or Zigbee connections. There are several brands that offer smart switches that you can easily extract and deploy using their cloud services.
But if you want to build a smart home that’s completely private, you don’t want to be dependent on a third party. You never know when they might shut down their cloud services. Safety and reliability are therefore major concerns. Fortunately, building smart switches that work with Alexa and smart home automation software, like Home Assistant, is a lot easier.
What you need to build a smart switch
Let’s say you want to build a 5-channel smart switch that you can use to control up to 5 different devices of up to ~2 amps at 220V or 110V. To build this smart switch you will need:
- A D1 Mini
- One Hi-Link 5V 5W or 10W PSU
- Two 6-pin screw terminals
- One 2-pin screw terminal
- Five 220Ω ¼ watt resistors
- Five 1 KΩ ¼ watt . resistors
- Five MOC3021 optocoupler ICs
- Five Triacs, such as BTA12, BTA16 or similar. We have used the BTA16.
- One fabricated or generic PCB to assemble and solder all components
- Soldering iron and tin
- Wires to connect your load
We’ve already designed the PCB and did the hard part (new and improved). All you have to do is download the Gerber file, which you can use to print or fabricate your PCBs from any PCB manufacturer or supplier. FYI, we fabricated 10 PCBs for $7 and paid $5 for shipping.
Solder the components on the PCB
Mount all components on the PCB as shown on the PCB. You can also use general PCB and follow the connection diagram below to manually assemble and solder all components.
Do not mount or solder the D1 Mini directly to the printed circuit board. Follow these instructions to mount the D1 Mini to the circuit board.
- D1 Mini comes with male and female mountain strips. Solder the male mountain strip to D1 Mini.
- Solder the female mountain strip to the PCB where we need to place the D1 Mini.
- Place the D1 Mini on the female strips soldered to the circuit board to mount it to the board.
This will help you quickly disconnect or replace the D1 Mini if it fails.
If you don’t know or have never soldered, we highly recommend that you learn how to solder before proceeding.
Flash the firmware
Once the components are mounted and soldered to the circuit board, follow these steps to download, flash, and configure the firmware on the D1 Mini to control the 5-Solid State relay on the board.
- Download the Tasmota firmware (tasmota.bin file) on your system and install the Tasmotizer Tool (only available for Windows). You can also use ESPHome Flasher tool if you are using macOS or Linux.
- Launch the Tasmotizer tool and connect the D1 Mini to your PC using the micro USB cable.
- Click on the Refresh knob.
- Select the COM port to which the D1 Mini is connected.
- Click Open and then browse the Tasmota firmware you downloaded (.bin file).
- Click Tasmotize. Wait for the process to complete. It takes less than a minute to complete.
- Once the flashing is complete, click the Send configuration knob.
- Select Wi-Fi and enter the SSID and password of your Wi-Fi network.
- Click Module/template and choose General.
- Click Save. You will see a message ‘Configuration sent. Device is rebooting.’
- Click on the Get IP button after a few seconds. This will show you the IP address of the device when it has successfully connected to your network.
- Open the web browser and enter this IP. It opens the Tasmota web interface.
If you like, you can also build a single-channel solid-state relay or DIY Alexa-supported single-channel smart switch.
Configure the DIY Smart Switch
Once the Tasmota web interface (web user interface) opens, follow the steps below to configure the 5 switches for Wi-Fi and Alexa control.
- Click Configuration > Configure module. Then refer to the screenshot below to view the . to choose Relay and Switch options followed by the channel number.
- After you have selected all required channels for: Relay and Switch options, click Save. The device saves the configuration and reboots. The web interface is automatically refreshed.
- You will see 5 controls on the Tasmota web user interface. These can be used to activate and control the solid state relays on the board to turn the connected load ON/OFF.
- 1 indicates the switch is ON while: 0 indicates FROM.
Enable Alexa support
Follow these steps to control this smart 5 channel smart switch with Alexa:
- In the Tasmota Web UIClick Configuration > Configure others.
- In the Device namegive your smart switch a fancy name like Smart switch in the living room. Also enter the name of the 5 devices you will control with this DIY smart switch. Since we use it for lighting controls, we named them accordingly.
- Make sure you have the . select Hue Bridge radio button and then click Save.
- The device will reboot. You can now ask your Echo device to discover devices with the command ‘Alexa, discover devices.’ You can also use the Alexa app > Devices to add these DIY smart switches.
- The devices will display the name you entered in the Friendly Name field in the Tasmota Web UI. However, you can edit or change the names in the Alexa app as you wish. They are recognized as Smart device from Royal Philips Electronics.
- Now you can control the smart switches with the Alexa app or with your Echo device. Just say, ‘Alexa, turn on the Led Strip.‘
Add to Home Assistant
To add this DIY smart switch to Home Assistant (HA), you need to enable the MQTT on Home Assistant and then enter the MQTT details through the Tasmota Web UI by following these steps:
- In the Tasmota UI, click Configuration > Configure MQTT.
- Enter the Host IP (your HA IP), User, and password. Keep other stuff as default and click Save.
- If auto-detection is enabled on your HA (it is by default), you will see the 5 new smart switches in Settings > Devices and services.
- You can select and add them to your HA dashboard and control the switches directly from the HA web user interface with real-time status updates from the switch.
Deploy silently DIY and private smart switches
You can build and use this 5-channel smart switch to control your fan, lighting or other home appliances that require up to 200-300 watts of power. Because we built this switch with Solid-State Relays (SSR), this switch works quietly without clicking noise. Plus, you can control them locally, even when there’s no internet, or, if you’re connected to the internet, from anywhere in the world using the Alexa app.