HTTP Controlled WS2811 Lights on Raspberry Pi. Built using go, tmepl, and HTMX.
This project was create to enable control over the lights in my cubicle and on my Chrismas tree.
The entire project is run on a Raspberry Pi. When on your local network, requests are fulfilled nearly instantly. For public access, you can setup a VPN between the Pi and a VPS running a reverse proxy. With this setup, you can also enable SSL using certbot. This adds some latency, but is still fairly responsive.
- The interface is served using templ, with HTMX for some interactivity
- Presets are stored in a PostgreSQL database, running on the Pi
- Presets support a dynamic number of colors
- While an admin mode does not exist, you can manually update the protected column in the presets table to write protect a preset
- Attempts to update the status of the lights are stored in the logs table, as well as if the request was successful
- A Raspberry Pi running Raspberry Pi OS Lite
- WS2811 Addressable LED lights (ensure they that are the 5V model to work with the Pi)
- A 5V power supply with enough amperage to power your lights.
- The required misc parts to connect everything
Connect the striped ground from the light string to ground on the Pi, and the center data pin on the light string to pin 12 on the Pi.
Connect to your pi, and run the following commands.
sudo apt install golang git cmake
go install github.com/a-h/templ/cmd/templ@latest
go install github.com/pressly/goose/v3/cmd/goose@latest
The rpi_ws281x library is required to enable support for the ws2811 lights. Use these steps to build the library, or read the official docs.
git clone https://github.com/jgarff/rpi_ws281x
cd rpi_ws281x/
mkdir build
cmake -D BUILD_SHARED=OFF -D BUILD_TEST=ON ..
sudo make installcd ~
git clone https://github.com/Rodabaugh/weblights
cd weblightssudo apt install postgresql
sudo passwd postgres
# Enter password for postgres user
sudo -u postgres psqlCREATE DATABASE weblights;
\c weblights
ALTER USER postgres PASSWORD '(YOUR DB PASSWORD HERE)';
exitcd sql/schema/
~/go/bin/goose postgres "postgres://postgres:(YOUR DB PASSWORD)@localhost:5432/weblights" up
cd ../..Next, create a .env file in the project dir and configure as shown below.
nano .envBe sure to enter the number of LEDs that you have, and your database creds.
PLATFORM=prod
NUM_LEDS=50 (or your number of LEDs)
DB_URL="postgres://postgres:(YOUR DB PASSWORD)@localhost:5432/weblights"
make build
sudo make installCheck to see the service is running using systemctl status weblights.service
On another device go to http://(The IP for your Pi):8080. You should see the weblights UI.
From here, I recommend setting up a wireguard VPN between your Pi and a public VPS. Then you can configure an nginx reverse proxy on the VPS and certbot, to provide public access to the weblights UI. This is out of scope for this guide, but information on this is easily found.