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.
Things You Will Need
An ESP8266 board, such as NodeMCU or D1 Mini. A dimmer module. You may buy a RobotDyn dimmer module or build a DIY one that works with Arduino and ESP8266. DuPont wires. A micro-USB cable. Home Assistant server running on Raspberry Pi
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.
Step 1: Compile the Firmware
To compile the firmware, you need to install the ESPHome add-on in Home Assistant. The steps are as follows:
In the Home Assistant, go to Settings > Add-Ons and click Add-On Store. Search for and install the ESPHome add-on. After installation, click Start and click on Open Web UI. Click +New Device > Continue. Enter the device name (e. g. light-dimmer) and click Next. Choose the board from the options. If you are using an NodeMCU, select ESP8266. For D1 Mini, click Pick specific board and select Wemos D1 and Wemos D1 mini. Click Next. Once done, click Skip. Find the light-dimmer device and click EDIT. Insert your Wi-Fi SSID and password:
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.
Step 2: Flash the Firmware
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.
Connect the NodeMCU or D1 Mini board to your system using a micro-USB cable Launch the ESPHome Flasher tool, click the refresh icon, and choose the COM port. Click Browse to select the firmware file and then click Flash ESP. Wait for a few seconds. The firmware will be flashed and the output or logs will start displaying in the ESPHome Flasher tool. The device will connect to the Wi-Fi network. Once this is done, go back to ESPHome in Home Assistant and check light-dimmer is showing ONLINE. You may click on LOGS to check the logs and IP address assigned to the board. Once everything is verified and working, you may disconnect the board.
Step 3: Connect the Dimmer Module to NodeMCU or D1 Mini
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.
Step 4: Add Controls to Home Assistant
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.
Click SUBMIT. You may need to enter the Encryption Key (you can find it in the light-dimmer YAML code). Paste the key and click SUBMIT again. Choose Area and click Finish. Next, find the module in the ESPHome list under Settings > Devices & Services. Click on it (light-dimmer in our case). Click on the entity and then click ADD TO DASHBOARD. Choose a room and click NEXT > ADD TO DASHBOARD. You can now go to the room under Overview and click on the dimmer name to open the slider control. You can use this slider to control the connected load speed (fan or motor) or brightness (lamp). You can also use the toggle control to switch the connected load on/off.
Step 5: Set Up Automations
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.
Save Energy to Save Money
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.