diff --git a/README.md b/README.md index 93488f5..22558c2 100644 --- a/README.md +++ b/README.md @@ -9,6 +9,16 @@ Un exemple de configuration pour home-assistant se trouve dans [configuration.ya Inspiré de ce site : http://ronmar.co/ha/2017/03/10/Ultimate-Alarm-Clock/ + https://community.home-assistant.io/t/creating-a-alarm-clock/410 +Avancement +========== + +WIP. +Le partie arduino fonctionne. +La partie home-assistant fonctionne, le reveil configuré est bien envoyé à l'arduino. +TODO: gitlab-ci : on peut checker la syntax en lancant un docker home-assistant !!! +TODO: voir si c'est possible de changere la couleur de l'icone de la scene, avoir une icone bleue pour une couleur orange ... +TODO: tester en prod ^^ + Matériel ======== * 1x ESP8266 Lolin (Nodemcu v3) @@ -32,12 +42,7 @@ Médias ![Fritzing BreadBoard](medias/alarmclock_bb.png) ![IRL](medias/irl1.jpg) -Avancement -========== -WIP. -Le partie arduino fonctionne, mais pour le moment il n'y a pas d'arret automatique de l'alarme. -La partie home-assistant fonctionne, le reveil configuré est bien envoyé à l'arduino. -TODO: gitlab-ci : on peut checker la syntax en lancant un docker home-assistant !!! -TODO: HA Il faut des scenes pour retrouver les couleurs classiques -TODO: Ard pas d'arret une fois le reveil lancé -TODO: voir si c'est possible de changere la couleur de l'icone de la scene, avoir une icone bleue pour une couleur orange ... +Astuce firewalld +================ + +Pensez à la zone trusted ... diff --git a/arduino/alarmclock/alarmclock.cpp b/arduino/alarmclock/alarmclock.cpp index f5e0d6c..b1473f6 100644 --- a/arduino/alarmclock/alarmclock.cpp +++ b/arduino/alarmclock/alarmclock.cpp @@ -157,9 +157,10 @@ void callbackMQTT(char* topic, byte* payload, unsigned int length) if (stopic == MQTT_LED_COMMAND) { if (msgString == "ON") { ledState = true; + curbrightness = LED_BRIGHTNESS_DEFAULT; + startTime = millis(); } else { ledState = false; - curbrightness = LED_BRIGHTNESS_DEFAULT; ledBlackAll(); } mqttSendState(); @@ -281,15 +282,22 @@ void loop() { client.loop(); // LED - EVERY_N_SECONDS(10) { - if (curbrightness <= maxBrightness) { - curbrightness++; - } - } - if (!ledState) { FastLED.delay(1000); } else { - ledDisplay(); + if (startTime + LED_DURATION <= millis()) { + Debug.println("END"); + ledState = false; + ledBlackAll(); + mqttSendState(); + } else { + EVERY_N_SECONDS(10) { + if (curbrightness <= maxBrightness) { + curbrightness++; + } + } + + ledDisplay(); + } } } diff --git a/arduino/alarmclock/alarmclock.exemple.h b/arduino/alarmclock/alarmclock.exemple.h index 6f58ad7..94fa3b9 100644 --- a/arduino/alarmclock/alarmclock.exemple.h +++ b/arduino/alarmclock/alarmclock.exemple.h @@ -17,6 +17,8 @@ RemoteDebug Debug; #define LED_MAXBRIGHTNESS_DEFAULT 80 #define LED_BRIGHTNESS_DEFAULT 6 #define LED_COLOR_DEFAULT CRGB::Red +// 1000 * 60 * 60 = 1h +#define LED_DURATION 3600000 // Corresponds à un max brightness configurable via HA int maxBrightness; @@ -25,6 +27,7 @@ int curbrightness; int color; CRGB leds[LED_NUM]; boolean ledState; +unsigned long startTime; // WIFI #define WIFI_SSID "XXX"