I really like the idea of controlling my feature lighting with Alexa and IFTTT, but the options for a wifi RGB lightstrip were way too expensive. So I decided to create an easy to use RGB lightstrips powered by Particle and Alexa. In other words, I only spent ($19 Photon, $0.50 IR LED, $15 RGB Lightstrip) $34 and not $90 for the Phillips LightStrip, and I got to enjoyed coding for Particle.
// This #include statement was automatically added by the Particle IDE.
//#include "martinhouse.h"
#include "IRremote.h"
#define On_Off 0xFF02FD
#define Red 0xFF1AE5
#define Green 0xFF9A65
#define Blue 0xFFA25D
#define White 0xFF22DD
#define Brighter 0xFF3AC5
#define Less_Bright 0xFFBA45
#define Flash 0xFFD02F
#define Fade7 0xFFE01F
#define Fade3 0xFF609F
#define Jump3 0xFF20DF
#define Jump7 0xFFA05F
#define Quick 0xFFE817
#define Slow 0xFFC837
IRsend irsend(D0);
bool lightStatus;
int currentHex;
int controlRGB(String command);
int wait = 1000;
int onoff = 0xFF02FD;
int hrz = 32;
void setup() {
lightStatus = false;
Particle.function("lights", controlRGB);
Particle.variable("lightStatus", lightStatus);
}
void loop() {}
void lightOnOff(){
irsend.sendNEC(On_Off, 32);
lightStatus = !lightStatus;
}
void setLight(int hex){
if(!lightStatus){
lightOnOff();
delay(wait);
}
irsend.sendNEC(hex,hrz);
}
int controlRGB(String command){
if(command == "onoff"){
lightOnOff();
}
if(command == "code"){
setLight(currentHex);
}
if(command == "red"){
setLight(Red);
}
if(command == "green"){
setLight(Green);
}
if(command == "blue"){
setLight(Blue);
}
if(command == "white"){
setLight(White);
}
if(command == "brighter"){
setLight(Brighter);
}
if(command == "lessBright"){
setLight(Less_Bright);
}
if(command == "flash"){
setLight(Flash);
}
if(command == "fade7"){
setLight(Fade7);
}
if(command == "fade3"){
setLight(Fade3);
}
if(command == "jump3"){
setLight(Jump3);
}
if(command == "jump7"){
setLight(Jump7);
}
if(command == "quick"){
setLight(Quick);
}
if(command == "slow"){
setLight(Slow);
}
if(command == "off"){
if(lightStatus){
lightOnOff();
}
}
if(command == "isoff"){
lightStatus = false;
}
}
The first challenge was recording the signals from the Lightstrip's remote control. I was not able to port the Arduino's library to Photon, so I used an Arduino to record the remote's signal, and then used https://github.com/qwertzguy/Spark-Core-IRremote to replicate the signals with the Photon.
Using Alexa and the IFTTT application was the simplest steps of all. Now you can use voice triggers in the Alexa channel to execute a registered function in Photon, for our case you can call the function lights and pass the argument of onoff to toggle the RGB lights.
Working in IFTTT
The following example shows how to call a function in Photon to send the red light signal to the RGB lightstrip.
Step 1 - Login to IFTTT or create a free account if you don't have one.
Step 2 - Create a recipe and select Alexa as a trigger channel
Step 3 - Choose the specific phrase on Alexa's trigger options
Step 4 - Set an easy to remember phrase, for this example we are going to use "red kitchen"
Step 5 - Create the trigger and proceed to the next step.
Step 6 - Look for the Particle Channel and select "Call a function"
Step 7 - Select the function "lights" on the Photon that is going to control the RGB lightstrip, and pass the argument "red" which will satisfied the if statement condition
if(command == "red"){
setLight(Red);
}
Step 8 - Mission accomplished, now you are ready to tell Alexa to trigger red kitchen. :)
Comments
Please log in or sign up to comment.