MagicMirror Module to control a led strip attached to a Raspberry Pi
This module is specifically meant for the Raspberry Pi system, using SPI and a LPD8806 or WS2801 LED strip. It may be compatible with other LED strips, but this has not been tested.
Buy the LPD8806 LED Strip here and learn how to connect it here
If using Raspbian, you will need to enable SPI:
sudo raspi-config
then navigate to Advanced
options and enable SPI
Clone the module and npm install:
cd ~/MagicMirror/modules
git clone https://github.com/robertalexa/MMM-PiLights.git
cd MMM-PiLights
npm install
Add the module config to ~/MagicMirror/config/config.js
modules: [
{
module: 'MMM-PiLights',
config: {
ledCount: 64,
type: 'ws2801', // 'ws2801' or 'lpd8806'
bus: 0,
device: 0,
brightness: 1.0 // between 0.0 and 1.0
}
}
]
Option | Type | Default | Description |
---|---|---|---|
ledCount |
Integer | 64 |
Number LEDs on your strip |
type |
String | ws2801 |
The LED strip type, either 'ws2801' or 'lpd8806' |
bus |
Integer | 0 |
The SPI bus number for your LED strip |
device |
Integer | 0 |
The SPI device number for your LED strip |
brightness |
Float | 0.0 |
The LED strip brightness (between 0.0 and 1.0) |
If you're developing a module and want to trigger a light sequence, here's an example of what you'd use in your module:
this.sendNotification('PILIGHTS_SEQUENCE', 'blue_pulse');
My other MagicMirror module is able to trigger light sequences with notifications: MMM-IFTTT
The GET endpoint is pretty simple:
http://yourmagicmirror/PiLights?sequence=blue_pulse
From the command line:
curl -X GET "http://yourmagicmirror/PiLights?sequence=blue_pulse"
- off
- white_pulse
- blue_pulse
- lightblue_pulse
- red_pulse
- green_pulse
- orange_pulse
- pink_pulse
- white_static
- warm_static
- blue_static
- red_static
- green_static
- orange_static
- pink_static
- rainbow
- christmas
- candy
I am not actively maintaining this, but happy to help anyone that will give this a go.
The code is not in a clean shape, not having enough time... one day i will improve it, hopefully :)
The code is slightly bespoke to my use case, where I am matching this with MMM-GoogleAssistant. When called, the assistant will trigger the lightblue_pulse notification. In case there was already an effect, once the pulse finishes, it gets restored.
/** WS-2801 LED Strip Control **/
/** Vocal commands script **/
var recipe = {
plugins: {
onActivate: "LED_LBLUE_PULSE"
},
commands: {
"LED_LBLUE_PULSE": {
notificationExec: {
notification: "PILIGHTS_SEQUENCE",
payload: {
sequence: "lightblue_pulse",
iterations: "2"
}
}
},
}
}
All credits go to the original author and original repository https://github.com/jc21/MMM-PiLights
I have only updated packages and made changes that I have been using for years, just never publicised.