Automating your home's lighting is an easy and affordable way to add smart home functionality. With a DIY smart light switch, you can control lights with your voice or a smartphone app for under $20. Here is a step-by-step guide to build your own smart light switch using basic components.

What You'll Need

Building a DIY smart light switch requires just a few components that can be purchased online for very low cost. Here's what you'll need:

In total, these components can be purchased for around $15-$20 on sites like Amazon or eBay. No soldering is required!

Assembly Steps

Building the smart switch is straightforward with just a few simple steps:

1. Connect the ESP8266 to the relay module

Use jumper wires to connect the ESP8266's GPIO 0 pin to the relay's IN pin. This allows it to control the relay. Also connect the GND and VCC pins between the modules.

2. Connect the relay to the light switch

The relay module has a NO/C/NC side. Connect the C (common) pin to one pin on the light switch. Connect the NO (normally open) pin to the other.

3. Mount the components in the enclosure

Place the ESP8266, relay module, and light switch into the plastic project box. Drill holes to mount the light switch and for connecting wires.

4. Connect wires from the wall to the relay

Connect the live wire from the wall to the C (common) pin on the relay. Connect the wire to the light fixture to the NO (normally open) pin.

5. Power the ESP8266 with a USB cable

Supply power to the ESP8266 by plugging in a USB cable. The other end can plug into a phone charger or USB port on a computer.

That completes the physical assembly! Now it's just a matter of programming the smart switch's behavior.

Programming the Smart Light Switch

To program the DIY smart switch, you'll need to install custom firmware on the ESP8266 WiFi module. Here are the steps:

1. Install ESPHome firmware

ESPHome is a popular open-source firmware for ESP8266-based devices. Follow their guide to get it installed.

2. Configure the firmware

Use ESPHome's web interface to configure the firmware. This involves naming your node, setting up WiFi credentials, and defining components.

3. Program basic light automation

Under components, add a Toggle to represent the physical light switch. Also add a Binary Sensor to track its state. Then create an Automation to turn the light on when the switch is toggled on, and off when toggled off.

4. (Optional) Add voice control

Integrate with Google Assistant or Amazon Alexa using ESPHome's integrations. Then add voice command triggers to control the light. Like "Alexa, turn on the living room light".

5. Upload the firmware

Finally, upload the configured firmware to the ESP8266 module through USB. The smart switch will now work!

The automation capabilities are endless - you can add schedules, scenes, notifications, etc. But the basics above are all you need to get started with DIY voice-controlled lighting.

Troubleshooting Tips

Here are some troubleshooting tips if your DIY smart switch isn't working:

With a little tweaking, you should be able to get the switch working reliably as a unique smart home project!


Building your own DIY smart light switch is an easy and fun way to add home automation. The ability to control lights with your voice or smartphone app provides a lot of convenience. This project can be completed for less than $20 with basic technical skills. As you enhance the switch's capabilities over time, you'll wonder how you ever lived without it! With the steps provided, you'll be automating your home's lighting in no time.