commit 8dafbb2b68474d3c7e558c45ef5b079817a20abb Author: Julien Cabillot Date: Mon Apr 24 01:28:35 2017 +0200 WIP: structure diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..e9a7126 --- /dev/null +++ b/.gitignore @@ -0,0 +1,8 @@ +.vscode/* +arduino/alarmclock/alarmclock.h +.travis.yml +lib/* +.pioenvs +.piolibdeps +.clang_complete +.gcc-flags.json diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml new file mode 100644 index 0000000..55abb96 --- /dev/null +++ b/.gitlab-ci.yml @@ -0,0 +1,27 @@ +inocode: + image: "java:8" + variables: + ESPURL: "http://arduino.esp8266.com/stable/package_esp8266com_index.json" + MEMORY: "custom_FlashSize=nodemcuv2_4M3M" + INSTBOARD: "esp8266:esp8266" + BOARD: "${INSTBOARD}:nodemcuv2" + before_script: + - cd / + - wget --quiet "https://www.arduino.cc/download.php?f=/arduino-nightly-linux64.tar.xz" -O "arduino-nightly-linux64.tar.xz" + - tar axf "arduino-nightly-linux64.tar.xz" + - /arduino-nightly/arduino --pref "boardsmanager.additional.urls=${ESPURL}" + - /arduino-nightly/arduino --install-boards "${INSTBOARD}" + script: + - cd "${CI_PROJECT_DIR}/arduino/${CI_PROJECT_NAME}" + - cp "${CI_PROJECT_NAME}.example.h" "${CI_PROJECT_NAME}.h" + - /arduino-nightly/arduino --install-library "FastLED" + - /arduino-nightly/arduino --install-library "PubSubClient" + - /arduino-nightly/arduino --pref "${MEMORY}" --board "${BOARD}" --verify "${CI_PROJECT_NAME}.ino" + +yaml: + image: "python:alpine" + before_script: + - pip install "PyYAML" + script: + - cd "${CI_PROJECT_DIR}/home-assistant" + - python -c "from yaml import load, Loader; load(open('ha_configuration.yml'), Loader=Loader)" diff --git a/README.md b/README.md new file mode 100644 index 0000000..b47c167 --- /dev/null +++ b/README.md @@ -0,0 +1,37 @@ +Introduction +============ + +Le but est simple : avoir un device qui pull du mqtt afin de surveiller un etat et une couleur. +Lorsque HA déclenche la commande "ON", on s'allume et on fait un breath sympas sur la couleur choisie. +Lorsque HA demande le "OFF", on coupe tout. + +Un exemple de configuration pour home-assistant se trouve dans [ha_configuration.yml](home-assistant/configuration.yaml). + +Matériel +======== + * 1x ESP8266 Lolin (Nodemcu v3) + * 1x Breadboard + * 1x Resistance 220Ω (jusqu'à 1kΩ) + * 1x Condensateur 1000μF + * 1x LED Strip wb2812b + * 1x Logic Level Translator + * 1x Transformateur AC-DC 220v-5v + +Consommation +============ + +Avec les wb2812b il faut prévoir : +0.05A par LED au maximum (blanc intense) à 5V +```NbreLed * 0.05 * 5 = Puissance maximum en Watts nécessaire``` + +Médias +====== + +![Fritzing BreadBoard](medias/alarmclock.png) +![IRL](medias/irl1.jpg) + +Avancement +========== +WIP. +TODO: Utiliser ArduinoOTA pour gérer les mises à jours sans fil. +TODO: ajouter l'url ou j'ai trouvé ce truc pour HA diff --git a/arduino/alarmclock/alarmclock.cpp b/arduino/alarmclock/alarmclock.cpp new file mode 100644 index 0000000..d403eba --- /dev/null +++ b/arduino/alarmclock/alarmclock.cpp @@ -0,0 +1,534 @@ +#include + +#define FASTLED_ESP8266_NODEMCU_PIN_ORDER +#include +#include +#include + +#include "alarmclock.h" + + +# TODO : tout reste à faire, ceci est la copie de mqttfastledmenu à adapter + +// LED +// En déplaçant ces vars dans le .h + init dans le setup, cylon crash au moment du premier retour ?! +float brightness = LED_BRIGHTNESS_DEFAULT; +int color = LED_COLOR_DEFAULT; +int speed = LED_SPEED_DEFAULT; +CRGB leds[LED_NUM]; +String ledEffect = LED_EFFECT_ERROR; +boolean ledState = false; + +// WIFI +WiFiClient espClient; + +// MQTT +char message_buff[100]; +PubSubClient client(espClient); + +void setup() +{ + Serial.begin(SERIAL_SPEED); + Serial.println("\nresetting"); + + // WIFI + setupWifi(); + + // LED + /* + brightness = LED_BRIGHTNESS_DEFAULT; + color = LED_COLOR_DEFAULT; + speed = LED_SPEED_DEFAULT; + ledEffect = LED_EFFECT_ERROR; + ledState = false; + */ + + LEDS.addLeds(leds, LED_NUM).setCorrection(TypicalSMD5050); + ledBlackAll(); + FastLED.setBrightness(brightness); + + //////////////////////////////// ColorPalette /////////////////////////////// + currentPalette = RainbowColors_p; + currentBlending = LINEARBLEND; + //////////////////////////////// ColorPalette /////////////////////////////// + + // MQTT + client.setServer(MQTT_SERVER, MQTT_PORT); + client.setCallback(callbackMQTT); + testConnectMQTT(); + + Serial.println("Ready"); + + /* MQTT + * Il est important de faire un loop avant toute chose, + * afin de récupérer les valeurs provenant du broker mqtt + * et pas démarrer avec de vieilles infos. + * Il faut un certains nombres de tentative pour tout récuperer. + */ + for (short int i = 0; i < 10; i++) { + delay(200); + client.loop(); + } + + Serial.println("End of setup"); +} + +// WIFI +void setupWifi() +{ + Serial.print("Connexion a "); + Serial.print(WIFI_SSID); + WiFi.mode(WIFI_STA); + WiFi.begin(WIFI_SSID, WIFI_PASSWORD); + + while (WiFi.status() != WL_CONNECTED) { + delay(500); + Serial.print("."); + } + Serial.println(" OK"); + Serial.print("IP : "); + Serial.println(WiFi.localIP()); +} + +// MQTT +void testConnectMQTT() +{ + while (!client.connected()) { + Serial.print("Connexion au serveur MQTT... "); + if (client.connect("ESP8266Client", MQTT_USER, MQTT_PASS)) { + Serial.print("OK\nSend Current State"); + mqttSendState(); + mqttSendSpeedState(); + mqttSendBrightnessState(); + mqttSendEffectState(); + mqttSendColorState(); + + Serial.print("OK\nSubscribe"); + client.subscribe(MQTT_LED_COMMAND); + client.subscribe(MQTT_LED_EFFECT_COMMAND); + client.subscribe(MQTT_LED_BRIGHTNESS_COMMAND); + client.subscribe(MQTT_LED_SPEED_COMMAND); + client.subscribe(MQTT_LED_COLOR_COMMAND); + + Serial.println(" OK"); + } else { + Serial.print("KO, erreur : "); + Serial.print(client.state()); + Serial.println(", on attend 5 secondes avant de recommencer"); + delay(5000); + } + } +} + +// Déclenche les actions à la réception d'un message +void callbackMQTT(char* topic, byte* payload, unsigned int length) +{ + String stopic = String(topic); + + unsigned int i = 0; + for(i = 0; i < length; i++) { + message_buff[i] = payload[i]; + } + message_buff[i] = '\0'; + String msgString = String(message_buff); + + Serial.print("Received [" + stopic + "] : "); + Serial.println(msgString); + + if (stopic == MQTT_LED_COMMAND) { + if (msgString == "ON") { + ledState = true; + } else { + ledState = false; + ledBlackAll(); + } + mqttSendState(); + } else if (stopic == MQTT_LED_EFFECT_COMMAND) { + // Si on ne repasse pas tout à noir, cela peut faire des effets surprenants + ledBlackAll(); + ledEffect = msgString; + mqttSendEffectState(); + } else if (stopic == MQTT_LED_BRIGHTNESS_COMMAND) { + brightness = msgString.toInt(); + FastLED.setBrightness(brightness); + mqttSendBrightnessState(); + } else if (stopic == MQTT_LED_COLOR_COMMAND) { + // Sample : 134,168,255 + int red = msgString.substring(0, msgString.indexOf(',')).toInt(); + int green = msgString.substring(msgString.indexOf(',') + 1, msgString.lastIndexOf(',')).toInt(); + int blue = msgString.substring(msgString.lastIndexOf(',') + 1).toInt(); + + color=((red <<16)|(green <<8)|blue); + mqttSendColorState(); + } else if (stopic == MQTT_LED_SPEED_COMMAND) { + speed = msgString.toInt(); + mqttSendSpeedState(); + } +} + +void mqttSendState() +{ + client.publish(MQTT_LED_STATE, (ledState) ? "ON": "OFF", true); +} + +void mqttSendEffectState() +{ + char buff[ledEffect.length() + 1]; + ledEffect.toCharArray(buff, ledEffect.length() + 1); + client.publish(MQTT_LED_EFFECT_STATE, buff, true); +} + +void mqttSendBrightnessState() +{ + char buff[4]; + itoa(brightness, buff, 10); + client.publish(MQTT_LED_BRIGHTNESS_STATE, buff, true); +} + +void mqttSendSpeedState() +{ + char buff[4]; + itoa(speed, buff, 10); + client.publish(MQTT_LED_SPEED_STATE, buff, true); +} + +void mqttSendColorState() +{ + int red = color>>16 & 0xFF; + int green = color>>8 & 0xFF; + int blue = color & 0xFF; + char buff[12]; + + sprintf(buff, "%i,%i,%i", red, green, blue); + client.publish(MQTT_LED_COLOR_STATE, buff, true); +} + +// LED +/** +* Coupe tout le strip de led. +*/ +void ledBlackAll() +{ + FastLED.clear(); + FastLED.show(); +} + +/** +* Effet Cylon : défilement d'une simple led sur le strip aller/retour. +* Pour faire plus sympas on ajoute une lueur autour, avec une lumière atténué. +*/ +void ledCylon() +{ + for (int i = 0; i < LED_NUM; i++) { + client.loop(); + + if (ledEffect != LED_EFFECT_CYLON) { + return; + } + + if ((i - 3) >= 0) { + leds[i - 3] = CRGB::Black; + } + if ((i - 2) >= 0) { + /* + * Se lit 128/256 d'intensité lumineuse actuelle + * https://github.com/FastLED/FastLED/wiki/Pixel-reference#dimming-and-brightening-colors + */ + leds[i - 2] = color; + leds[i - 2].fadeLightBy(220); + } + if ((i - 1) >= 0) { + leds[i - 1] = color; + leds[i - 1].fadeLightBy(200); + } + + leds[i] = color; + + if ((i + 1) <= LED_NUM) { + leds[i + 1] = color; + // Je suis volontairement un peu moins puissant sur l'avant + // pour donner un effet de trainée sur l'arrière + leds[i + 1].fadeLightBy(249); + } + + FastLED.delay(1000 / speed); + } + // Il faut nettoyer certaines cases avant la prochaine loop + if ((LED_NUM - 2) >= 0) { + leds[LED_NUM - 2] = color; + leds[LED_NUM - 2].fadeLightBy(220); + } + if ((LED_NUM - 1) >= 0 ) { + leds[LED_NUM - 1] = CRGB::Black; + } + FastLED.show(); + + // led[0] et led[255] sont gérées par la loop précédante + for (int i = LED_NUM - 1; i >= 0; i--) { + client.loop(); + if (ledEffect != LED_EFFECT_CYLON) { + return; + } + if ((i - 1) >= 0) { + leds[i - 1] = color; + leds[i - 1].fadeLightBy(249); + } + + leds[i] = color; + + if ((i + 1) <= LED_NUM) { + leds[i + 1] = color; + leds[i + 1].fadeLightBy(200); + } + + if ((i + 2) <= LED_NUM) { + leds[i + 2] = color; + leds[i + 2].fadeLightBy(220); + } + + if ((i + 3) <= LED_NUM) { + leds[i + 3] = CRGB::Black; + } + FastLED.delay(1000 / speed); + } + // Il faut nettoyer certaines cases avant la prochaine loop + if (1 <= LED_NUM) { + leds[1] = color; + leds[1].fadeLightBy(220); + } + if (2 <= LED_NUM) { + leds[2] = CRGB::Black; + } + FastLED.show(); +} + +/** + * Utilise pour indiquer une erreur sur la reception de l'effet. + */ +void ledError() +{ + for (int i = 0; i < LED_NUM; i++) { + if ((i % 2) == 0) { + leds[i] = CRGB::Black; + } else { + leds[i] = CRGB::Red; + } + } + + FastLED.delay(1000 / speed); +} + +/** + * Affiche une couleur de manière uniforme sur le strip. + * Pour éviter un éclairage basique, on applique un breath qui permet + * de faire respirer la couleur (brightness). + */ +void ledFullColor() +{ + + // Source : http://sean.voisen.org/blog/2011/10/breathing-led-with-arduino/ + // Voic la version avec la gestion du speed, mais je ne suis pas convaincu + //float breath = (exp(sin(millis() / 2000.0 * map(speed, 0, 255, 50, 300)/100 * PI)) - 0.3678794) * 108.4; + float breath = (exp(sin(millis() / 4000.0 * PI)) - 0.3678794) * 108.4; + + // J'ai essayé de mapper breath sur 3;brightness pour ne pas eteindre les leds, + // mais l'effet est plus saccadé + + fill_solid(leds, LED_NUM, color); + FastLED.setBrightness(breath); + FastLED.show(); +} + +///////////////////// FastLED-3.1.5/examples/ColorPalette ///////////////////// +void ledColorPattern() +{ + ChangePalettePeriodically(); + + static uint8_t startIndex = 0; + startIndex = startIndex + 1; /* motion speed */ + + FillLEDsFromPaletteColors(startIndex); + + FastLED.delay(1000 / speed); +} + +void FillLEDsFromPaletteColors(uint8_t colorIndex) +{ + uint8_t brightness = 255; + + for( int i = 0; i < LED_NUM; i++) { + leds[i] = ColorFromPalette( + currentPalette, + colorIndex, + brightness, + currentBlending + ); + colorIndex += 3; + } +} + +// There are several different palettes of colors demonstrated here. +// +// FastLED provides several 'preset' palettes: RainbowColors_p, RainbowStripeColors_p, +// OceanColors_p, CloudColors_p, LavaColors_p, ForestColors_p, and PartyColors_p. +// +// Additionally, you can manually define your own color palettes, or you can write +// code that creates color palettes on the fly. All are shown here. +void ChangePalettePeriodically() +{ + uint8_t secondHand = (millis() / 1000) % 60; + static uint8_t lastSecond = 99; + + if( lastSecond != secondHand) { + lastSecond = secondHand; + /* + if (secondHand == 0) { currentPalette = RainbowColors_p; currentBlending = LINEARBLEND; } + if (secondHand == 10) { currentPalette = RainbowStripeColors_p; currentBlending = NOBLEND; } + if (secondHand == 15) { currentPalette = RainbowStripeColors_p; currentBlending = LINEARBLEND; } + if (secondHand == 20) { SetupPurpleAndGreenPalette(); currentBlending = LINEARBLEND; } + if (secondHand == 25) { SetupTotallyRandomPalette(); currentBlending = LINEARBLEND; } + if (secondHand == 30) { SetupBlackAndWhiteStripedPalette(); currentBlending = NOBLEND; } + if (secondHand == 35) { SetupBlackAndWhiteStripedPalette(); currentBlending = LINEARBLEND; } + if (secondHand == 40) { currentPalette = CloudColors_p; currentBlending = LINEARBLEND; } + if (secondHand == 45) { currentPalette = PartyColors_p; currentBlending = LINEARBLEND; } + if (secondHand == 50) { currentPalette = myRedWhiteBluePalette_p; currentBlending = NOBLEND; } + if (secondHand == 55) { currentPalette = myRedWhiteBluePalette_p; currentBlending = LINEARBLEND; } + */ + if (secondHand == 0) { SetupPurpleAndGreenPalette(); currentBlending = LINEARBLEND; } + if (secondHand == 10) { SetupBlackAndWhiteStripedPalette(); currentBlending = LINEARBLEND; } + if (secondHand == 30) { currentPalette = CloudColors_p; currentBlending = LINEARBLEND; } + if (secondHand == 40) { currentPalette = myRedWhiteBluePalette_p; currentBlending = LINEARBLEND; } + } +} + +/* +// This function fills the palette with totally random colors. +void SetupTotallyRandomPalette() +{ + for (int i = 0; i < 16; i++) { + currentPalette[i] = CHSV(random8(), 255, random8()); + } +} +*/ + +// This function sets up a palette of black and white stripes, +// using code. Since the palette is effectively an array of +// sixteen CRGB colors, the various fill_* functions can be used +// to set them up. +void SetupBlackAndWhiteStripedPalette() +{ + // 'black out' all 16 palette entries... + fill_solid(currentPalette, 16, CRGB::Black); + // and set every fourth one to white. + currentPalette[0] = CRGB::White; + currentPalette[4] = CRGB::White; + currentPalette[8] = CRGB::White; + currentPalette[12] = CRGB::White; +} + +// This function sets up a palette of purple and green stripes. +void SetupPurpleAndGreenPalette() +{ + CRGB purple = CHSV(HUE_PURPLE, 255, 255); + CRGB green = CHSV(HUE_GREEN, 255, 255); + CRGB black = CRGB::Black; + + currentPalette = CRGBPalette16( + green, green, black, black, + purple, purple, black, black, + green, green, black, black, + purple, purple, black, black + ); +} +///////////////////// FastLED-3.1.5/examples/ColorPalette ///////////////////// + +/////////////////// FastLED-3.1.5/examples/ColorTemperature /////////////////// +void colorTemp() +{ + // draw a generic, no-name rainbow + static uint8_t starthue = 0; + fill_rainbow(leds + 5, LED_NUM - 5, --starthue, 20); + + // Choose which 'color temperature' profile to enable. + uint8_t secs = (millis() / 1000) % (DISPLAYTIME * 2); + if (secs < DISPLAYTIME) { + FastLED.setTemperature(TEMPERATURE_1 ); // first temperature + leds[0] = TEMPERATURE_1; // show indicator pixel + } else { + FastLED.setTemperature(TEMPERATURE_2 ); // second temperature + leds[0] = TEMPERATURE_2; // show indicator pixel + } + + // Black out the LEDs for a few secnds between color changes + // to let the eyes and brains adjust + if((secs % DISPLAYTIME) < BLACKTIME) { + memset8(leds, 0, LED_NUM * sizeof(CRGB)); + } + + FastLED.show(); + FastLED.delay(8); +} +/////////////////// FastLED-3.1.5/examples/ColorTemperature /////////////////// + +//////////////////////// FastLED-3.1.5/examples/Fire202 /////////////////////// +void fire() +{ + // Array of temperature readings at each simulation cell + static byte heat[LED_NUM]; + + // Step 1. Cool down every cell a little + for (int i = 0; i < LED_NUM; i++) { + heat[i] = qsub8(heat[i], random8(0, ((COOLING * 10) / LED_NUM) + 2)); + } + + // Step 2. Heat from each cell drifts 'up' and diffuses a little + for (int k= LED_NUM - 1; k >= 2; k--) { + heat[k] = (heat[k - 1] + heat[k - 2] + heat[k - 2] ) / 3; + } + + // Step 3. Randomly ignite new 'sparks' of heat near the bottom + if (random8() < SPARKING ) { + int y = random8(7); + heat[y] = qadd8(heat[y], random8(160,255)); + } + + // Step 4. Map from heat cells to LED colors + for (int j = 0; j < LED_NUM; j++) { + CRGB color = HeatColor( heat[j]); + int pixelnumber; + if (gReverseDirection) { + pixelnumber = (LED_NUM - 1) - j; + } else { + pixelnumber = j; + } + leds[pixelnumber] = color; + } + + FastLED.delay(1000 / speed); +} +//////////////////////// FastLED-3.1.5/examples/Fire202 /////////////////////// + +void loop() { + // MQTT + testConnectMQTT(); + client.loop(); + + // LED + if (!ledState) { + FastLED.delay(1000); + } else { + if (ledEffect == LED_EFFECT_CYLON) { + ledCylon(); + } else if (ledEffect == LED_EFFECT_FULLRED) { + ledFullColor(); + } else if (ledEffect == LED_EFFECT_COLORPATTERN) { + ledColorPattern(); + } else if (ledEffect == LED_EFFECT_COLORTEMP) { + colorTemp(); + } else if (ledEffect == LED_EFFECT_FIRE) { + fire(); + } else { + ledError(); + } + } +} diff --git a/arduino/alarmclock/alarmclock.exemple.h b/arduino/alarmclock/alarmclock.exemple.h new file mode 100644 index 0000000..a256919 --- /dev/null +++ b/arduino/alarmclock/alarmclock.exemple.h @@ -0,0 +1,180 @@ +#define SERIAL_SPEED 115200 + +# TODO : tout reste à faire, ceci est la copie de mqttfastledmenu à adapter + +// LED +#define LED_NUM 300 +#define LED_PIN 5 // = D1 +#define LED_CHIPSET WS2812B +#define LED_COLOR_ORDER GRB +#define LED_BRIGHTNESS_DEFAULT 96 +#define LED_SPEED_DEFAULT 120 +#define LED_COLOR_DEFAULT CRGB::Red + +#define LED_EFFECT_CYLON "cylon" +#define LED_EFFECT_COLORPATTERN "colorp" +#define LED_EFFECT_COLORTEMP "colort" +#define LED_EFFECT_FIRE "fire" +#define LED_EFFECT_FULLRED "full" +#define LED_EFFECT_ERROR "error" + +// WIFI +#define WIFI_SSID "XXX" +#define WIFI_PASSWORD "XXX" + +// MQTT +#define MQTT_SERVER "XXX" +#define MQTT_PORT 1883 +#define MQTT_USER "XXX" +#define MQTT_PASS "XXX" + +#define MQTT_LED_COMMAND "strip1/switch" +#define MQTT_LED_STATE "strip1/status" +#define MQTT_LED_EFFECT_COMMAND "strip1/effect/switch" +#define MQTT_LED_EFFECT_STATE "strip1/effect/status" +#define MQTT_LED_BRIGHTNESS_COMMAND "strip1/brightness/switch" +#define MQTT_LED_BRIGHTNESS_STATE "strip1/brightness/status" +#define MQTT_LED_SPEED_COMMAND "strip1/speed/switch" +#define MQTT_LED_SPEED_STATE "strip1/speed/status" +#define MQTT_LED_COLOR_COMMAND "strip1/color/switch" +#define MQTT_LED_COLOR_STATE "strip1/color/status" + + +void setupWifi(); +void testConnectMQTT(); +void callbackMQTT(char* topic, byte* payload, unsigned int length); +void mqttSendState(); +void mqttSendEffectState(); +void mqttSendBrightnessState(); +void mqttSendSpeedState(); +void mqttSendColorState(); +void ledBlackAll(); +void ledCylon(); +void ledError(); +void ledFullColor(); +///////////////////////////////// ColorPalette +// This example shows several ways to set up and use 'palettes' of colors +// with FastLED. +// +// These compact palettes provide an easy way to re-colorize your +// animation on the fly, quickly, easily, and with low overhead. +// +// USING palettes is MUCH simpler in practice than in theory, so first just +// run this sketch, and watch the pretty lights as you then read through +// the code. Although this sketch has eight (or more) different color schemes, +// the entire sketch compiles down to about 6.5K on AVR. +// +// FastLED provides a few pre-configured color palettes, and makes it +// extremely easy to make up your own color schemes with palettes. +// +// Some notes on the more abstract 'theory and practice' of +// FastLED compact palettes are at the bottom of this file. +CRGBPalette16 currentPalette; +TBlendType currentBlending; + +extern CRGBPalette16 myRedWhiteBluePalette; +extern const TProgmemPalette16 myRedWhiteBluePalette_p PROGMEM; + +// This example shows how to set up a static color palette +// which is stored in PROGMEM (flash), which is almost always more +// plentiful than RAM. A static PROGMEM palette like this +// takes up 64 bytes of flash. +const TProgmemPalette16 myRedWhiteBluePalette_p PROGMEM = +{ + CRGB::Red, + CRGB::Gray, // 'white' is too bright compared to red and blue + CRGB::Blue, + CRGB::Black, + + CRGB::Red, + CRGB::Gray, + CRGB::Blue, + CRGB::Black, + + CRGB::Red, + CRGB::Red, + CRGB::Gray, + CRGB::Gray, + CRGB::Blue, + CRGB::Blue, + CRGB::Black, + CRGB::Black +}; + +void ledColorPattern(); +void FillLEDsFromPaletteColors(uint8_t colorIndex); +void ChangePalettePeriodically(); +void SetupTotallyRandomPalette(); +void SetupBlackAndWhiteStripedPalette(); +void SetupPurpleAndGreenPalette(); +//////////////////////////////////////////////// ColorTemperature +// THIS EXAMPLE demonstrates the second, "color temperature" control. +// It shows a simple rainbow animation first with one temperature profile, +// and a few seconds later, with a different temperature profile. +// +// The first pixel of the strip will show the color temperature. +// +// HELPFUL HINTS for "seeing" the effect in this demo: +// * Don't look directly at the LED pixels. Shine the LEDs aganst +// a white wall, table, or piece of paper, and look at the reflected light. +// +// * If you watch it for a bit, and then walk away, and then come back +// to it, you'll probably be able to "see" whether it's currently using +// the 'redder' or the 'bluer' temperature profile, even not counting +// the lowest 'indicator' pixel. +// +// +// FastLED provides these pre-conigured incandescent color profiles: +// Candle, Tungsten40W, Tungsten100W, Halogen, CarbonArc, +// HighNoonSun, DirectSunlight, OvercastSky, ClearBlueSky, +// FastLED provides these pre-configured gaseous-light color profiles: +// WarmFluorescent, StandardFluorescent, CoolWhiteFluorescent, +// FullSpectrumFluorescent, GrowLightFluorescent, BlackLightFluorescent, +// MercuryVapor, SodiumVapor, MetalHalide, HighPressureSodium, +// FastLED also provides an "Uncorrected temperature" profile +// UncorrectedTemperature; + +#define TEMPERATURE_1 Tungsten100W +#define TEMPERATURE_2 OvercastSky +// How many seconds to show each temperature before switching +#define DISPLAYTIME 20 +// How many seconds to show black between switches +#define BLACKTIME 3 +void colorTemp(); +///////////////////////////////////////////////Fire202 +bool gReverseDirection = false; +// This basic one-dimensional 'fire' simulation works roughly as follows: +// There's a underlying array of 'heat' cells, that model the temperature +// at each point along the line. Every cycle through the simulation, +// four steps are performed: +// 1) All cells cool down a little bit, losing heat to the air +// 2) The heat from each cell drifts 'up' and diffuses a little +// 3) Sometimes randomly new 'sparks' of heat are added at the bottom +// 4) The heat from each cell is rendered as a color into the leds array +// The heat-to-color mapping uses a black-body radiation approximation. +// +// Temperature is in arbitrary units from 0 (cold black) to 255 (white hot). +// +// This simulation scales it self a bit depending on NUM_LEDS; it should look +// "OK" on anywhere from 20 to 100 LEDs without too much tweaking. +// +// I recommend running this simulation at anywhere from 30-100 frames per second, +// meaning an interframe delay of about 10-35 milliseconds. +// +// Looks best on a high-density LED setup (60+ pixels/meter). +// +// +// There are two main parameters you can play with to control the look and +// feel of your fire: COOLING (used in step 1 above), and SPARKING (used +// in step 3 above). +// +// COOLING: How much does the air cool as it rises? +// Less cooling = taller flames. More cooling = shorter flames. +// Default 50, suggested range 20-100 +#define COOLING 55 + +// SPARKING: What chance (out of 255) is there that a new spark will be lit? +// Higher chance = more roaring fire. Lower chance = more flickery fire. +// Default 120, suggested range 50-200. +#define SPARKING 120 +void fire(); diff --git a/arduino/alarmclock/alarmclock.ino b/arduino/alarmclock/alarmclock.ino new file mode 100644 index 0000000..e69de29 diff --git a/home-assistant/conf_automation.d/alarmclock.yaml b/home-assistant/conf_automation.d/alarmclock.yaml new file mode 100644 index 0000000..7ab9653 --- /dev/null +++ b/home-assistant/conf_automation.d/alarmclock.yaml @@ -0,0 +1,11 @@ +- alias: "Alarm Clock" + hide_entity: False + trigger: + platform: "template" + value_template: "{{ states.sensor.time.state == states.sensor.alarmclock_time_long.state }}" + condition: + condition: "state" + entity_id: "input_boolean.alarmclock_status" + state: "on" + action: + service: "script.wake_up" diff --git a/home-assistant/conf_customize.d/alarmclock.yaml b/home-assistant/conf_customize.d/alarmclock.yaml new file mode 100644 index 0000000..d2f3906 --- /dev/null +++ b/home-assistant/conf_customize.d/alarmclock.yaml @@ -0,0 +1,20 @@ +sensor.time: + hidden: true +sensor.alarmclock_hour: + hidden: true +sensor.alarmclock_minute: + hidden: true +sensor.alarmclock_time_long: + hidden: true +sensor.alarmclock_time: + friendly_name: "Alarm Clock Setting" + icon: "mdi:alarm" +input_slider.alarmclock_hour: + friendly_name: "Hour" + icon: "mdi:timer" +input_slider.alarmclock_minute: + friendly_name: "Minute" + icon: "mdi:timer" +input_boolean.alarmclock_status: + friendly_name: "Alarm Clock Status" + icon: "mdi:alarm-check" diff --git a/home-assistant/conf_group.d/alarmclock.yaml b/home-assistant/conf_group.d/alarmclock.yaml new file mode 100644 index 0000000..adf742a --- /dev/null +++ b/home-assistant/conf_group.d/alarmclock.yaml @@ -0,0 +1,14 @@ +alarmclock: + name: "Alarm Clock" + entities: + - "sensor.alarmclock_time" + - "input_slider.alarmclock_hour" + - "input_slider.alarmclock_minute" + - "input_boolean.alarmclock_status" + +alarmclock2: + name: "Alarm Clock" + view: "yes" + icon: "mdi:alarm" + entities: + - "group.alarmclock" diff --git a/home-assistant/conf_input_boolean.d/alarmclock.yaml b/home-assistant/conf_input_boolean.d/alarmclock.yaml new file mode 100644 index 0000000..d6bf369 --- /dev/null +++ b/home-assistant/conf_input_boolean.d/alarmclock.yaml @@ -0,0 +1,2 @@ +alarmclock_status: + initial: "off" diff --git a/home-assistant/conf_input_slider.d/alarmclock.yaml b/home-assistant/conf_input_slider.d/alarmclock.yaml new file mode 100644 index 0000000..5c6ffed --- /dev/null +++ b/home-assistant/conf_input_slider.d/alarmclock.yaml @@ -0,0 +1,10 @@ +alarmclock_hour: + initial: 7 + min: 0 + max: 23 + step: 1 +alarmclock_minute: + initial: 0 + min: 0 + max: 55 + step: 5 diff --git a/home-assistant/conf_light.d/alarmclock.yaml b/home-assistant/conf_light.d/alarmclock.yaml new file mode 100644 index 0000000..00f2088 --- /dev/null +++ b/home-assistant/conf_light.d/alarmclock.yaml @@ -0,0 +1,7 @@ +- platform: "mqtt" + name: "alarmclock" + retain: true + command_topic: "strip1/switch" + state_topic: "strip1/status" + rgb_command_topic: "strip1/color/switch" + rgb_state_topic: "strip1/color/status" diff --git a/home-assistant/conf_script.d/alarmclock.yaml b/home-assistant/conf_script.d/alarmclock.yaml new file mode 100644 index 0000000..e685846 --- /dev/null +++ b/home-assistant/conf_script.d/alarmclock.yaml @@ -0,0 +1,9 @@ +alarmclock: + sequence: + - service: "light.turn_on" + data: + entity_id: "light.lux_lamp" + brightness: 255 + transition: 10 + - service: "homeassistant.turn_off" + entity_id: "switch.smart_switch1" diff --git a/home-assistant/conf_sensors.d/alarmclock.yaml b/home-assistant/conf_sensors.d/alarmclock.yaml new file mode 100644 index 0000000..57f46d5 --- /dev/null +++ b/home-assistant/conf_sensors.d/alarmclock.yaml @@ -0,0 +1,26 @@ +- platform: "time_date" + display_options: + - "time" +- platform: "template" + sensors: + alarmclock_hour: + value_template: "{{ states.input_slider.alarmclock_hour.state | int }}" + alarmclock_minute: + value_template: "{{ states.input_slider.alarmclock_minute.state | int }}" + alarmclock_time: + value_template: >- + {{ states.sensor.alarmclock_hour.state }}: + {%- if states.sensor.alarmclock_minute.state|length == 1 -%} + 0 + {%- endif -%} + {{ states.sensor.alarmclock_minute.state }} + alarmclock_time_long: + value_template: >- + {% if states.sensor.alarmclock_hour.state|length == 1 -%} + 0 + {%- endif -%} + {{ states.sensor.alarmclock_hour.state }}: + {%- if states.sensor.alarmclock_minute.state|length == 1 -%} + 0 + {%- endif -%} + {{ states.sensor.alarmclock_minute.state }} diff --git a/home-assistant/configuration.yaml b/home-assistant/configuration.yaml new file mode 100644 index 0000000..d124096 --- /dev/null +++ b/home-assistant/configuration.yaml @@ -0,0 +1,16 @@ +# TODO : tout reste à faire, ceci est la copie de mqttfastledmenu à adapter + +homeassistant: + customize: !include_dir_merge_named "conf_customize.d/" + +mqtt: + broker: "XXX" + port: 1883 + client_id: "homeassistant1" + username: "XXX" + password: "XXX" + +light: !include_dir_merge_list "conf_light.d/" +automation: !include_dir_merge_list "conf_automation.d/" +group: !include_dir_merge_named "conf_group.d/" +script: !include_dir_merge_named "conf_script.d/" diff --git a/logo.jpg b/logo.jpg new file mode 100644 index 0000000..28ddb17 Binary files /dev/null and b/logo.jpg differ diff --git a/logo.png b/logo.png new file mode 100644 index 0000000..afd7bb8 Binary files /dev/null and b/logo.png differ diff --git a/medias/alarmclock_bb.png b/medias/alarmclock_bb.png new file mode 100644 index 0000000..91fb0eb Binary files /dev/null and b/medias/alarmclock_bb.png differ diff --git a/medias/irl1.jpg b/medias/irl1.jpg new file mode 100644 index 0000000..97aad95 Binary files /dev/null and b/medias/irl1.jpg differ diff --git a/medias/mqttfastledmenu.fzz b/medias/mqttfastledmenu.fzz new file mode 100644 index 0000000..196f488 Binary files /dev/null and b/medias/mqttfastledmenu.fzz differ diff --git a/platformio.ini b/platformio.ini new file mode 100644 index 0000000..d0775cb --- /dev/null +++ b/platformio.ini @@ -0,0 +1,18 @@ +; PlatformIO Project Configuration File +; +; Build options: build flags, source filter +; Upload options: custom upload port, speed and extra flags +; Library options: dependencies, extra library storages +; Advanced options: extra scripting +; +; Please visit documentation for the other options and examples +; http://docs.platformio.org/page/projectconf.html + +[env:nodemcuv2] +platform=espressif8266 +board=nodemcuv2 +framework=arduino + +[platformio] +src_dir=arduino/alarmclock +lib_dir=/home/jcabillot/Arduino/libraries