From 76ac031b1ecefeb5e9c7f40dc3a54b90428ff009 Mon Sep 17 00:00:00 2001 From: Fma965 Date: Wed, 26 Dec 2018 18:39:14 +0000 Subject: [PATCH 01/17] Initial Upload --- .../ESP_MQTT_Digital_LEDs.ino | 876 ++++++++++++++++-- README.md | 136 +-- 2 files changed, 900 insertions(+), 112 deletions(-) diff --git a/ESP_MQTT_Digital_LEDs/ESP_MQTT_Digital_LEDs.ino b/ESP_MQTT_Digital_LEDs/ESP_MQTT_Digital_LEDs.ino index e1624b8..f47b15e 100644 --- a/ESP_MQTT_Digital_LEDs/ESP_MQTT_Digital_LEDs.ino +++ b/ESP_MQTT_Digital_LEDs/ESP_MQTT_Digital_LEDs.ino @@ -6,6 +6,21 @@ | |_) | | |\ \-.| `--' | | | | | / _____ \ | `--' | | | | `--' | | | | | / _____ \ | | | | | `--' | | |\ | |______/ | _| `.__| \______/ |__| |__| /__/ \__\ \______/ |__| \______/ |__| |__| /__/ \__\ |__| |__| \______/ |__| \__| + __ __ _ _ __ _ _ _ ______ __ _ _ _ _ _ ____ ____ _ _ _____ _____ + | \/ | ___ __| (_)/ _(_) ___ __| | | |__ _ _ / ___\ \ / // \ | \ | | | / \ | __ ) ___| | \ | | ____|_ _| + | |\/| |/ _ \ / _` | | |_| |/ _ \/ _` | | '_ \| | | | | | \ V // _ \ | \| | | / _ \ | _ \___ \ | \| | _| | | + | | | | (_) | (_| | | _| | __/ (_| | | |_) | |_| | | |___ | |/ ___ \| |\ | |___ / ___ \| |_) |__) || |\ | |___ | | + |_| |_|\___/ \__,_|_|_| |_|\___|\__,_| |_.__/ \__, | \____| |_/_/ \_\_| \_|_____/_/ \_\____/____(_)_| \_|_____| |_| + |___/ + VERSION 1.0 + + This is a modified and combined version created by Fma965, it gathers many effects found around the internet including Bruhs, Bkpsu and The-Red-Team. Most of the credit goes to Bruh for the base code. + - https://github.com/bruhautomation/ESP-MQTT-JSON-Digital-LEDs/blob/master/ESP_MQTT_Digital_LEDs/ESP_MQTT_Digital_LEDs.ino + - https://github.com/bkpsu/ESP-MQTT-JSON-Digital-LEDs/blob/master/ESP_MQTT_Digital_LEDs/ESP_MQTT_Digital_LEDs_w_JSON.ino + - https://github.com/the-red-team/Arduino-FastLED-Music-Visualizer/blob/master/music_visualizer.ino + + - You can find all information relating to this script at https://github.com/cyanlabs/ESP-MQTT-JSON-Digital-LEDs + Thanks much to @corbanmailloux for providing a great framework for implementing flash/fade with HomeAssistant https://github.com/corbanmailloux/esp-mqtt-rgb-led To use this code you will need the following dependancies: @@ -17,9 +32,15 @@ - You will also need to download the follow libraries by going to Sketch -> Include Libraries -> Manage Libraries - FastLED - PubSubClient - - ArduinoJSON + - ArduinoJSON (5.12.0) + + - You will need to connect the Addressable RGB strip to Pin D3 on the NodeMCU or change the pin definition below. + - You can use a microphone or directly wire the output of the a speaker port on a amp to your NodeMCU, wire GND (black speaker wire) to a GND and the Possitive (usually red speaker wire) to A0 on the NodeMCU + - For a list of the effects that can be used check GitHub */ +//#define FASTLED_INTERRUPT_RETRY_COUNT 0 + #include #include #include @@ -28,28 +49,24 @@ #include #include - - /************ WIFI and MQTT Information (CHANGE THESE FOR YOUR SETUP) ******************/ -const char* ssid = "YourSSID"; //type your WIFI information inside the quotes -const char* password = "YourWIFIpassword"; -const char* mqtt_server = "your.MQTT.server.ip"; -const char* mqtt_username = "yourMQTTusername"; -const char* mqtt_password = "yourMQTTpassword"; +const char* ssid = "SSID"; //type your WIFI information inside the quotes +const char* password = "WIFIPASSWORD"; // +const char* mqtt_server = "10.0.0.2"; +const char* mqtt_username = "homeassistant"; +const char* mqtt_password = "MQTTPASSWORD"; const int mqtt_port = 1883; - /**************************** FOR OTA **************************************************/ -#define SENSORNAME "porch" //change this to whatever you want to call your device -#define OTApassword "yourOTApassword" //the password you will need to enter to upload remotely via the ArduinoIDE -int OTAport = 8266; - +#define SENSORNAME "RGBStrip" //change this to whatever you want to call your device +#define OTApassword "OTAPassword" //the password you will need to enter to upload remotely via the ArduinoIDE +int OTAport = 8266; /************* MQTT TOPICS (change these topics as you wish) **************************/ -const char* light_state_topic = "bruh/porch"; -const char* light_set_topic = "bruh/porch/set"; +const char* light_state_topic = "home/RGBStrip1"; +const char* light_set_topic = "home/RGBStrip1/set"; const char* on_cmd = "ON"; const char* off_cmd = "OFF"; @@ -57,17 +74,14 @@ const char* effect = "solid"; String effectString = "solid"; String oldeffectString = "solid"; - - /****************************************FOR JSON***************************************/ const int BUFFER_SIZE = JSON_OBJECT_SIZE(10); #define MQTT_MAX_PACKET_SIZE 512 - - /*********************************** FastLED Defintions ********************************/ -#define NUM_LEDS 186 -#define DATA_PIN 5 +#define NUM_LEDS 64 + +#define DATA_PIN 3 //#define CLOCK_PIN 5 #define CHIPSET WS2811 #define COLOR_ORDER BRG @@ -81,7 +95,219 @@ byte green = 255; byte blue = 255; byte brightness = 255; - +/**************************** MUSIC VISUALIZER **************************************************/ +#define UPDATES_PER_SECOND 100 +#define MUSIC_SENSITIVITY 4 + +// AUDIO INPUT SETUP +int audio = A0; + +// STANDARD VISUALIZER VARIABLES +int loop_max = 0; +int k = 255; // COLOR WHEEL POSITION +int wheel_speed = 3; // COLOR WHEEL SPEED +int decay = 0; // HOW MANY MS BEFORE ONE LIGHT DECAY +int decay_check = 0; +long pre_react = 0; // NEW SPIKE CONVERSION +long react = 0; // NUMBER OF LEDs BEING LIT +long post_react = 0; // OLD SPIKE CONVERSION + +///////////////DrZzs Palettes for custom BPM effects////////////////////////// +///////////////Add any custom palettes here////////////////////////////////// + +// Gradient palette "bhw2_thanks_gp", originally from +// http://soliton.vm.bytemark.co.uk/pub/cpt-city/bhw/bhw2/tn/bhw2_thanks.png.index.html +// converted for FastLED with gammas (2.6, 2.2, 2.5) +// Size: 36 bytes of program space. + +DEFINE_GRADIENT_PALETTE( bhw2_thanks_gp ) { + 0, 9, 5, 1, + 48, 25, 9, 1, + 76, 137, 27, 1, + 96, 98, 42, 1, + 124, 144, 79, 1, + 153, 98, 42, 1, + 178, 137, 27, 1, + 211, 23, 9, 1, + 255, 9, 5, 1}; + +// Gradient palette "bhw2_redrosey_gp", originally from +// http://soliton.vm.bytemark.co.uk/pub/cpt-city/bhw/bhw2/tn/bhw2_redrosey.png.index.html +// converted for FastLED with gammas (2.6, 2.2, 2.5) +// Size: 32 bytes of program space. + +DEFINE_GRADIENT_PALETTE( bhw2_redrosey_gp ) { + 0, 103, 1, 10, + 33, 109, 1, 12, + 76, 159, 5, 48, + 119, 175, 55,103, + 127, 175, 55,103, + 178, 159, 5, 48, + 221, 109, 1, 12, + 255, 103, 1, 10}; + +// Gradient palette "bluered_gp", originally from +// http://soliton.vm.bytemark.co.uk/pub/cpt-city/h5/tn/bluered.png.index.html +// converted for FastLED with gammas (2.6, 2.2, 2.5) +// Size: 12 bytes of program space. + +DEFINE_GRADIENT_PALETTE( bluered_gp ) { + 0, 0, 0,255, + 127, 255,255,255, + 255, 255, 0, 0}; + +// Gradient palette "bhw2_xmas_gp", originally from +// http://soliton.vm.bytemark.co.uk/pub/cpt-city/bhw/bhw2/tn/bhw2_xmas.png.index.html +// converted for FastLED with gammas (2.6, 2.2, 2.5) +// Size: 48 bytes of program space. + +DEFINE_GRADIENT_PALETTE( bhw2_xmas_gp ) { + 0, 0, 12, 0, + 40, 0, 55, 0, + 66, 1,117, 2, + 77, 1, 84, 1, + 81, 0, 55, 0, + 119, 0, 12, 0, + 153, 42, 0, 0, + 181, 121, 0, 0, + 204, 255, 12, 8, + 224, 121, 0, 0, + 244, 42, 0, 0, + 255, 42, 0, 0}; + +// Gradient palette "bhw2_xc_gp", originally from +// http://soliton.vm.bytemark.co.uk/pub/cpt-city/bhw/bhw2/tn/bhw2_xc.png.index.html +// converted for FastLED with gammas (2.6, 2.2, 2.5) +// Size: 28 bytes of program space. + +DEFINE_GRADIENT_PALETTE( bhw2_xc_gp ) { + 0, 4, 2, 9, + 58, 16, 0, 47, + 122, 24, 0, 16, + 158, 144, 9, 1, + 183, 179, 45, 1, + 219, 220,114, 2, + 255, 234,237, 1}; + +// Gradient palette "bhw1_04_gp", originally from +// http://soliton.vm.bytemark.co.uk/pub/cpt-city/bhw/bhw1/tn/bhw1_04.png.index.html +// converted for FastLED with gammas (2.6, 2.2, 2.5) +// Size: 20 bytes of program space. + +DEFINE_GRADIENT_PALETTE( bhw1_04_gp ) { + 0, 229,227, 1, + 15, 227,101, 3, + 142, 40, 1, 80, + 198, 17, 1, 79, + 255, 0, 0, 45}; + +// Gradient palette "bhw4_051_gp", originally from +// http://soliton.vm.bytemark.co.uk/pub/cpt-city/bhw/bhw4/tn/bhw4_051.png.index.html +// converted for FastLED with gammas (2.6, 2.2, 2.5) +// Size: 36 bytes of program space. + +// Gradient palette "fs2006_gp", originally from +// http://soliton.vm.bytemark.co.uk/pub/cpt-city/cl/tn/fs2006.png.index.html +// converted for FastLED with gammas (2.6, 2.2, 2.5) +// Size: 56 bytes of program space. + +DEFINE_GRADIENT_PALETTE( fs2006_gp ) { + 0, 0, 49, 5, + 34, 0, 49, 5, + 34, 79,168, 66, + 62, 79,168, 66, + 62, 252,168, 92, + 103, 252,168, 92, + 103, 234, 81, 29, + 143, 234, 81, 29, + 143, 222, 30, 1, + 184, 222, 30, 1, + 184, 90, 13, 1, + 238, 90, 13, 1, + 238, 210, 1, 1, + 255, 210, 1, 1}; + + +DEFINE_GRADIENT_PALETTE( bhw4_051_gp ) { + 0, 1, 1, 4, + 28, 16, 24, 77, + 66, 35, 87,160, + 101, 125,187,205, + 127, 255,233, 13, + 145, 125,187,205, + 193, 28, 70,144, + 224, 14, 19, 62, + 255, 1, 1, 4}; + +// Gradient palette "blue_g2_5_gp", originally from +// http://soliton.vm.bytemark.co.uk/pub/cpt-city/go2/webtwo/tn/blue-g2-5.png.index.html +// converted for FastLED with gammas (2.6, 2.2, 2.5) +// Size: 16 bytes of program space. + +DEFINE_GRADIENT_PALETTE( blue_g2_5_gp ) { + 0, 2, 6, 63, + 127, 2, 9, 67, + 255, 255, 255, 115, + 255, 255, 255, 0}; + +// Gradient palette "bhw3_41_gp", originally from +// http://soliton.vm.bytemark.co.uk/pub/cpt-city/bhw/bhw3/tn/bhw3_41.png.index.html +// converted for FastLED with gammas (2.6, 2.2, 2.5) +// Size: 36 bytes of program space. + +DEFINE_GRADIENT_PALETTE( bhw3_41_gp ) { + 0, 0, 0, 45, + 71, 7, 12,255, + 76, 75, 91,255, + 76, 255,255,255, + 81, 255,255,255, + 178, 255,255,255, + 179, 255, 55, 45, + 196, 255, 0, 0, + 255, 42, 0, 0}; + +DEFINE_GRADIENT_PALETTE( test_gp ) { + 0, 255, 0, 0, // Red +// 32, 171, 85, 0, // Orange +// 64, 171,171, 0, // Yellow +// 96, 0,255, 0, // Green +//128, 0,171, 85, // Aqua + 160, 0, 0,255, // Blue +//192, 85, 0,171, // Purple +//224, 171, 0, 85, // Pink +//255, 255, 0, 0};// and back to Red +}; + +// Gradient palette "bhw2_greenman_gp", originally from +// http://soliton.vm.bytemark.co.uk/pub/cpt-city/bhw/bhw2/tn/bhw2_greenman.png.index.html +// converted for FastLED with gammas (2.6, 2.2, 2.5) +// Size: 12 bytes of program space. + +DEFINE_GRADIENT_PALETTE( bhw2_greenman_gp ) { + 0, 1, 22, 1, + 130, 1,168, 2, + 255, 1, 22, 1}; + +// Gradient palette "PSU_gp" +// converted for FastLED with gammas (2.6, 2.2, 2.5) +// Size: 12 bytes of program space. + +DEFINE_GRADIENT_PALETTE( PSU_gp ) { + 0, 4, 30, 66, + 127, 30, 64, 124, + 255, 255,255,255}; + +// Gradient palette "Orange_to_Purple_gp", originally from +// http://soliton.vm.bytemark.co.uk/pub/cpt-city/ds/icons/tn/Orange-to-Purple.png.index.html +// converted for FastLED with gammas (2.6, 2.2, 2.5) +// Size: 12 bytes of program space. + +DEFINE_GRADIENT_PALETTE( Orange_to_Purple_gp ) { + 0, 208, 50, 1, + 127, 146, 27, 45, + 255, 97, 12,178}; + +/* END PALETTE DEFINITIONS */ /******************************** GLOBALS for fade/flash *******************************/ bool stateOn = false; @@ -89,6 +315,7 @@ bool startFade = false; bool onbeforeflash = false; unsigned long lastLoop = 0; int transitionTime = 0; +int delayMultiplier = 1; int effectSpeed = 0; bool inFade = false; int loopCount = 0; @@ -104,8 +331,6 @@ byte flashGreen = green; byte flashBlue = blue; byte flashBrightness = brightness; - - /********************************** GLOBALS for EFFECTS ******************************/ //RAINBOW uint8_t thishue = 0; // Starting hue value. @@ -113,6 +338,11 @@ uint8_t deltahue = 10; //CANDYCANE CRGBPalette16 currentPalettestriped; //for Candy Cane +CRGBPalette16 hailPalettestriped; //for Hail +CRGBPalette16 ThxPalettestriped; //for Thanksgiving +CRGBPalette16 HalloweenPalettestriped; //for Halloween +CRGBPalette16 HJPalettestriped; //for Holly Jolly +CRGBPalette16 IndPalettestriped; //for Independence CRGBPalette16 gPal; //for fire //NOISE @@ -152,7 +382,14 @@ int lightningcounter = 0; int idex = 0; //-LED INDEX (0 to NUM_LEDS-1 int TOP_INDEX = int(NUM_LEDS / 2); int thissat = 255; //-FX LOOPS DELAY VAR + +//////////////////add thishue__ for Police All custom effects here///////////////////////////////////////////////////////// +/////////////////use hsv Hue number for one color, for second color change "thishue__ + __" in the setEffect section////// + uint8_t thishuepolice = 0; +uint8_t thishuehail = 183; +uint8_t thishueLovey = 0; + int antipodal_index(int i) { int iN = i + TOP_INDEX; if (i >= TOP_INDEX) { @@ -169,6 +406,16 @@ bool gReverseDirection = false; //BPM uint8_t gHue = 0; +//CHRISTMAS +int toggle = 0; + +//RANDOM STARS +const int NUM_STARS = NUM_LEDS/10; +static int stars[NUM_STARS]; + +//SINE HUE +int hue_index = 0; +int led_index = 0; WiFiClient espClient; PubSubClient client(espClient); @@ -182,6 +429,12 @@ void setup() { FastLED.addLeds(leds, NUM_LEDS); setupStripedPalette( CRGB::Red, CRGB::Red, CRGB::White, CRGB::White); //for CANDY CANE + setupThxPalette( CRGB::OrangeRed, CRGB::Olive, CRGB::Maroon, CRGB::Maroon); //for Thanksgiving + setupHailPalette( CRGB::Blue, CRGB::Blue, CRGB::White, CRGB::White); //for HAIL + setupHalloweenPalette( CRGB::DarkOrange, CRGB::DarkOrange, CRGB::Indigo, CRGB::Indigo); //for Halloween + setupHJPalette( CRGB::Red, CRGB::Red, CRGB::Green, CRGB::Green); //for Holly Jolly + setupIndPalette( CRGB::FireBrick, CRGB::Cornsilk, CRGB::MediumBlue, CRGB::MediumBlue); //for Independence + gPal = HeatColors_p; //for FIRE setup_wifi(); @@ -216,9 +469,6 @@ void setup() { ArduinoOTA.begin(); Serial.println("Ready"); - Serial.print("IP Address: "); - Serial.println(WiFi.localIP()); - } @@ -243,7 +493,7 @@ void setup_wifi() { Serial.println(""); Serial.println("WiFi connected"); - Serial.println("IP address: "); + Serial.print("IP address: "); Serial.println(WiFi.localIP()); } @@ -385,7 +635,7 @@ bool processJson(char* message) { if (root.containsKey("color_temp")) { //temp comes in as mireds, need to convert to kelvin then to RGB int color_temp = root["color_temp"]; - unsigned int kelvin = MILLION / color_temp; + unsigned int kelvin = 1000000 / color_temp; //MILLION / color_temp; temp2rgb(kelvin); @@ -429,7 +679,7 @@ void sendState() { root["brightness"] = brightness; root["effect"] = effectString.c_str(); - + root["transition"] = transitionTime; char buffer[root.measureLength() + 1]; root.printTo(buffer, sizeof(buffer)); @@ -437,8 +687,6 @@ void sendState() { client.publish(light_state_topic, buffer, true); } - - /********************************** START RECONNECT*****************************************/ void reconnect() { // Loop until we're reconnected @@ -460,8 +708,6 @@ void reconnect() { } } - - /********************************** START Set Color*****************************************/ void setColor(int inR, int inG, int inB) { for (int i = 0; i < NUM_LEDS; i++) { @@ -481,8 +727,6 @@ void setColor(int inR, int inG, int inB) { Serial.println(inB); } - - /********************************** START MAIN LOOP*****************************************/ void loop() { @@ -497,12 +741,247 @@ void loop() { return; } - - client.loop(); ArduinoOTA.handle(); +///////////////////////////////////////// +//////Music Visualizer////////////// +/////////////////////////////////////// + + // Left to Right + if(effectString == "Music - L2R") { + visualize_music(1); + } + // Middle Out + if(effectString == "Music - Middle") { + visualize_music(2); + } + // Custom for Fma965 + if(effectString == "Music - Fma965") { + visualize_music(3); + } + +///////////////////////////////////////// +//////DrZzs custom effects////////////// +/////////////////////////////////////// + + if (effectString == "Christmas") { // colored stripes pulsing in Shades of GREEN and RED + uint8_t BeatsPerMinute = 62; + CRGBPalette16 palette = bhw2_xmas_gp; + uint8_t beat = beatsin8( BeatsPerMinute, 64, 255); + for( int i = 0; i < NUM_LEDS; i++) { //9948 + leds[i] = ColorFromPalette(palette, gHue+(i*2), beat-gHue+(i*10)); + } + if (transitionTime == 0 or transitionTime == NULL) { + transitionTime = 30; + } + delayMultiplier = 1; + showleds(); +} + + if (effectString == "St Patty") { // colored stripes pulsing in Shades of GREEN + uint8_t BeatsPerMinute = 62; + CRGBPalette16 palette = bhw2_greenman_gp; + uint8_t beat = beatsin8( BeatsPerMinute, 64, 255); + for( int i = 0; i < NUM_LEDS; i++) { //9948 + leds[i] = ColorFromPalette(palette, gHue+(i*2), beat-gHue+(i*10)); + } + if (transitionTime == 0 or transitionTime == NULL) { + transitionTime = 30; + } + delayMultiplier = 1; + showleds(); +} + + if (effectString == "Valentine") { // colored stripes pulsing in Shades of PINK and RED + uint8_t BeatsPerMinute = 62; + CRGBPalette16 palette = bhw2_redrosey_gp; + uint8_t beat = beatsin8( BeatsPerMinute, 64, 255); + for( int i = 0; i < NUM_LEDS; i++) { //9948 + leds[i] = ColorFromPalette(palette, gHue+(i*2), beat-gHue+(i*10)); + } + if (transitionTime == 0 or transitionTime == NULL) { + transitionTime = 30; + } + delayMultiplier = 1; + showleds(); +} + + if (effectString == "Turkey Day") { // colored stripes pulsing in Shades of Brown and ORANGE + uint8_t BeatsPerMinute = 62; + CRGBPalette16 palette = bhw2_thanks_gp; + uint8_t beat = beatsin8( BeatsPerMinute, 64, 255); + for( int i = 0; i < NUM_LEDS; i++) { //9948 + leds[i] = ColorFromPalette(palette, gHue+(i*2), beat-gHue+(i*10)); + } + if (transitionTime == 0 or transitionTime == NULL) { + transitionTime = 30; + } + delayMultiplier = 1; + showleds(); +} + + if (effectString == "Thanksgiving") { // colored stripes pulsing in Shades of Red and ORANGE and Green + static uint8_t startIndex = 0; + startIndex = startIndex + 1; /* higher = faster motion */ + + fill_palette( leds, NUM_LEDS, + startIndex, 16, /* higher = narrower stripes */ + ThxPalettestriped, 255, LINEARBLEND); + if (transitionTime == 0 or transitionTime == NULL) { + transitionTime = 30; + } + delayMultiplier = 1; + showleds(); +} + + if (effectString == "USA") { // colored stripes pulsing in Shades of Red White & Blue + uint8_t BeatsPerMinute = 62; + CRGBPalette16 palette = bhw3_41_gp; + uint8_t beat = beatsin8( BeatsPerMinute, 64, 255); + for( int i = 0; i < NUM_LEDS; i++) { //9948 + leds[i] = ColorFromPalette(palette, gHue+(i*2), beat-gHue+(i*10)); + } + if (transitionTime == 0 or transitionTime == NULL) { + transitionTime = 30; + } + delayMultiplier = 1; + showleds(); +} + + if (effectString == "Independence") { // colored stripes of Red White & Blue + static uint8_t startIndex = 0; + startIndex = startIndex + 1; /* higher = faster motion */ + + fill_palette( leds, NUM_LEDS, + startIndex, 16, /* higher = narrower stripes */ + IndPalettestriped, 255, LINEARBLEND); + if (transitionTime == 0 or transitionTime == NULL) { + transitionTime = 30; + } + delayMultiplier = 1; + showleds(); +} + + + if (effectString == "Halloween") { // colored stripes pulsing in Shades of Purple and Orange + uint8_t BeatsPerMinute = 62; + CRGBPalette16 palette = Orange_to_Purple_gp; + uint8_t beat = beatsin8( BeatsPerMinute, 64, 255); + for( int i = 0; i < NUM_LEDS; i++) { //9948 + leds[i] = ColorFromPalette(palette, gHue+(i*2), beat-gHue+(i*10)); + } + if (transitionTime == 0 or transitionTime == NULL) { + transitionTime = 30; + } + delayMultiplier = 1; + showleds(); +} + + if (effectString == "Go Lions") { // colored stripes pulsing in Shades of Maize and Blue & White (FTFY DrZZZ :-P) + uint8_t BeatsPerMinute = 62; + CRGBPalette16 palette = PSU_gp; + uint8_t beat = beatsin8( BeatsPerMinute, 64, 255); + for( int i = 0; i < NUM_LEDS; i++) { //9948 + leds[i] = ColorFromPalette(palette, gHue+(i*2), beat-gHue+(i*10)); + } + if (transitionTime == 0 or transitionTime == NULL) { + transitionTime = 30; + } + delayMultiplier = 1; + showleds(); +} + + if (effectString == "Hail") { + static uint8_t startIndex = 0; + startIndex = startIndex + 1; /* higher = faster motion */ + + fill_palette( leds, NUM_LEDS, + startIndex, 16, /* higher = narrower stripes */ + hailPalettestriped, 255, LINEARBLEND); + if (transitionTime == 0 or transitionTime == NULL) { + transitionTime = 30; + } + delayMultiplier = 1; + showleds(); +} + + if (effectString == "Touchdown") { //Maize and Blue & White with POLICE ALL animation + idex++; + if (idex >= NUM_LEDS) { + idex = 0; + } + int idexY = idex; + int idexB = antipodal_index(idexY); + int thathue = ( thishuehail + 64) % 255; + leds[idexY] = CRGB::Blue; //CHSV(thishuehail, thissat, 255); + leds[idexB] = CRGB::White; //CHSV(thathue, thissat, 255); + if (transitionTime == 0 or transitionTime == NULL) { + transitionTime = 30; + } + delayMultiplier = 1; + showleds(); + } + + if (effectString == "Punkin") { + static uint8_t startIndex = 0; + startIndex = startIndex + 1; /* higher = faster motion */ + + fill_palette( leds, NUM_LEDS, + startIndex, 16, /* higher = narrower stripes */ + HalloweenPalettestriped, 255, LINEARBLEND); + if (transitionTime == 0 or transitionTime == NULL) { + transitionTime = 30; + } + delayMultiplier = 1; + showleds(); + } + + if (effectString == "Lovey Day") { //Valentine's Day colors (TWO COLOR SOLID) + idex++; + if (idex >= NUM_LEDS) { + idex = 0; + } + int idexR = idex; + int idexB = antipodal_index(idexR); + int thathue = (thishueLovey + 244) % 255; + leds[idexR] = CHSV(thishueLovey, thissat, 255); + leds[idexB] = CHSV(thathue, thissat, 255); + if (transitionTime == 0 or transitionTime == NULL) { + transitionTime = 30; + } + delayMultiplier = 1; + showleds(); + } + + if (effectString == "Holly Jolly") { + static uint8_t startIndex = 0; + startIndex = startIndex + 1; /* higher = faster motion */ + + fill_palette( leds, NUM_LEDS, + startIndex, 16, /* higher = narrower stripes */ + HJPalettestriped, 255, LINEARBLEND); + if (transitionTime == 0 or transitionTime == NULL) { + transitionTime = 30; + } + delayMultiplier = 1; + showleds(); + } + +/////////////////End DrZzs effects///////////// +/////////////////////////////////////////////// + +////////Place your custom effects below//////////// + + + + +/////////////end custom effects//////////////// + +/////////////////////////////////////////////// +/////////fastLED & Bruh effects/////////////// +///////////////////////////////////////////// //EFFECT BPM if (effectString == "bpm") { @@ -515,6 +994,7 @@ void loop() { if (transitionTime == 0 or transitionTime == NULL) { transitionTime = 30; } + delayMultiplier = 1; showleds(); } @@ -529,6 +1009,7 @@ void loop() { if (transitionTime == 0 or transitionTime == NULL) { transitionTime = 0; } + delayMultiplier = 1; showleds(); } @@ -541,6 +1022,7 @@ void loop() { if (transitionTime == 0 or transitionTime == NULL) { transitionTime = 30; } + delayMultiplier = 1; showleds(); } @@ -553,6 +1035,7 @@ void loop() { // Set the i'th led to red leds[i] = CHSV(hue++, 255, 255); // Show the leds + delayMultiplier = 1; showleds(); // now that we've shown the leds, reset the i'th led to black // leds[i] = CRGB::Black; @@ -564,6 +1047,7 @@ void loop() { // Set the i'th led to red leds[i] = CHSV(hue++, 255, 255); // Show the leds + delayMultiplier = 1; showleds(); // now that we've shown the leds, reset the i'th led to black // leds[i] = CRGB::Black; @@ -586,7 +1070,8 @@ void loop() { if (transitionTime == 0 or transitionTime == NULL) { transitionTime = 30; - } + } + delayMultiplier = 1; showleds(); } @@ -597,6 +1082,7 @@ void loop() { if (transitionTime == 0 or transitionTime == NULL) { transitionTime = 150; } + delayMultiplier = 2; showleds(); } @@ -610,6 +1096,7 @@ void loop() { if (transitionTime == 0 or transitionTime == NULL) { transitionTime = 30; } + delayMultiplier = 1; showleds(); } @@ -623,6 +1110,7 @@ void loop() { if (transitionTime == 0 or transitionTime == NULL) { transitionTime = 130; } + delayMultiplier = 1; showleds(); } @@ -634,8 +1122,8 @@ void loop() { FastLED.clear(); FastLED.show(); } - ledstart = random8(NUM_LEDS); // Determine starting location of flash - ledlen = random8(NUM_LEDS - ledstart); // Determine length of flash (not to go beyond NUM_LEDS-1) + ledstart = random16(NUM_LEDS); // Determine starting location of flash + ledlen = random16(NUM_LEDS - ledstart); // Determine length of flash (not to go beyond NUM_LEDS-1) for (int flashCounter = 0; flashCounter < random8(3, flashes); flashCounter++) { if (flashCounter == 0) dimmer = 5; // the brightness of the leader is scaled down by a factor of 5 else dimmer = random8(1, 3); // return strokes are brighter than the leader @@ -651,6 +1139,7 @@ void loop() { if (transitionTime == 0 or transitionTime == NULL) { transitionTime = 0; } + delayMultiplier = 1; showleds(); } @@ -669,6 +1158,7 @@ void loop() { if (transitionTime == 0 or transitionTime == NULL) { transitionTime = 30; } + delayMultiplier = 1; showleds(); } @@ -695,6 +1185,7 @@ void loop() { if (transitionTime == 0 or transitionTime == NULL) { transitionTime = 30; } + delayMultiplier = 1; showleds(); } @@ -707,6 +1198,7 @@ void loop() { if (transitionTime == 0 or transitionTime == NULL) { transitionTime = 130; } + delayMultiplier = 1; showleds(); } @@ -720,11 +1212,12 @@ void loop() { if (transitionTime == 0 or transitionTime == NULL) { transitionTime = 130; } + delayMultiplier = 1; showleds(); } - //EFFECT SIENLON + //EFFECT SINELON if (effectString == "sinelon") { fadeToBlackBy( leds, NUM_LEDS, 20); int pos = beatsin16(13, 0, NUM_LEDS - 1); @@ -732,6 +1225,7 @@ void loop() { if (transitionTime == 0 or transitionTime == NULL) { transitionTime = 150; } + delayMultiplier = 1; showleds(); } @@ -760,12 +1254,142 @@ void loop() { if (transitionTime == 0 or transitionTime == NULL) { transitionTime = 0; } + delayMultiplier = 1; showleds(); } + //EFFECT CHRISTMAS ALTERNATE + if (effectString == "christmas alternate") { + for (int i = 0; i < NUM_LEDS; i++) { + if ((toggle + i) % 2 == 0) { + leds[i] = CRGB::Crimson; + } + else { + leds[i] = CRGB::DarkGreen; + } + } + toggle=(toggle + 1) % 2; + if (transitionTime == 0 or transitionTime == NULL) { + transitionTime = 130; + } + delayMultiplier = 30; + showleds(); + fadeall(); + //delay(200); + } + + //EFFECT RANDOM STARS + if (effectString == "random stars") { + fadeUsingColor( leds, NUM_LEDS, CRGB::Blue); + int pos = random16(NUM_LEDS); + leds[pos] += CRGB(realRed + random8(64), realGreen, realBlue); + addGlitter(80); + if (transitionTime == 0 or transitionTime == NULL) { + transitionTime = 30; + } + delayMultiplier = 6; + //delay(60); + showleds(); + + } + +//EFFECT "Sine Hue" + if (effectString == "sine hue") { + static uint8_t hue_index = 0; + static uint8_t led_index = 0; + if (led_index >= NUM_LEDS) { //Start off at 0 if the led_index was incremented past the segment size in some other effect + led_index = 0; + } + for (int i = 0; i < NUM_LEDS; i = i + 1) + { + leds[i] = CHSV(hue_index, 255, 255 - int(abs(sin(float(i + led_index) / NUM_LEDS * 2 * 3.14159) * 255))); + } + + led_index++,hue_index++; + + if (hue_index >= 255) { + hue_index = 0; + } + delayMultiplier = 2; + showleds(); + } + + +//EFFECT "Full Hue" + if (effectString == "full hue") { + static uint8_t hue_index = 0; + fill_solid(leds, NUM_LEDS, CHSV(hue_index, 255, 255)); + hue_index++; + + if (hue_index >= 255) { + hue_index = 0; + } + delayMultiplier = 2; + showleds(); + } + + +//EFFECT "Breathe" + if (effectString == "breathe") { + static bool toggle; + static uint8_t brightness_index = 0; + fill_solid(leds, NUM_LEDS,CHSV(thishue,255,brightness_index)); + if (brightness_index >= 255) { + toggle=0; + } + else if (brightness_index <= 0) + { + toggle=1; + } + + if (toggle) + { + brightness_index++; + } + else + { + brightness_index--; + } + + delayMultiplier = 2; + showleds(); + } - EVERY_N_MILLISECONDS(10) { +//EFFECT "Hue Breathe" + if (effectString == "hue breathe") { + static uint8_t hue_index = 0; + static bool toggle = 1; + static uint8_t brightness_index = 0; + fill_solid(leds, NUM_LEDS, CHSV(hue_index, 255, brightness_index)); + if (brightness_index >= 255) { + toggle=0; + hue_index=hue_index+10; + } + else if (brightness_index <= 0) + { + toggle=1; + hue_index=hue_index+10; + } + + if (toggle) + { + brightness_index++; + } + else + { + brightness_index--; + } + + if (hue_index >= 255) { + hue_index = 0; + } + + delayMultiplier = 2; + showleds(); + } + + EVERY_N_MILLISECONDS(10) { nblendPaletteTowardPalette(currentPalette, targetPalette, maxChanges); // FOR NOISE ANIMATIon { gHue++; @@ -782,6 +1406,7 @@ void loop() { if (transitionTime == 0 or transitionTime == NULL) { transitionTime = 0; } + delayMultiplier = 1; showleds(); } @@ -810,12 +1435,11 @@ void loop() { if (transitionTime == 0 or transitionTime == NULL) { transitionTime = 30; } + delayMultiplier = 1; showleds(); } - } - EVERY_N_SECONDS(5) { targetPalette = CRGBPalette16(CHSV(random8(), 255, random8(128, 255)), CHSV(random8(), 255, random8(128, 255)), CHSV(random8(), 192, random8(128, 255)), CHSV(random8(), 255, random8(128, 255))); } @@ -896,7 +1520,6 @@ void loop() { } } - /**************************** START TRANSITION FADER *****************************************/ // From https://www.arduino.cc/en/Tutorial/ColorCrossfader /* BELOW THIS LINE IS THE MATH -- YOU SHOULDN'T NEED TO CHANGE THIS FOR THE BASICS @@ -956,6 +1579,8 @@ int calculateVal(int step, int val, int i) { return val; } +////////////////////////place setup__Palette and __Palettestriped custom functions here - for Candy Cane effects ///////////////// +///////You can use up to 4 colors and change the pattern of A's AB's B's and BA's as you like////////////// /**************************** START STRIPLED PALETTE *****************************************/ @@ -966,6 +1591,42 @@ void setupStripedPalette( CRGB A, CRGB AB, CRGB B, CRGB BA) { ); } +void setupHailPalette( CRGB A, CRGB AB, CRGB B, CRGB BA) +{ + hailPalettestriped = CRGBPalette16( + A, A, A, A, A, A, A, A, B, B, B, B, B, B, B, B + ); +} + +void setupHJPalette( CRGB A, CRGB AB, CRGB B, CRGB BA) +{ + HJPalettestriped = CRGBPalette16( + A, A, A, A, A, A, A, A, B, B, B, B, B, B, B, B + ); +} + +void setupIndPalette( CRGB A, CRGB AB, CRGB B, CRGB BA) +{ + IndPalettestriped = CRGBPalette16( + A, A, A, A, A, AB, AB, AB, AB, AB, B, B, B, B, B, B + ); +} + +void setupThxPalette( CRGB A, CRGB AB, CRGB B, CRGB BA) +{ + ThxPalettestriped = CRGBPalette16( + A, A, A, A, A, A, A, AB, AB, AB, B, B, B, B, B, B + ); +} + +void setupHalloweenPalette( CRGB A, CRGB AB, CRGB B, CRGB BA) +{ + HalloweenPalettestriped = CRGBPalette16( + A, A, A, A, A, A, A, A, B, B, B, B, B, B, B, B + ); +} + +//////////////////////////////////////////////////////// /********************************** START FADE************************************************/ @@ -975,8 +1636,6 @@ void fadeall() { } } - - /********************************** START FIRE **********************************************/ void Fire2012WithPalette() { @@ -1015,8 +1674,6 @@ void Fire2012WithPalette() } } - - /********************************** START ADD GLITTER *********************************************/ void addGlitter( fract8 chanceOfGlitter) { @@ -1025,8 +1682,6 @@ void addGlitter( fract8 chanceOfGlitter) } } - - /********************************** START ADD GLITTER COLOR ****************************************/ void addGlitterColor( fract8 chanceOfGlitter, int red, int green, int blue) { @@ -1035,8 +1690,6 @@ void addGlitterColor( fract8 chanceOfGlitter, int red, int green, int blue) } } - - /********************************** START SHOW LEDS ***********************************************/ void showleds() { @@ -1045,8 +1698,8 @@ void showleds() { if (stateOn) { FastLED.setBrightness(brightness); //EXECUTE EFFECT COLOR FastLED.show(); - if (transitionTime > 0 && transitionTime < 130) { //Sets animation speed based on receieved value - FastLED.delay(1000 / transitionTime); + if (transitionTime > 0 && transitionTime < 250) { //Sets animation speed based on receieved value + FastLED.delay(transitionTime / 10 * delayMultiplier); //1000 / transitionTime); //delay(10*transitionTime); } } @@ -1109,3 +1762,114 @@ void temp2rgb(unsigned int kelvin) { } } } + +/**************************** MUSIC VISUALIZER **************************************************/ +// https://github.com/the-red-team/Arduino-FastLED-Music-Visualizer/blob/master/music_visualizer.ino +// Modified by Fma965 + +CRGB Scroll(int pos) { + CRGB color (0,0,0); + if(pos < 85) { + color.g = 0; + color.r = ((float)pos / 85.0f) * 255.0f; + color.b = 255 - color.r; + } else if(pos < 170) { + color.g = ((float)(pos - 85) / 85.0f) * 255.0f; + color.r = 255 - color.g; + color.b = 0; + } else if(pos < 256) { + color.b = ((float)(pos - 170) / 85.0f) * 255.0f; + color.g = 255 - color.b; + color.r = 1; + } + return color; +} + +void visualize_music(int LEDDirection) +{ + int audio_input = analogRead(audio) * MUSIC_SENSITIVITY; + + if (audio_input > 0) + { + if(LEDDirection == 1) { + pre_react = ((long)NUM_LEDS * (long)audio_input) / 1023L; // TRANSLATE AUDIO LEVEL TO NUMBER OF LEDs + } else if(LEDDirection == 2) { + pre_react = ((long)NUM_LEDS/2 * (long)audio_input) / 1023L; // TRANSLATE AUDIO LEVEL TO NUMBER OF LEDs + } else if(LEDDirection == 3) { + pre_react = ((long)NUM_LEDS/4 * (long)audio_input) / 1023L; // TRANSLATE AUDIO LEVEL TO NUMBER OF LEDs + } + + if (pre_react > react) // ONLY ADJUST LEVEL OF LED IF LEVEL HIGHER THAN CURRENT LEVEL + react = pre_react; + } + if(LEDDirection == 1) { + RainbowL2R(); // Left to Right + } else if(LEDDirection == 2) { + RainbowMiddleOut(); //Middle Out + } else if(LEDDirection == 3) { + RainbowFma965(); //Custom setup for Fma965 + } + + k = k - wheel_speed; // SPEED OF COLOR WHEEL + if (k < 0) // RESET COLOR WHEEL + k = 255; + + // REMOVE LEDs + decay_check++; + if (decay_check > decay) + { + decay_check = 0; + if (react > 0) + react--; + } + //delay(1); +} + +// https://github.com/NeverPlayLegit/Rainbow-Fader-FastLED/blob/master/rainbow.ino +void RainbowL2R() +{ + for(int i = NUM_LEDS - 1; i >= 0; i--) { + if (i < react) + leds[i] = Scroll((i * 256 / 50 + k) % 256); + else + leds[i] = CRGB(0, 0, 0); + } + FastLED.show(); +} + +void RainbowMiddleOut() +{ + for(int i = 0; i < NUM_LEDS/2; i++) { + if (i < react) { + leds[NUM_LEDS/2+i] = Scroll((i * 256 / NUM_LEDS + k) % 256); + leds[NUM_LEDS/2-i] = Scroll((i * 256 / NUM_LEDS + k) % 256); + } + else { + leds[i] = CRGB(0, 0, 0); + } + } + FastLED.show(); +} + +void RainbowFma965() +{ + for(int i = 0; i < 21; i++) { + if (i < react) { + leds[42-i] = Scroll((i * 256 / NUM_LEDS + k) % 256); + leds[42+i] = Scroll((i * 256 / NUM_LEDS + k) % 256); + } else { + leds[42-i] = CRGB(0, 0, 0); + leds[42+i] = CRGB(0, 0, 0); + } + } + for(int i = 0; i < 12; i++) { + if (i < react) { + leds[10+i] = Scroll((i * 256 / NUM_LEDS + k) % 256); + leds[10-i] = Scroll((i * 256 / NUM_LEDS + k) % 256); + } else { + leds[10+i] = CRGB(0, 0, 0); + leds[10-i] = CRGB(0, 0, 0); + } + } + FastLED.show(); +} \ No newline at end of file diff --git a/README.md b/README.md index a5840b0..73a62c9 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,10 @@ # ESP MQTT JSON Digital LEDs -This project shows a super easy way to get started using Digital LED strips with [Home Assistant](https://home-assistant.io/), a sick, open-source Home Automation platform that can do just about anything. +This is a modified version of https://github.com/bkpsu/ESP-MQTT-JSON-Digital-LEDs which is a modified version of https://github.com/bruhautomation/ESP-MQTT-JSON-Digital-LEDs -The code covered in this repository utilizes [Home Assistant's MQTT JSON Light Component](https://home-assistant.io/components/light.mqtt_json/) and an ESP8266 microcontroller. +The code covered in this repository utilizes [Home Assistant's MQTT Light Component](https://home-assistant.io/components/light.mqtt_json/) and an ESP8266 microcontroller. + +I would suggest using the same versions of libraries to minimize potential isues, PubSubClient (2.7.0), ArduinoJSON (5.12.0) and FastLED (3.2.1) #### Supported Features Include - RGB Color Selection @@ -12,6 +14,12 @@ The code covered in this repository utilizes [Home Assistant's MQTT JSON Light C - Transitions - Effects with Animation Speed - Over-the-Air (OTA) Upload from the ArduinoIDE! +- Music Visualizer (Left to Right and Middle) +- DrZZs Effects +- bkpsu Effects + +#### Music Visualizer +This requires some sort of sound device, Microphone or a speaker output from an amp. for my purposes i spliced in to the speaker output of a rear speaker and connected 1 end to my amp and the other to the NodeMCU. The pins that are used for this code are A0 for the possitive (red speaker wire) and GND for the GND (black speaker wire). This works perfectly without requiring any extra hardware. it also doesn't get ruined by voice as it's using a direct sound output. Some of the effects incorporate the currrently selected color (sinelon, confetti, juggle, etc) while other effects use pre-defined colors. You can also select custom transition speeds between colors. The transition variable in Home Assistant (HA) also functions to control the animation speed of the currently running animation. The input_slider and automation in the HA configuration example allow you to easily set a transition speed from HA's user interface without needing to use the Services tool. @@ -20,65 +28,81 @@ The default speed for the effects is hard coded and is set when the light is fir #### OTA Uploading This code also supports remote uploading to the ESP8266 using Arduino's OTA library. To utilize this, you'll need to first upload the sketch using the traditional USB method. However, if you need to update your code after that, your WIFI-connected ESP chip should show up as an option under Tools -> Port -> Porch at your.ip.address.xxx. More information on OTA uploading can be found [here](http://esp8266.github.io/Arduino/versions/2.0.0/doc/ota_updates/ota_updates.html). Note: You cannot access the serial monitor over WIFI at this point. - #### Demo Video -[![Demo Video](http://i.imgur.com/cpW2JAX.png)](https://www.youtube.com/watch?v=DQZ4x6Z3678 "Demo - RGB Digital LED Strip controlled using ESP, MQTT, and Home Assistant") #### Tutorial Video -[![Tutorial Video](http://i.imgur.com/9UMl8Xo.jpg)](https://www.youtube.com/watch?v=9KI36GTgwuQ "The BEST Digital LED Strip Light Tutorial - DIY, WIFI-Controllable via ESP, MQTT, and Home Assistant") #### Parts List -- [Digital RGB Leds](http://geni.us/8mBml) -- [NodeMCU](http://geni.us/4pVoT) -- [Aluminum Mounting Channel/Diffuser](http://geni.us/JBDhv7) -- [12v to 5v Step Down](http://geni.us/PghhV9) -- [12V 15amp Power Supply](http://geni.us/8rKC) -- [Strip Connector](http://geni.us/OL7tHv) -- [Logic Level Shifter](http://geni.us/4hJAyy) -- [20 Gauge Wire](http://geni.us/2MBYAXF) -- [Cable Chase](http://geni.us/lFqD) -- [Project Box](http://geni.us/kZRgaj) -- [Header Wires](http://geni.us/GniKAX) -- [Power Jacks](http://geni.us/7Ywdut) - #### Wiring Diagram ![alt text](https://github.com/bruhautomation/ESP-MQTT-Digital-LEDs/blob/master/ESP%20MQTT%20Digital%20LEDs%20Wiring%20Diagram.png?raw=true "Wiring Diagram") - - -#### Home Assistant Service Examples -Besides using the card in Home Assistant's user interface, you can also use the Services tool to control the light using the light.turn_on and light.turn_off services. This will let you play with the parameters you can call later in automations or scripts. - -Fade the Light On Over 5 Seconds - light.turn_on -``` -{"entity_id":"light.porch_strip", -"brightness":150, -"color_name":"blue", -"transition":"5" -} -``` - -Flash The Light - light.turn_on -``` -{"entity_id":"light.porch_strip", -"color_name":"green", -"brightness":255, -"flash":"short" -} -``` - -Call Rainbow Effect with Slow Animation Speed - light.turn_on -``` -{"entity_id":"light.porch_strip", -"transition":"50", -"brightness":255, -"effect":"rainbow" -} -``` - -Fade the Light Off Over 5 Seconds - light.turn_off -``` -{"entity_id":"light.porch_strip", -"transition":"50" -} -``` +Note this modified code uses Pin D3 instead of Pin D5 + +#### Home Assistant Configuration YAML +```` +light: + - platform: mqtt + schema: json + name: "RGB Light Strip" + state_topic: "home/RGBStrip1" + command_topic: "home/RGBStrip1/set" + effect: true + effect_list: + - solid + - musicVisualizer (965) + - musicVisualizer (L2R) + - musicVisualizer (Middle) + - bpm + - candy cane + - confetti + - cyclon rainbow + - dots + - fire + - glitter + - juggle + - lightning + - noise + - police all + - police one + - rainbow + - rainbow with glitter + - ripple + - sinelon + - twinkle + - sinelon + - sine hue + - full hue + - breathe + - hue breathe + - Christmas + - christmas alternate + - random stars + - St Patty + - Valentine + - Turkey Day + - Thanksgiving + - USA + - Independence + - Halloween + - Go Lions + - Hail + - Touchdown + - Punkin + - Lovey Day + - Holly Jolly +```` + +#### Example MQTT Payload +```` + { + "brightness": 120, + "color": { + "r": 255, + "g": 100, + "b": 100 + }, + "flash": 2, + "transition": 5, + "state": "ON" + } +```` From f7823471d7509531bd681712def405bdb9c24810 Mon Sep 17 00:00:00 2001 From: Fma965 Date: Wed, 26 Dec 2018 18:43:21 +0000 Subject: [PATCH 02/17] Update README.md --- README.md | 66 ++++++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 58 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 73a62c9..4b70da4 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,3 @@ -# ESP MQTT JSON Digital LEDs - This is a modified version of https://github.com/bkpsu/ESP-MQTT-JSON-Digital-LEDs which is a modified version of https://github.com/bruhautomation/ESP-MQTT-JSON-Digital-LEDs The code covered in this repository utilizes [Home Assistant's MQTT Light Component](https://home-assistant.io/components/light.mqtt_json/) and an ESP8266 microcontroller. @@ -29,14 +27,10 @@ The default speed for the effects is hard coded and is set when the light is fir This code also supports remote uploading to the ESP8266 using Arduino's OTA library. To utilize this, you'll need to first upload the sketch using the traditional USB method. However, if you need to update your code after that, your WIFI-connected ESP chip should show up as an option under Tools -> Port -> Porch at your.ip.address.xxx. More information on OTA uploading can be found [here](http://esp8266.github.io/Arduino/versions/2.0.0/doc/ota_updates/ota_updates.html). Note: You cannot access the serial monitor over WIFI at this point. #### Demo Video +[![Demo Video](http://i.imgur.com/cpW2JAX.png)](https://www.youtube.com/watch?v=DQZ4x6Z3678 "Demo - RGB Digital LED Strip controlled using ESP, MQTT, and Home Assistant") #### Tutorial Video - -#### Parts List - -#### Wiring Diagram -![alt text](https://github.com/bruhautomation/ESP-MQTT-Digital-LEDs/blob/master/ESP%20MQTT%20Digital%20LEDs%20Wiring%20Diagram.png?raw=true "Wiring Diagram") -Note this modified code uses Pin D3 instead of Pin D5 +[![Tutorial Video](http://i.imgur.com/9UMl8Xo.jpg)](https://www.youtube.com/watch?v=9KI36GTgwuQ "The BEST Digital LED Strip Light Tutorial - DIY, WIFI-Controllable via ESP, MQTT, and Home Assistant") #### Home Assistant Configuration YAML ```` @@ -106,3 +100,59 @@ light: "state": "ON" } ```` + +#### Parts List +- [Digital RGB Leds](http://geni.us/8mBml) +- [NodeMCU](http://geni.us/4pVoT) +- [Aluminum Mounting Channel/Diffuser](http://geni.us/JBDhv7) +- [12v to 5v Step Down](http://geni.us/PghhV9) +- [12V 15amp Power Supply](http://geni.us/8rKC) +- [Strip Connector](http://geni.us/OL7tHv) +- [Logic Level Shifter](http://geni.us/4hJAyy) +- [20 Gauge Wire](http://geni.us/2MBYAXF) +- [Cable Chase](http://geni.us/lFqD) +- [Project Box](http://geni.us/kZRgaj) +- [Header Wires](http://geni.us/GniKAX) +- [Power Jacks](http://geni.us/7Ywdut) + + +#### Wiring Diagram +![alt text](https://github.com/bruhautomation/ESP-MQTT-Digital-LEDs/blob/master/ESP%20MQTT%20Digital%20LEDs%20Wiring%20Diagram.png?raw=true "Wiring Diagram") + + +#### Home Assistant Service Examples +Besides using the card in Home Assistant's user interface, you can also use the Services tool to control the light using the light.turn_on and light.turn_off services. This will let you play with the parameters you can call later in automations or scripts. + +Fade the Light On Over 5 Seconds - light.turn_on +``` +{"entity_id":"light.porch_strip", +"brightness":150, +"color_name":"blue", +"transition":"5" +} +``` + +Flash The Light - light.turn_on +``` +{"entity_id":"light.porch_strip", +"color_name":"green", +"brightness":255, +"flash":"short" +} +``` + +Call Rainbow Effect with Slow Animation Speed - light.turn_on +``` +{"entity_id":"light.porch_strip", +"transition":"50", +"brightness":255, +"effect":"rainbow" +} +``` + +Fade the Light Off Over 5 Seconds - light.turn_off +``` +{"entity_id":"light.porch_strip", +"transition":"50" +} +``` From 9af0870ff9dc0c046dc18c0b466295d28fa2c02d Mon Sep 17 00:00:00 2001 From: Scott Date: Wed, 26 Dec 2018 18:57:53 +0000 Subject: [PATCH 03/17] Update README.md --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 4b70da4..70edec6 100644 --- a/README.md +++ b/README.md @@ -43,9 +43,9 @@ light: effect: true effect_list: - solid - - musicVisualizer (965) - - musicVisualizer (L2R) - - musicVisualizer (Middle) + - Music - L2R + - Music - Middle + - Music - Fma965 - bpm - candy cane - confetti From 1ff8ea1e5dc45c2731614e7aa101306e8c8070e1 Mon Sep 17 00:00:00 2001 From: Fma965 Date: Wed, 26 Dec 2018 19:06:16 +0000 Subject: [PATCH 04/17] bug fix --- ESP_MQTT_Digital_LEDs/ESP_MQTT_Digital_LEDs.ino | 3 ++- README.md | 6 +++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/ESP_MQTT_Digital_LEDs/ESP_MQTT_Digital_LEDs.ino b/ESP_MQTT_Digital_LEDs/ESP_MQTT_Digital_LEDs.ino index f47b15e..4587533 100644 --- a/ESP_MQTT_Digital_LEDs/ESP_MQTT_Digital_LEDs.ino +++ b/ESP_MQTT_Digital_LEDs/ESP_MQTT_Digital_LEDs.ino @@ -1845,7 +1845,8 @@ void RainbowMiddleOut() leds[NUM_LEDS/2-i] = Scroll((i * 256 / NUM_LEDS + k) % 256); } else { - leds[i] = CRGB(0, 0, 0); + leds[NUM_LEDS/2-i] = CRGB(0, 0, 0); + leds[NUM_LEDS/2+i] = CRGB(0, 0, 0); } } FastLED.show(); diff --git a/README.md b/README.md index 4b70da4..70edec6 100644 --- a/README.md +++ b/README.md @@ -43,9 +43,9 @@ light: effect: true effect_list: - solid - - musicVisualizer (965) - - musicVisualizer (L2R) - - musicVisualizer (Middle) + - Music - L2R + - Music - Middle + - Music - Fma965 - bpm - candy cane - confetti From 0d1ed908a76476ec03b0f283bfebe3d24777596f Mon Sep 17 00:00:00 2001 From: Fma965 Date: Wed, 26 Dec 2018 19:17:02 +0000 Subject: [PATCH 05/17] Add Speed control using Transition --- ESP_MQTT_Digital_LEDs/ESP_MQTT_Digital_LEDs.ino | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ESP_MQTT_Digital_LEDs/ESP_MQTT_Digital_LEDs.ino b/ESP_MQTT_Digital_LEDs/ESP_MQTT_Digital_LEDs.ino index 4587533..b16a6d4 100644 --- a/ESP_MQTT_Digital_LEDs/ESP_MQTT_Digital_LEDs.ino +++ b/ESP_MQTT_Digital_LEDs/ESP_MQTT_Digital_LEDs.ino @@ -1822,7 +1822,7 @@ void visualize_music(int LEDDirection) if (react > 0) react--; } - //delay(1); + delay(transitionTime); } // https://github.com/NeverPlayLegit/Rainbow-Fader-FastLED/blob/master/rainbow.ino From 5087a372cae494b16525be831652e8655013b41e Mon Sep 17 00:00:00 2001 From: Fma965 Date: Wed, 26 Dec 2018 20:26:05 +0000 Subject: [PATCH 06/17] optimize the speed slider anything less than 50 is set to delay of 25. all other values are /2 so 150 is 75 --- ESP_MQTT_Digital_LEDs/ESP_MQTT_Digital_LEDs.ino | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/ESP_MQTT_Digital_LEDs/ESP_MQTT_Digital_LEDs.ino b/ESP_MQTT_Digital_LEDs/ESP_MQTT_Digital_LEDs.ino index b16a6d4..634002e 100644 --- a/ESP_MQTT_Digital_LEDs/ESP_MQTT_Digital_LEDs.ino +++ b/ESP_MQTT_Digital_LEDs/ESP_MQTT_Digital_LEDs.ino @@ -97,7 +97,7 @@ byte brightness = 255; /**************************** MUSIC VISUALIZER **************************************************/ #define UPDATES_PER_SECOND 100 -#define MUSIC_SENSITIVITY 4 +#define MUSIC_SENSITIVITY 5 // AUDIO INPUT SETUP int audio = A0; @@ -1814,7 +1814,7 @@ void visualize_music(int LEDDirection) if (k < 0) // RESET COLOR WHEEL k = 255; - // REMOVE LEDs + // REMOVE LEDs decay_check++; if (decay_check > decay) { @@ -1822,7 +1822,11 @@ void visualize_music(int LEDDirection) if (react > 0) react--; } - delay(transitionTime); + if (transitionTime <= 50) { + delay(25); + } else { + delay(transitionTime / 2); + } } // https://github.com/NeverPlayLegit/Rainbow-Fader-FastLED/blob/master/rainbow.ino From 905b2209b617497ae2e7f1ccf975e563fb542abf Mon Sep 17 00:00:00 2001 From: Fma965 Date: Wed, 26 Dec 2018 21:22:27 +0000 Subject: [PATCH 07/17] replaced aniimation slider with white value replaced aniimation slider with white value thanks to TheHookUP's latest video for the idea. --- ESP_MQTT_Digital_LEDs/ESP_MQTT_Digital_LEDs.ino | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/ESP_MQTT_Digital_LEDs/ESP_MQTT_Digital_LEDs.ino b/ESP_MQTT_Digital_LEDs/ESP_MQTT_Digital_LEDs.ino index 634002e..0cfc10c 100644 --- a/ESP_MQTT_Digital_LEDs/ESP_MQTT_Digital_LEDs.ino +++ b/ESP_MQTT_Digital_LEDs/ESP_MQTT_Digital_LEDs.ino @@ -544,7 +544,7 @@ void callback(char* topic, byte* payload, unsigned int length) { realBlue = 0; } - Serial.println(effect); + //Serial.println(effect); startFade = true; inFade = false; // Kill the current fade @@ -605,8 +605,9 @@ bool processJson(char* message) { twinklecounter = 0; //manage twinklecounter } - if (root.containsKey("transition")) { - transitionTime = root["transition"]; + if (root.containsKey("white_value")) { + transitionTime = map(root["white_value"], 0, 255, 1, 150); + //transitionTime = root["transition"]; } else if ( effectString == "solid") { transitionTime = 0; @@ -651,8 +652,8 @@ bool processJson(char* message) { twinklecounter = 0; //manage twinklecounter } - if (root.containsKey("transition")) { - transitionTime = root["transition"]; + if (root.containsKey("white_value")) { + transitionTime = map(root["white_value"], 0, 255, 1, 150); } else if ( effectString == "solid") { transitionTime = 0; @@ -679,7 +680,7 @@ void sendState() { root["brightness"] = brightness; root["effect"] = effectString.c_str(); - root["transition"] = transitionTime; + root["white_value"] = map(transitionTime, 0, 150, 1, 255); char buffer[root.measureLength() + 1]; root.printTo(buffer, sizeof(buffer)); @@ -1814,7 +1815,7 @@ void visualize_music(int LEDDirection) if (k < 0) // RESET COLOR WHEEL k = 255; - // REMOVE LEDs + // REMOVE LEDs decay_check++; if (decay_check > decay) { From 45d691bec2ea51da2c0d82d9071475f1f02ec486 Mon Sep 17 00:00:00 2001 From: Fma965 Date: Wed, 26 Dec 2018 21:24:44 +0000 Subject: [PATCH 08/17] update yaml config --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 70edec6..717ac0c 100644 --- a/README.md +++ b/README.md @@ -41,6 +41,7 @@ light: state_topic: "home/RGBStrip1" command_topic: "home/RGBStrip1/set" effect: true + white_value: true effect_list: - solid - Music - L2R From 989220fbc84b795f3ee6a31df7f5c7f8b51ffb86 Mon Sep 17 00:00:00 2001 From: Fma965 Date: Wed, 26 Dec 2018 21:48:08 +0000 Subject: [PATCH 09/17] Fixed issue with solid constantly updating! --- ESP_MQTT_Digital_LEDs/ESP_MQTT_Digital_LEDs.ino | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/ESP_MQTT_Digital_LEDs/ESP_MQTT_Digital_LEDs.ino b/ESP_MQTT_Digital_LEDs/ESP_MQTT_Digital_LEDs.ino index 0cfc10c..0fe0da0 100644 --- a/ESP_MQTT_Digital_LEDs/ESP_MQTT_Digital_LEDs.ino +++ b/ESP_MQTT_Digital_LEDs/ESP_MQTT_Digital_LEDs.ino @@ -39,7 +39,7 @@ - For a list of the effects that can be used check GitHub */ -//#define FASTLED_INTERRUPT_RETRY_COUNT 0 +define FASTLED_INTERRUPT_RETRY_COUNT 0 #include #include @@ -605,11 +605,11 @@ bool processJson(char* message) { twinklecounter = 0; //manage twinklecounter } - if (root.containsKey("white_value")) { + if (root.containsKey("white_value") && effect != "solid") { transitionTime = map(root["white_value"], 0, 255, 1, 150); //transitionTime = root["transition"]; } - else if ( effectString == "solid") { + else if ( effect == "solid") { transitionTime = 0; } @@ -652,10 +652,11 @@ bool processJson(char* message) { twinklecounter = 0; //manage twinklecounter } - if (root.containsKey("white_value")) { + if (root.containsKey("white_value") && effect != "solid") { transitionTime = map(root["white_value"], 0, 255, 1, 150); + //transitionTime = root["transition"]; } - else if ( effectString == "solid") { + else if ( effect == "solid") { transitionTime = 0; } @@ -680,7 +681,7 @@ void sendState() { root["brightness"] = brightness; root["effect"] = effectString.c_str(); - root["white_value"] = map(transitionTime, 0, 150, 1, 255); + root["white_value"] = map(transitionTime, 1,150, 0, 255); char buffer[root.measureLength() + 1]; root.printTo(buffer, sizeof(buffer)); From ff36c3ee99324e19d6a45fb2a9c002f7bd732e39 Mon Sep 17 00:00:00 2001 From: Nikola <40897274+niksy111@users.noreply.github.com> Date: Sun, 30 Dec 2018 10:32:46 +0100 Subject: [PATCH 10/17] Missing # You missed # at start of the code. --- ESP_MQTT_Digital_LEDs/ESP_MQTT_Digital_LEDs.ino | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ESP_MQTT_Digital_LEDs/ESP_MQTT_Digital_LEDs.ino b/ESP_MQTT_Digital_LEDs/ESP_MQTT_Digital_LEDs.ino index 0fe0da0..71c9a6b 100644 --- a/ESP_MQTT_Digital_LEDs/ESP_MQTT_Digital_LEDs.ino +++ b/ESP_MQTT_Digital_LEDs/ESP_MQTT_Digital_LEDs.ino @@ -39,7 +39,7 @@ - For a list of the effects that can be used check GitHub */ -define FASTLED_INTERRUPT_RETRY_COUNT 0 +#define FASTLED_INTERRUPT_RETRY_COUNT 0 #include #include @@ -1879,4 +1879,4 @@ void RainbowFma965() } } FastLED.show(); -} \ No newline at end of file +} From f5216388cc23a1cc3360be71b91a48b791ea71ed Mon Sep 17 00:00:00 2001 From: Fma965 Date: Sun, 13 Jan 2019 16:30:24 +0000 Subject: [PATCH 11/17] V1.1 Fixed a bunch of bugs, solid wasn't able to be turned off, also added a new Left + Right to middle music effect, "Music - LR2M", set the whitevalue to control transition speed, set the whitevalue to control music sensitivity in music effect --- .../ESP_MQTT_Digital_LEDs.ino | 59 +++++++++++------ Example Home Assistant Configuration.yaml | 64 ++++++++++--------- 2 files changed, 75 insertions(+), 48 deletions(-) diff --git a/ESP_MQTT_Digital_LEDs/ESP_MQTT_Digital_LEDs.ino b/ESP_MQTT_Digital_LEDs/ESP_MQTT_Digital_LEDs.ino index 0fe0da0..58361a6 100644 --- a/ESP_MQTT_Digital_LEDs/ESP_MQTT_Digital_LEDs.ino +++ b/ESP_MQTT_Digital_LEDs/ESP_MQTT_Digital_LEDs.ino @@ -67,6 +67,7 @@ int OTAport = 8266; /************* MQTT TOPICS (change these topics as you wish) **************************/ const char* light_state_topic = "home/RGBStrip1"; const char* light_set_topic = "home/RGBStrip1/set"; +const char* light_set_topic_group = "home/LEDStrip_Group1/set"; const char* on_cmd = "ON"; const char* off_cmd = "OFF"; @@ -97,7 +98,9 @@ byte brightness = 255; /**************************** MUSIC VISUALIZER **************************************************/ #define UPDATES_PER_SECOND 100 -#define MUSIC_SENSITIVITY 5 + +#define MUSIC_SENSITIVITY 4 +//To set a fixed MUSIC_SENSITIVITY you must un comment the line "int audio_input = analogRead(audio) * MUSIC_SENSITIVITY;" near the bottom. // AUDIO INPUT SETUP int audio = A0; @@ -605,11 +608,10 @@ bool processJson(char* message) { twinklecounter = 0; //manage twinklecounter } - if (root.containsKey("white_value") && effect != "solid") { + if (root.containsKey("white_value")) { transitionTime = map(root["white_value"], 0, 255, 1, 150); - //transitionTime = root["transition"]; } - else if ( effect == "solid") { + else if ( effectString == "solid") { transitionTime = 0; } @@ -652,14 +654,12 @@ bool processJson(char* message) { twinklecounter = 0; //manage twinklecounter } - if (root.containsKey("white_value") && effect != "solid") { + if (root.containsKey("white_value")) { transitionTime = map(root["white_value"], 0, 255, 1, 150); - //transitionTime = root["transition"]; } - else if ( effect == "solid") { + else if ( effectString == "solid") { transitionTime = 0; } - } return true; @@ -698,6 +698,7 @@ void reconnect() { if (client.connect(SENSORNAME, mqtt_username, mqtt_password)) { Serial.println("connected"); client.subscribe(light_set_topic); + client.subscribe(light_set_topic_group); setColor(0, 0, 0); sendState(); } else { @@ -763,6 +764,10 @@ void loop() { if(effectString == "Music - Fma965") { visualize_music(3); } + // Out to Middle + if(effectString == "Music - LR2M") { + visualize_music(4); + } ///////////////////////////////////////// //////DrZzs custom effects////////////// @@ -1789,18 +1794,18 @@ CRGB Scroll(int pos) { void visualize_music(int LEDDirection) { - int audio_input = analogRead(audio) * MUSIC_SENSITIVITY; - + //int audio_input = analogRead(audio) * MUSIC_SENSITIVITY; +int audio_input = analogRead(audio) * map(transitionTime, 1, 150, 2, 7); if (audio_input > 0) { if(LEDDirection == 1) { pre_react = ((long)NUM_LEDS * (long)audio_input) / 1023L; // TRANSLATE AUDIO LEVEL TO NUMBER OF LEDs - } else if(LEDDirection == 2) { + } else if(LEDDirection == 2 || LEDDirection == 4) { pre_react = ((long)NUM_LEDS/2 * (long)audio_input) / 1023L; // TRANSLATE AUDIO LEVEL TO NUMBER OF LEDs } else if(LEDDirection == 3) { pre_react = ((long)NUM_LEDS/4 * (long)audio_input) / 1023L; // TRANSLATE AUDIO LEVEL TO NUMBER OF LEDs } - + if (pre_react > react) // ONLY ADJUST LEVEL OF LED IF LEVEL HIGHER THAN CURRENT LEVEL react = pre_react; } @@ -1810,6 +1815,8 @@ void visualize_music(int LEDDirection) RainbowMiddleOut(); //Middle Out } else if(LEDDirection == 3) { RainbowFma965(); //Custom setup for Fma965 + } else if(LEDDirection == 4) { + RainbowOutMiddle(); //Out to Middle } k = k - wheel_speed; // SPEED OF COLOR WHEEL @@ -1848,34 +1855,48 @@ void RainbowMiddleOut() for(int i = 0; i < NUM_LEDS/2; i++) { if (i < react) { leds[NUM_LEDS/2+i] = Scroll((i * 256 / NUM_LEDS + k) % 256); - leds[NUM_LEDS/2-i] = Scroll((i * 256 / NUM_LEDS + k) % 256); + leds[NUM_LEDS/2-i-1] = Scroll((i * 256 / NUM_LEDS + k) % 256); } else { - leds[NUM_LEDS/2-i] = CRGB(0, 0, 0); - leds[NUM_LEDS/2+i] = CRGB(0, 0, 0); + leds[NUM_LEDS/2+i] = CRGB(0, 0, 0); + leds[NUM_LEDS/2-i-1] = CRGB(0, 0, 0); } } FastLED.show(); } +void RainbowOutMiddle() +{ + for(int i = 0; i < NUM_LEDS/2+1; i++) { + if (i < react) { + leds[0+i] = Scroll((i * 256 / NUM_LEDS + k) % 256); + leds[NUM_LEDS-i] = Scroll((i * 256 / NUM_LEDS + k) % 256); + } else { + leds[0+i] = CRGB(0, 0, 0); + leds[NUM_LEDS-i] = CRGB(0, 0, 0); + } + } + FastLED.show(); +} + void RainbowFma965() { for(int i = 0; i < 21; i++) { if (i < react) { - leds[42-i] = Scroll((i * 256 / NUM_LEDS + k) % 256); + leds[42-i-1] = Scroll((i * 256 / NUM_LEDS + k) % 256); leds[42+i] = Scroll((i * 256 / NUM_LEDS + k) % 256); } else { - leds[42-i] = CRGB(0, 0, 0); + leds[42-i-1] = CRGB(0, 0, 0); leds[42+i] = CRGB(0, 0, 0); } } for(int i = 0; i < 12; i++) { if (i < react) { leds[10+i] = Scroll((i * 256 / NUM_LEDS + k) % 256); - leds[10-i] = Scroll((i * 256 / NUM_LEDS + k) % 256); + leds[10-i-1] = Scroll((i * 256 / NUM_LEDS + k) % 256); } else { leds[10+i] = CRGB(0, 0, 0); - leds[10-i] = CRGB(0, 0, 0); + leds[10-i-1] = CRGB(0, 0, 0); } } FastLED.show(); diff --git a/Example Home Assistant Configuration.yaml b/Example Home Assistant Configuration.yaml index fedca29..38b68ad 100644 --- a/Example Home Assistant Configuration.yaml +++ b/Example Home Assistant Configuration.yaml @@ -6,12 +6,19 @@ mqtt: password: YOURPASSWORD light: - - platform: mqtt_json - name: "Porch Strip" - state_topic: "bruh/porch" - command_topic: "bruh/porch/set" + - platform: mqtt + schema: json + name: "RGB Light Strip 1" + state_topic: "home/RGBStrip1" + command_topic: "home/RGBStrip1/set" + white_value: true effect: true effect_list: + - solid + - Music - L2R + - Music - Middle + - Music - LR2M + - Music - Fma965 - bpm - candy cane - confetti @@ -27,32 +34,31 @@ light: - rainbow - rainbow with glitter - ripple - - sinelon - - solid - - twinkle + - sinelon + - twinkle + - sinelon + - sine hue + - full hue + - breathe + - hue breathe + - Christmas + - christmas alternate + - random stars + - St Patty + - Valentine + - Turkey Day + - Thanksgiving + - USA + - Independence + - Halloween + - Go Lions + - Hail + - Touchdown + - Punkin + - Lovey Day + - Holly Jolly brightness: true flash: true rgb: true optimistic: false - qos: 0 - -input_slider: - porch_animation_speed: - name: Porch Animation Speed - initial: 150 - min: 1 - max: 150 - step: 10 - -automation: - - alias: "Porch Animation Speed" - initial_state: True - hide_entity: False - trigger: - - platform: state - entity_id: input_slider.porch_animation_speed - action: - - service: mqtt.publish - data_template: - topic: "bruh/porch/set" - payload: '{"transition":{{ trigger.to_state.state | int }}}' + qos: 0 \ No newline at end of file From 6a4c75e83c0c4f5bf3f9c8395bdd9d974493d4c9 Mon Sep 17 00:00:00 2001 From: Fma965 Date: Sun, 13 Jan 2019 16:32:19 +0000 Subject: [PATCH 12/17] Update README.md --- README.md | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 717ac0c..aed5c8b 100644 --- a/README.md +++ b/README.md @@ -10,9 +10,9 @@ I would suggest using the same versions of libraries to minimize potential isues - Flash - Fade - Transitions -- Effects with Animation Speed +- Effects with Animation Speed controlled with White_Value for ease of use - Over-the-Air (OTA) Upload from the ArduinoIDE! -- Music Visualizer (Left to Right and Middle) +- Music Visualizer (Various effects), sensitivity controlled by White_Value - DrZZs Effects - bkpsu Effects @@ -34,18 +34,26 @@ This code also supports remote uploading to the ESP8266 using Arduino's OTA libr #### Home Assistant Configuration YAML ```` +mqtt: + broker: your.mqtt.ip.address + port: 1883 + client_id: home-assistant-1 + username: YOURUSERNAME + password: YOURPASSWORD + light: - platform: mqtt schema: json - name: "RGB Light Strip" + name: "RGB Light Strip 1" state_topic: "home/RGBStrip1" command_topic: "home/RGBStrip1/set" + white_value: true effect: true - white_value: true effect_list: - solid - Music - L2R - Music - Middle + - Music - LR2M - Music - Fma965 - bpm - candy cane @@ -84,7 +92,12 @@ light: - Touchdown - Punkin - Lovey Day - - Holly Jolly + - Holly Jolly + brightness: true + flash: true + rgb: true + optimistic: false + qos: 0 ```` #### Example MQTT Payload @@ -145,7 +158,7 @@ Flash The Light - light.turn_on Call Rainbow Effect with Slow Animation Speed - light.turn_on ``` {"entity_id":"light.porch_strip", -"transition":"50", +"white_value":"50", "brightness":255, "effect":"rainbow" } @@ -154,6 +167,6 @@ Call Rainbow Effect with Slow Animation Speed - light.turn_on Fade the Light Off Over 5 Seconds - light.turn_off ``` {"entity_id":"light.porch_strip", -"transition":"50" +"white_value":"50" } ``` From 68f6d01f7025af80a45ee7512fc9a7ccdad3337d Mon Sep 17 00:00:00 2001 From: Fma965 Date: Sun, 13 Jan 2019 17:01:09 +0000 Subject: [PATCH 13/17] add LWT by Joeboyc2 --- ESP_MQTT_Digital_LEDs/ESP_MQTT_Digital_LEDs.ino | 6 +++++- Example Home Assistant Configuration.yaml | 1 + README.md | 1 + 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/ESP_MQTT_Digital_LEDs/ESP_MQTT_Digital_LEDs.ino b/ESP_MQTT_Digital_LEDs/ESP_MQTT_Digital_LEDs.ino index 5c3b1e0..90e9f4f 100644 --- a/ESP_MQTT_Digital_LEDs/ESP_MQTT_Digital_LEDs.ino +++ b/ESP_MQTT_Digital_LEDs/ESP_MQTT_Digital_LEDs.ino @@ -68,6 +68,7 @@ int OTAport = 8266; const char* light_state_topic = "home/RGBStrip1"; const char* light_set_topic = "home/RGBStrip1/set"; const char* light_set_topic_group = "home/LEDStrip_Group1/set"; +const char* LWT_topic = "home/RGBStrip1/LWT"; const char* on_cmd = "ON"; const char* off_cmd = "OFF"; @@ -695,10 +696,11 @@ void reconnect() { while (!client.connected()) { Serial.print("Attempting MQTT connection..."); // Attempt to connect - if (client.connect(SENSORNAME, mqtt_username, mqtt_password)) { + if (client.connect(SENSORNAME, mqtt_username, mqtt_password, LWT_topic, 0, 1, "offline")) { Serial.println("connected"); client.subscribe(light_set_topic); client.subscribe(light_set_topic_group); + client.publish(LWT_topic, "online", true); setColor(0, 0, 0); sendState(); } else { @@ -1901,3 +1903,5 @@ void RainbowFma965() } FastLED.show(); } + + diff --git a/Example Home Assistant Configuration.yaml b/Example Home Assistant Configuration.yaml index 38b68ad..ccb3cce 100644 --- a/Example Home Assistant Configuration.yaml +++ b/Example Home Assistant Configuration.yaml @@ -11,6 +11,7 @@ light: name: "RGB Light Strip 1" state_topic: "home/RGBStrip1" command_topic: "home/RGBStrip1/set" + availability_topic: "home/RGBStrip1/LWT" white_value: true effect: true effect_list: diff --git a/README.md b/README.md index aed5c8b..ea50af7 100644 --- a/README.md +++ b/README.md @@ -47,6 +47,7 @@ light: name: "RGB Light Strip 1" state_topic: "home/RGBStrip1" command_topic: "home/RGBStrip1/set" + availability_topic: "home/RGBStrip1/LWT" white_value: true effect: true effect_list: From 491c0e76b963cc9b6eb362934ecfb956afe6da69 Mon Sep 17 00:00:00 2001 From: Scott Date: Tue, 22 Jan 2019 12:51:30 +0000 Subject: [PATCH 14/17] Update README.md --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index ea50af7..aa169b6 100644 --- a/README.md +++ b/README.md @@ -132,6 +132,7 @@ light: #### Wiring Diagram +PLEASE NOTE I USE PIN D3 IN MY CODE, NOT D5 ![alt text](https://github.com/bruhautomation/ESP-MQTT-Digital-LEDs/blob/master/ESP%20MQTT%20Digital%20LEDs%20Wiring%20Diagram.png?raw=true "Wiring Diagram") From 64393298030663e47138da3f9be734658806d17c Mon Sep 17 00:00:00 2001 From: Scott Date: Tue, 20 Aug 2019 14:52:28 +0100 Subject: [PATCH 15/17] corrected json for newer HA --- README.md | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index aa169b6..e5f6c56 100644 --- a/README.md +++ b/README.md @@ -42,19 +42,19 @@ mqtt: password: YOURPASSWORD light: - - platform: mqtt + - platform: mqtt schema: json name: "RGB Light Strip 1" state_topic: "home/RGBStrip1" command_topic: "home/RGBStrip1/set" - availability_topic: "home/RGBStrip1/LWT" + rgb: true + availability_topic: "home/RGBStrip1/LWT" white_value: true effect: true effect_list: - solid - Music - L2R - Music - Middle - - Music - LR2M - Music - Fma965 - bpm - candy cane @@ -70,8 +70,7 @@ light: - police one - rainbow - rainbow with glitter - - ripple - - sinelon + - ripple - twinkle - sinelon - sine hue @@ -95,8 +94,6 @@ light: - Lovey Day - Holly Jolly brightness: true - flash: true - rgb: true optimistic: false qos: 0 ```` From a3064ff7ee7f36ba387b1a4c48067786c11fc528 Mon Sep 17 00:00:00 2001 From: Scott Date: Tue, 20 Aug 2019 14:53:00 +0100 Subject: [PATCH 16/17] updated config --- Example Home Assistant Configuration.yaml | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/Example Home Assistant Configuration.yaml b/Example Home Assistant Configuration.yaml index ccb3cce..8b7c38b 100644 --- a/Example Home Assistant Configuration.yaml +++ b/Example Home Assistant Configuration.yaml @@ -6,11 +6,12 @@ mqtt: password: YOURPASSWORD light: - - platform: mqtt + - platform: mqtt schema: json name: "RGB Light Strip 1" state_topic: "home/RGBStrip1" command_topic: "home/RGBStrip1/set" + rgb: true availability_topic: "home/RGBStrip1/LWT" white_value: true effect: true @@ -18,7 +19,6 @@ light: - solid - Music - L2R - Music - Middle - - Music - LR2M - Music - Fma965 - bpm - candy cane @@ -34,8 +34,7 @@ light: - police one - rainbow - rainbow with glitter - - ripple - - sinelon + - ripple - twinkle - sinelon - sine hue @@ -59,7 +58,5 @@ light: - Lovey Day - Holly Jolly brightness: true - flash: true - rgb: true optimistic: false - qos: 0 \ No newline at end of file + qos: 0 From ebf83a9371194a74ccb7840c5e5d906c18b5a006 Mon Sep 17 00:00:00 2001 From: Scott Date: Thu, 20 May 2021 18:51:46 +0100 Subject: [PATCH 17/17] Update README.md --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index e5f6c56..e55e59c 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,5 @@ +`This repo is no longer updated as i have switched to using https://github.com/Aircoookie/WLED + This is a modified version of https://github.com/bkpsu/ESP-MQTT-JSON-Digital-LEDs which is a modified version of https://github.com/bruhautomation/ESP-MQTT-JSON-Digital-LEDs The code covered in this repository utilizes [Home Assistant's MQTT Light Component](https://home-assistant.io/components/light.mqtt_json/) and an ESP8266 microcontroller.