Build a Wi-Fi based smart dimmer or fan speed controller


A Wi-Fi based smart dimmer or fan speed controller lets you control light brightness, fan speed or any connected AC load using your smartphone or web interface wirelessly . Although you can purchase such smart dimmer switches or fan controllers, they are often expensive and require registration and an internet connection to operate. It may not be reliable and may not work if the network connection is poor or the Internet is not available.

To overcome this, you can build a DIY smart dimmer with an ESP8266-based board that works on the local network and does not require the Internet or your personal data to operate.

Things you will need

  • An ESP8266 board, such as NodeMCU or D1 Mini.
  • A dimmer module. You can buy a RobotDyn dimmer module or build a DIY one that works with Arduino and ESP8266.
  • Son DuPont.
  • A micro USB cable.
  • Home Assistant server running on Raspberry Pi

Once you’ve 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.

Step 1: Compile Firmware

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

  1. In the home assistant, go to Settings > Additional modules and click Complementary store.
  2. Find and install the ESPHome To add.
  3. After installation, click Begin and click on Open Web UI.
  4. Click on +New device > Continue.
  5. Enter the device name (e.g. dimmer) and click Next.
  6. Choose the table from the options. If you are using a NodeMCU, select ESP8266. For D1 Mini, click Choose a specific table and select Wemos D1 and Wemos D1 mini. Click on Next.
  7. When finished, click Skip.
  8. Find the dimmer switch and click EDIT.
  9. Insert your Wi-Fi SSID and password:


ssid: "MyWiFiName"
password: "MyWIFiPassword"

Just below the captive portal:paste the following code:

- platform: ac_dimmer
id: symphony_cooler
gate_pin: D1
number: D2
min_power: 60%
- platform: monochromatic
output: symphony_cooler
name: Symphony Cooler

You can change identifier and Last name depending on the device you want to control. We use this dimmer to control the speed of a Symphony cooler fan. power_min: is held at 60% when the chiller responds or starts to a slider of 60% minimum. You can remove it or adjust the value based on your device’s response. The code should look like this:

When finished, click to safeguard > Install. Picking out Log into this computer then wait for the compilation to finish. It may take up to 10 minutes.

Once the firmware is ready, click Download the project and save the firmware to any location.

Step 2: Flash the firmware

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

  1. Connect the NodeMCU or D1 Mini board to your system using a micro-USB cable
  2. Launch the ESPHome Flasher tool, click the refresh icon and choose the COM Port.
  3. Click on Browse to select the firmware file, then click Flash ESP.
  4. Wait a few seconds. The firmware will be flashed and the output or logs will start showing in the ESPHome Flasher tool.
  5. The device will connect to the Wi-Fi network. Once done, return to ESPHome in home assistant and verify that the dimmer is displayed ON LINE. You can click NEWSPAPERS to check the logs and the IP address assigned to the card.
  6. Once everything is checked and working, you can disconnect the board.

Step 3: Connect dimmer module to NodeMCU or D1 Mini

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

D1 Mini/NodeMCU Dimmer module
5V or V VDC
g Earth

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

Step 4: Add commands to Home Assistant

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

If the device is not discovered, you can return to ESPHome, click NEWSPAPERS under the dimmer and note it IP adress. Then go to Settings > Devices and click Add integrations. Select ESPHome, paste the IP address and click Relate.

  1. Click on SUBMIT. You may need to enter the encryption key (you can find it in the YAML code of the dimmer). Paste the key and click SUBMIT Again.
  2. Picking out Area and click Finish.
  3. Then find the module in the ESPHome list under Settings > Devices and Services.
  4. Click on it (dimmer in our case).
  5. Click on the entity and then on ADD TO DASHBOARD.
  6. Choose a room and click NEXT > ADD TO DASHBOARD.
  7. You can now go to the room under Insight and click on the dimmer name to open the fader control. You can use this slider to control the speed of the connected load (fan or motor) or brightness (lamp).

    You can also use the toggle control to turn on/off the connected load.

Make sure not to connect any load greater than 500-1000W (depending on the TRIAC used). If you want to control heavier loads, you can build a DIY zero cross dimmer module using a BTA41 which can be used to control loads up to 4000W with a suitable heatsink.

Step 5: Set up automations

Setting up automations in Home Assistant is pretty straightforward and can help you use your devices efficiently, increasing their lifespan. Below is an example of an automation you can set up where the cooler fan speed goes from 100% (when you go to bed) to 80% at 3:00 a.m. when the temperature drops.

alias: Cooler
description: ''
- platform: time
at: '03:00:00'
condition: []
- device_id: ffa25bd424ab6fc99a46286e8148ef5b
domain: light
entity_id: light.symphony_cooler
type: brightness_decrease
- type: turn_off
device_id: ffa25bd424ab6fc99a46286e8148ef5b
entity_id: light.symphony_pump
domain: light
mode: single

Similarly, you can use automation to turn the connected light(s) on to 80% brightness at 7:00 p.m., dim it to 50% or less (depending on your needs) at midnight, and turn it off in the morning. You can set it for every day or certain days depending on your needs.

You can set them up to control multiple lights in your living room, kitchen, or bedroom, and set the automation to set the mood. For example, when you turn on your smart TV, the lights automatically dim and the brightness increases when the TV is off. You can also detect the presence of the room to automate the smart dimmer. The possibilities with Home Assistant are endless.

You can also purchase these dimmer modules in two- or four-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 dimming module and add as many channels as you want. A single pin of the D1 Mini or NodeMCU is used to detect the zero crossing; the rest can be used to control the load.

Save energy to save money

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


Comments are closed.