Triangular wall shelves under a sloped ceiling, each shelf lit by a string of warm fairy lights.

# Christmas lights hack

Table of Contents

A project to bring a little more mood lighting to my room. Originally I had one Ikea light which was just a little too bright. So I decided to buy cheap Christmas lights, but these required batteries and had to be switched off individually, too much effort. So I hacked them by cutting off the batteries and connecting them to an ESP controller such that I could control them via Home Assistant with just one button press.

Before and after

Triangular wall shelves lit only by a single bright lamp on the bottom shelf
Before: one Ikea lamp, a little too bright

The same shelves lit evenly by strings of warm fairy lights on each shelf
After: fairy lights on every shelf

Shopping list

Itemqtyprice
Wemos D1 mini1 x1.50 €
2N2222 transistor3 x0.10 €
1k resistor3 x0.10 €
30x15mm perfboard1 x0.20 €
DC-DC Buck converter1 x0.30 €
Wire
Christmas lights3 x~1.80 €

Tools

  • Soldering essentials
  • 3D printer

Build log

Every good project of course starts off with a good plan. For this I drew a circuit, which I then tried on a breadboard which seemed to work fine. Initially without resistors, but this caused the ESP to heat up.

The circuit design works as follows. There are three LEDs placed before transistors. These transistors control the flow and allow us to digitally switch the LEDs. The transistors are connected to GPIO 5-7 with a resistor to limit the current. The LEDs are powered from a DC-DC buck converter to provide them with 4.5 volts, equivalent to 3xAA. The buck converter is connected to the 5V and ground pins.

Hand-drawn schematic on grid paper: three LEDs switched by transistors with 1k base resistors on GPIO 5, 6 and 7, powered by a buck converter from 5V
The circuit plan

Construction

Solder side of the perfboard with resistors and yellow, red and black jumper wires, next to a Wemos D1 mini
The solder side, a bit of a mess

It became a bit of a mess because I mirrored the pins incorrectly at first. After that I also had to add resistors to the already finished board. But everything still fitted within the footprint and I called it good enough.

Component side of the perfboard with female headers and the buck converter soldered flat, next to a Wemos D1 mini
Headers and the buck converter

On the other side are all the headers and the buck converter. The buck converter is soldered to the board to make it more low profile and fit under the ESP. On the converter the traces at adjust are connected, allowing me to turn the potentiometer on the other side to set the voltage. This was set to 4.5V. The top headers allow us to plug in the Christmas lights.

A string of fairy lights with its battery pack holding three AA batteries
The cheap battery-powered Christmas lights

Then the lights. These are cheap store-bought Christmas lights. All we have to do is cut off the battery pack and connect a male header to them. I used these connectors because these were the smallest connectors I had around. I also created some wire extensions to connect the light to the controller. These are just simple wires with headers connected to them.

A white 3D-printed box and a red lid with a cut-out logo, next to the assembled controller
The 3D-printed enclosure

Then it is time to create an enclosure. The electronics are just housed in a simple box with two holes. One for the USB and the other for the light. The logo is cut out to allow more heat to escape, and it looks nice as well.

Home Assistant

Now that the construction is finished we can add the code. Since we will use this as an integration with Home Assistant, we can use ESPHome, which allows us to define its functions with just one YAML config.

christmas_lights.yaml
esphome:
name: christmas_lights
platform: ESP8266
board: d1_mini_lite
wifi:
ssid: "WIFINAME"
password: "PASSWORD"
# Enable fallback hotspot (captive portal) in case wifi connection fails
ap:
ssid: "Christmass Ligths"
password: "FALLBACKPASSWORD"
captive_portal:
# Enable logging
logger:
# Enable Home Assistant API
api:
ota:
output:
- platform: esp8266_pwm
pin: 12
frequency: 1000 Hz
id: pwm_output0
- platform: esp8266_pwm
pin: 14
frequency: 1000 Hz
id: pwm_output1
- platform: esp8266_pwm
pin: 13
frequency: 1000 Hz
id: pwm_output2
light:
- platform: monochromatic
output: pwm_output0
name: "shelfTop"
- platform: monochromatic
output: pwm_output1
name: "shelfMiddle"
- platform: monochromatic
output: pwm_output2
name: "shelfBottom"

With that flashed we can now use our new smart lights. I use the lights with an automation which turns them on when the sun is down. But there can be many examples of interesting use cases.

My avatar

Thanks for reading my blog post! Feel free to check out my other posts or contact me via the social links in the footer.


More Posts

Comments