diff --git a/things.ino b/things.ino index b00b8a9..c53e485 100644 --- a/things.ino +++ b/things.ino @@ -50,6 +50,25 @@ void setupHandler() { #endif } +bool ledOnHandler(String value) { + if (value == "true") { + analogWrite(PIN_LED_RED, led_red); + analogWrite(PIN_LED_GREEN, led_green); + analogWrite(PIN_LED_BLUE, led_blue); + Homie.setNodeProperty(ledNode, "on", "true"); + Serial.println("led is on"); + } else if (value == "false") { + analogWrite(PIN_LED_RED, 0); + analogWrite(PIN_LED_GREEN, 0); + analogWrite(PIN_LED_BLUE, 0); + Homie.setNodeProperty(ledNode, "on", "false"); + Serial.println("led is off"); + } else { + return false; + } + return true; +} + bool ledColorHandler(String message) { DynamicJsonBuffer json_inBuffer; JsonObject& json_in = json_inBuffer.parseObject(message); @@ -170,6 +189,7 @@ void setup() { Homie.registerNode(ldrNode); #endif #ifdef HAS_LED + ledNode.subscribe("on", ledOnHandler); ledNode.subscribe("color", ledColorHandler); Homie.registerNode(ledNode); #endif