ESP8266 and NodeMCU: A Cost-Effective Ceiling Light Control Solution

I’ve been on a quest to find a reliable and budget-friendly way to control my ceiling lights through Home Assistant while still maintaining the convenience of traditional wall switches. After some trial and error, I’ve come up with a setup that I’m really happy with, and I’d love to share it in case it helps anyone else!

The Challenge

As many of us have discovered, pulling out your phone to turn on a light just isn’t very convenient. Plus, smart bulbs can be expensive, especially when you have multiple fixtures to update. They also often require the switch to be in the ‘on’ position for wireless control, which wasn’t ideal for me.

The Solution

I decided to go with an ESP8266-based microcontroller (specifically a Wemos D1 Mini or NodeMCU) controlled via MQTT. The idea is to use the microcontroller to handle the switching of the live feed for the lights, while the wall switches simply communicate with the microcontroller.

Here’s how it works:

  • The live feed for the lights runs through a relay on the microcontroller.
  • The wall switches are rewired to send 3.3v DC signals to the microcontroller instead of directly controlling the live feed.
  • This setup means the switches don’t handle any high voltage, making the installation safer and easier to undo if needed.

The Setup

The installation was surprisingly straightforward. I simply had to reroute the live feed, place the relay on the live side, and connect the switch wires to the microcontroller. No new cables were needed, and it’s easily reversible if I ever move.

The Software

I developed some code using great libraries to handle the MQTT communication and switch control. The code is available on my GitHub page for anyone who wants to take a look or adapt it for their own use. Some key features include:

  • Basic control via MQTT commands (e.g., “1” to turn on, “0” to turn off).
  • Automation triggers with a double toggle of the switch.
  • Automatic recovery and offline mode, which has been invaluable for maintaining functionality during network outages.

The Results

After running this setup for over six months, I’ve been really impressed with its reliability. The lights recover smoothly from router restarts, network outages, or power cuts. The automatic recovery and offline mode have been especially useful, ensuring that my girlfriend (and I!) never get caught in the dark due to a technical issue.

Final Thoughts

This project has been a fantastic way to integrate smart lighting into my home without breaking the bank or sacrificing the convenience of traditional switches. I’d love to hear if anyone else has tried something similar or has any questions about the setup!

Happy tinkering! :rocket: