banner
Home / News / Build a Wi
News

Build a Wi

Jul 29, 2023Jul 29, 2023

Control your light or fan remotely with this DIY smart dimmer switch using an ESP8266-based board and Home Assistant.

A Wi-Fi-based smart light dimmer or fan speed controller allows you to control the light brightness, fan speed, or any connected AC load using your smartphone or web interface wirelessly. Although you can buy such smart light dimmers or fan regulators, they’re often expensive and require registration and an internet connection to work. This could be unreliable and may not work if the network connection is poor or the internet isn’t available.

To overcome this, you can build a DIY smart dimmer switch with an ESP8266-based board that works on the local network and doesn’t require the internet or your personal details to work.

Once you have gathered the required components, follow these steps to connect them and build a DIY dimmer module to control your light/lamp brightness and fan speed.

To compile the firmware, you need to install the ESPHome add-on in Home Assistant. The steps are as follows:

Just below the captive_portal:, paste the following code:

You can change id and name as per the device you want to control. We are using this dimmer to control a Symphony cooler fan's speed. min_power: is kept at 60% as the cooler responds or starts at a minimum 60% slider. You can remove this or adjust the value based on your device's response. The code should look something like this:

Once done, click Save > Install. Choose Plug into this computer and then wait for the compilation to finish. This can take up to 10 minutes.

Once the firmware is ready, click Download Project and save the firmware at any location.

To flash the firmware we compiled in the previous step on our D1 Mini or NodeMCU, download the ESPHome Flasher tool on your Windows or Mac system and follow these steps.

Refer to the diagram and connections table below to connect the RobotDyn dimmer module to your D1 Mini or NodeMCU board.

Also, connect the AC input to the AC-In terminals of the dimmer module and your fan or light bulb to the LOAD terminals. For instance, you can connect the two wires going to the light bulb or fan to the AC IN and then connect the fan or light to the LOAD terminals.

Once everything is connected, you can turn the AC power on and also switch on the D1 Mini power supply. In your Home Assistant, go to Settings > Devices and Services. Your dimmer module should be automatically listed under the Integrations tab. Click on Configure.

If the device is not discovered, you can go back to ESPHome, click on LOGS under the light-dimmer and note down the IP address. Then Go to Settings > Devices and click Add Integrations. Select ESPHome, paste the IP address, and click Connect.

Make sure you do not connect any load that exceeds 500-1000W (based on the TRIAC used). If you want to control heavier loads, you may build a DIY zero-cross dimmer module using a BTA41 that can be used to control loads up to 4000W with a suitable heat sink.

Setting up automations in Home Assistant is quite easy and can help you efficiently use your devices, thereby increasing their lifespan. Below is an example of an automation you may set up where the cooler fan speed goes down from 100% (for when you go to sleep) to 80% by 3:00 AM as the temperature drops.

Similarly, you can use automation to switch on the connected light(s) with 80% brightness at 7:00 PM, decrease it to 50% or lower (as per your needs) by midnight, and switch it off in the morning. You can set this for every day or particular days based on your needs.

You may install these to control multiple lights in your living room, kitchen area, or bedroom, and set automation to create an ambiance. For example, as you switch on your smart TV, the lights will auto-dim and the brightness will increase when the TV is off. You can also detect room presence to automate the smart dimmer switch. The possibilities with Home Assistant are endless.

You can also buy these dimmer modules in dual- or quad-channel versions to control up to four loads. However, if you need to control more than four different loads, you can buy more or build a DIY dimmer module and add as many channels as you want. Only one pin of the D1 Mini or NodeMCU is used for detecting zero-cross; the rest can be used to control the load.

The smart dimmer device we have built can help you save energy, reduce your electricity bills, and conserve fossil fuels. You can set up an automation in Home Assistant to automatically increase and decrease the bulb brightness (or fan speed), or switch it on/off based on the time of the day or as per your needs. It is estimated that regular dimming of your lights by 20-30% can easily cut down your electricity costs by 30% or more.

Ravi is an expert tech explainer, an IoT enthusiast, and a Linux lover with a background in big data and app development. He's a tech geek with over 7 years of experience in creating DIY tech and how-to guides on data recovery, file repair, Exchange Server, Outlook, Microsoft 365, Windows, Mac, Linux, iOS, and smart home.

Settings Add-OnsAdd-On StoreESPHomeStart Open Web UI+New Device ContinueNextESP8266Pick specific boardWemos D1 and Wemos D1 miniNextSkipEDITcaptive_portal:idnamemin_power:Save InstallPlug into this computer Download ProjectCOM BrowseFlash ESP ESPHome Home Assistant ONLINELOGSD1 Mini/NodeMCUDimmer ModuleSettings Devices and ServicesIntegrations ConfigureLOGSlight-dimmerIP addressSettings DevicesAdd IntegrationsConnectSUBMITSUBMIT Area FinishSettings Devices & Serviceslight-dimmerADD TO DASHBOARDNEXT ADD TO DASHBOARDOverview