Control Your Christmas Lights with a $5 Raspberry Pi Zero and Plugable Bluetooth Switches

The Holidays are upon us, and with it come the sights and sounds of the special season—sleigh bells, Santa Claus, chestnuts roasting by the fire, and colorful displays of Christmas lights! Here at Plugable we can’t do much about the bells and the chestnuts, but we definitely have some ideas about the lights.

We’ve put together a fun Python project that will allow you to go wild with multiple strings of Christmas lights and other decorations, using just a five dollar Raspberry Pi Zero, a Plugable USB-BT4LE Bluetooth adapter and one Plugable Bluetooth Home Automation Switch for each decoration you want to control. It also works with a Raspberry Pi B+ or Pi 2.

The concept is simple: Plugable Bluetooth home automation switches allow you to freely switch on and off any house-current-powered device within Bluetooth range. The Raspberry Pi is a cheap, simple little computer that can talk to the switches. Put them together, and you have a setup that gives you Ultimate Power over your display.

Plugable Christmas Lights

Plugable Christmas Lights

The Pi connects and controls the switches through the Plugable Bluetooth adapter. A Plugable Wifi adapter connects your Pi to the home network. Using ssh, you can control the Pi and change the setup from any computer on your network or use a phone or tablet to create a Couch Christmas Command Center in your living room.

What you’ll need

Set it up!

To set it up, just do these steps:

Put up your Christmas display

You can go wild with this. Use your artistic decorating skills (or lack of them) to arrange the lights in a pleasing manner that will look absolutely insane when you begin turning them on and off in random ways.

Connect your switches

Since the range of Bluetooth is limited, the AC connection for each string must be within 30 feet (10 meters) of the Bluetooth adapter. Closer is better. Plug each decoration into its own Bluetooth switch, using extension cords if needed. A maximum of seven switches can be used. AC power and wet weather don’t play well together, so you’ll want to have the Bluetooth switches in a sheltered location out of the rain and snow.

Set up your Pi

Connect your Pi to a monitor and plug in a keyboard and mouse (using an OTG cable and hub with a Pi Zero). Plug in the Bluetooth adapter and WiFi adapter (if using one). Download the Raspbian Jessie image from the Raspberry Pi website and install it on a micro-SD card. Put it in the Pi, and start it up. Establish an internet connection (click the network icon at the upper-right of the Pi’s desktop for WiFi), then open a terminal window and type the following commands to make sure your Pi is up to date:

sudo apt-get update
sudo apt-get upgrade

Issue the following command to make sure the Pi sees the Bluetooth adapter:

hcitool dev

You should get a response with the Bluetooth address of the adapter. If this doesn’t work, then issue the following (with an internet connection present):

sudo apt-get install rfkill
sudo rfkill unblock bluetooth
sudo hciconfig hci0 up

Then try the hcitool dev command again.

Place your Pi in a sheltered place within Wifi range (or near an Ethernet cable) and within 30 feet (10 meters) of each switch. If the Pi is too far away, you can use a Plugable 10-meter USB extension cable to bring the Bluetooth adapter closer to switches. After setting up the Pi, it won’t need a dedicated keyboard or monitor if you use ssh to connect from another computer on your network.

Download and use the Python script

The Python code for this project is meant as a starting point for your own experimentation. We assume you know Python. If you don’t, there are many great online tutorials. The code contains a collection of functions that allow your Pi to discover nearby Plugable switches, give them names, and connect to them. Other functions give examples of using loops and other methods to create patterns and wildly random displays. It’s pretty primitive, but should give you some ideas. While I have deliberately kept it simple to encourage experimentation, I’ll probably be adding some improvements like exception handling in the next few days.

The script is shown in the window below. To put it on your Pi, start its web browser and open this same blog post in it. Right-click the following link:

Download Script

Select “Save Link As…” and in the window that appears, change the name of the file to

Click Save. The file will be saved in your home directory.

To run the script from the desktop on your Pi, just double-click on the file in the file manager, or type the following in a terminal window:


This will open the file in Idle, a simple Python IDE. Select Run > Run Module to execute the file. This will open a shell window. At the Python prompt type:

results = setUpSwitches()

Detailed instructions and a description of each function are given in the comments in the code.

Running from the command line or using ssh

Once you have written some functions of your own, you can run the program directly from the command line and avoid the graphical user interface, or use ssh to access your Pi remotely from a computer or Android/iOS device on your network. The disadvantage to this is you won’t have the file open to see the functions that are there. To do this, just type the following at the command prompt in the directory where the software is saved:


In the Python shell, load the code by typing the following:


To connect to your devices, type:

results = setUpSwitches()

Once that process is complete, you can execute the functions included in the script or write your own.

Have Fun!

We hope you have fun with this! We would love to hear about the cool projects you create. Please tell us in the comments below!

From all of us at Plugable, we wish you a wonderful holiday season and a happy New Year!

3 comments on “Control Your Christmas Lights with a $5 Raspberry Pi Zero and Plugable Bluetooth Switches”

  1. udai

    What and how are things connected to the pi zero? (I understand the pi zero has just one micro USB port for data)

  2. Michael


    I am trying to find a way to make it so I can use the Rasberry pi and Bluetooth and also a RBG or RBGW controller to use some RBGW led light strip for my wheelchair. I was thinking Bluetooth because the wifi controller would need the internet and that wouldn’t work unless I can use my smartphone 🙂 Can someone help with this? I have everything even a battery.


Comments are closed.