From b3b7c21cb7e7753cee5456f378233928d576afcd Mon Sep 17 00:00:00 2001 From: sq5gvm Date: Fri, 28 Dec 2018 20:34:39 +0100 Subject: [PATCH 1/3] Domoticz over MQTT to Espurna RGB/RGBW/RGBWW --- code/espurna/domoticz.ino | 75 ++++++++++++++++++++++++++++++++++++--- 1 file changed, 70 insertions(+), 5 deletions(-) diff --git a/code/espurna/domoticz.ino b/code/espurna/domoticz.ino index 23386529..4bd39496 100644 --- a/code/espurna/domoticz.ino +++ b/code/espurna/domoticz.ino @@ -67,11 +67,76 @@ void _domoticzMqtt(unsigned int type, const char * topic, const char * payload) // IDX unsigned int idx = root["idx"]; - unsigned char relayID = _domoticzRelay(idx); - if (relayID >= 0) { - unsigned char value = root["nvalue"]; - DEBUG_MSG_P(PSTR("[DOMOTICZ] Received value %u for IDX %u\n"), value, idx); - relayStatus(relayID, value == 1); + String stype = root["stype"]; + + if ( + (stype.equals("RGB") || stype.equals("RGBW") || stype.equals("RGBWW")) + && lightHasColor() + ) { + + // m field contains information about color mode (enum ColorMode from domoticz ColorSwitch.h): + unsigned int cmode = root["Color"]["m"]; + unsigned int cval; + + if (cmode == 3 || cmode == 4) { // ColorModeRGB or ColorModeCustom - see + + // RED + cval = root["Color"]["r"]; + DEBUG_MSG_P(PSTR("[DOMOTICZ] Received RED value %u for IDX %u\n"), cval, idx); + lightChannel(0, cval); + + // GREEN + cval = root["Color"]["g"]; + DEBUG_MSG_P(PSTR("[DOMOTICZ] Received GREEN value %u for IDX %u\n"), cval, idx); + lightChannel(1, cval); + + // BLUE + cval = root["Color"]["b"]; + DEBUG_MSG_P(PSTR("[DOMOTICZ] Received BLUE value %u for IDX %u\n"), cval, idx); + lightChannel(2, cval); + + // WARM WHITE or MONOCHROME WHITE if supported + if (lightChannels() > 3) { + cval = root["Color"]["ww"]; + DEBUG_MSG_P(PSTR("[DOMOTICZ] Received WARM WHITE value %u for IDX %u\n"), cval, idx); + lightChannel(3, cval); + } + + // COLD WHITE if supported + if (lightChannels() > 4) { + cval = root["Color"]["cw"]; + DEBUG_MSG_P(PSTR("[DOMOTICZ] Received COLD WHITE value %u for IDX %u\n"), cval, idx); + lightChannel(4, cval); + } + + + unsigned int brightness = root["Level"]; + DEBUG_MSG_P(PSTR("[DOMOTICZ] Received BRIGHTNESS value %u for IDX %u\n"), brightness, idx); + unsigned int br = (brightness / 100.0) * LIGHT_MAX_BRIGHTNESS; + DEBUG_MSG_P(PSTR("[DOMOTICZ] Calculated BRIGHTNESS value %u for IDX %u\n"), br, idx); + lightBrightness(br); // domoticz uses 100 as maximum value while we're using LIGHT_MAX_BRIGHTNESS + + // update lights + lightUpdate(true, mqttForward()); + + } + + + + unsigned char relayID = _domoticzRelay(idx); + if (relayID >= 0) { + unsigned char value = root["nvalue"]; + DEBUG_MSG_P(PSTR("[DOMOTICZ] Received value %u for IDX %u\n"), value, idx); + relayStatus(relayID, value > 0); + } + + } else { + unsigned char relayID = _domoticzRelay(idx); + if (relayID >= 0) { + unsigned char value = root["nvalue"]; + DEBUG_MSG_P(PSTR("[DOMOTICZ] Received value %u for IDX %u\n"), value, idx); + relayStatus(relayID, value == 1); + } } } From 24d15aa31a98b884df4f32f1cf9b9062c60745e7 Mon Sep 17 00:00:00 2001 From: sq5gvm Date: Fri, 28 Dec 2018 20:36:41 +0100 Subject: [PATCH 2/3] added missing comment --- code/espurna/domoticz.ino | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/code/espurna/domoticz.ino b/code/espurna/domoticz.ino index 4bd39496..546a1b13 100644 --- a/code/espurna/domoticz.ino +++ b/code/espurna/domoticz.ino @@ -78,7 +78,7 @@ void _domoticzMqtt(unsigned int type, const char * topic, const char * payload) unsigned int cmode = root["Color"]["m"]; unsigned int cval; - if (cmode == 3 || cmode == 4) { // ColorModeRGB or ColorModeCustom - see + if (cmode == 3 || cmode == 4) { // ColorModeRGB or ColorModeCustom - see domoticz ColorSwitch.h // RED cval = root["Color"]["r"]; From 17d38bd36f13dc26cb907b8ffc2016506c352fb4 Mon Sep 17 00:00:00 2001 From: sq5gvm Date: Fri, 28 Dec 2018 20:58:23 +0100 Subject: [PATCH 3/3] added missing #if's for devices that aren't light controllers --- code/espurna/domoticz.ino | 107 ++++++++++++++++++++------------------ 1 file changed, 55 insertions(+), 52 deletions(-) diff --git a/code/espurna/domoticz.ino b/code/espurna/domoticz.ino index 546a1b13..37e90c45 100644 --- a/code/espurna/domoticz.ino +++ b/code/espurna/domoticz.ino @@ -68,68 +68,71 @@ void _domoticzMqtt(unsigned int type, const char * topic, const char * payload) // IDX unsigned int idx = root["idx"]; String stype = root["stype"]; - if ( (stype.equals("RGB") || stype.equals("RGBW") || stype.equals("RGBWW")) - && lightHasColor() ) { +#if LIGHT_PROVIDER != LIGHT_PROVIDER_NONE + if (lightHasColor()) { - // m field contains information about color mode (enum ColorMode from domoticz ColorSwitch.h): - unsigned int cmode = root["Color"]["m"]; - unsigned int cval; - - if (cmode == 3 || cmode == 4) { // ColorModeRGB or ColorModeCustom - see domoticz ColorSwitch.h - - // RED - cval = root["Color"]["r"]; - DEBUG_MSG_P(PSTR("[DOMOTICZ] Received RED value %u for IDX %u\n"), cval, idx); - lightChannel(0, cval); - - // GREEN - cval = root["Color"]["g"]; - DEBUG_MSG_P(PSTR("[DOMOTICZ] Received GREEN value %u for IDX %u\n"), cval, idx); - lightChannel(1, cval); - - // BLUE - cval = root["Color"]["b"]; - DEBUG_MSG_P(PSTR("[DOMOTICZ] Received BLUE value %u for IDX %u\n"), cval, idx); - lightChannel(2, cval); + // m field contains information about color mode (enum ColorMode from domoticz ColorSwitch.h): + unsigned int cmode = root["Color"]["m"]; + unsigned int cval; - // WARM WHITE or MONOCHROME WHITE if supported - if (lightChannels() > 3) { - cval = root["Color"]["ww"]; - DEBUG_MSG_P(PSTR("[DOMOTICZ] Received WARM WHITE value %u for IDX %u\n"), cval, idx); - lightChannel(3, cval); - } - - // COLD WHITE if supported - if (lightChannels() > 4) { - cval = root["Color"]["cw"]; - DEBUG_MSG_P(PSTR("[DOMOTICZ] Received COLD WHITE value %u for IDX %u\n"), cval, idx); - lightChannel(4, cval); + if (cmode == 3 || cmode == 4) { // ColorModeRGB or ColorModeCustom - see domoticz ColorSwitch.h + + // RED + cval = root["Color"]["r"]; + DEBUG_MSG_P(PSTR("[DOMOTICZ] Received RED value %u for IDX %u\n"), cval, idx); + lightChannel(0, cval); + + // GREEN + cval = root["Color"]["g"]; + DEBUG_MSG_P(PSTR("[DOMOTICZ] Received GREEN value %u for IDX %u\n"), cval, idx); + lightChannel(1, cval); + + // BLUE + cval = root["Color"]["b"]; + DEBUG_MSG_P(PSTR("[DOMOTICZ] Received BLUE value %u for IDX %u\n"), cval, idx); + lightChannel(2, cval); + + // WARM WHITE or MONOCHROME WHITE if supported + if (lightChannels() > 3) { + cval = root["Color"]["ww"]; + DEBUG_MSG_P(PSTR("[DOMOTICZ] Received WARM WHITE value %u for IDX %u\n"), cval, idx); + lightChannel(3, cval); + } + + // COLD WHITE if supported + if (lightChannels() > 4) { + cval = root["Color"]["cw"]; + DEBUG_MSG_P(PSTR("[DOMOTICZ] Received COLD WHITE value %u for IDX %u\n"), cval, idx); + lightChannel(4, cval); + } + + + unsigned int brightness = root["Level"]; + DEBUG_MSG_P(PSTR("[DOMOTICZ] Received BRIGHTNESS value %u for IDX %u\n"), brightness, idx); + unsigned int br = (brightness / 100.0) * LIGHT_MAX_BRIGHTNESS; + DEBUG_MSG_P(PSTR("[DOMOTICZ] Calculated BRIGHTNESS value %u for IDX %u\n"), br, idx); + lightBrightness(br); // domoticz uses 100 as maximum value while we're using LIGHT_MAX_BRIGHTNESS + + // update lights + lightUpdate(true, mqttForward()); + } - unsigned int brightness = root["Level"]; - DEBUG_MSG_P(PSTR("[DOMOTICZ] Received BRIGHTNESS value %u for IDX %u\n"), brightness, idx); - unsigned int br = (brightness / 100.0) * LIGHT_MAX_BRIGHTNESS; - DEBUG_MSG_P(PSTR("[DOMOTICZ] Calculated BRIGHTNESS value %u for IDX %u\n"), br, idx); - lightBrightness(br); // domoticz uses 100 as maximum value while we're using LIGHT_MAX_BRIGHTNESS - // update lights - lightUpdate(true, mqttForward()); - - } - - - - unsigned char relayID = _domoticzRelay(idx); - if (relayID >= 0) { - unsigned char value = root["nvalue"]; - DEBUG_MSG_P(PSTR("[DOMOTICZ] Received value %u for IDX %u\n"), value, idx); - relayStatus(relayID, value > 0); + unsigned char relayID = _domoticzRelay(idx); + if (relayID >= 0) { + unsigned char value = root["nvalue"]; + DEBUG_MSG_P(PSTR("[DOMOTICZ] Received value %u for IDX %u\n"), value, idx); + relayStatus(relayID, value > 0); + } } - +#else + DEBUG_MSG_P(PSTR("[DOMOTICZ] ESPurna compiled without LIGHT_PROVIDER")); +#endif } else { unsigned char relayID = _domoticzRelay(idx); if (relayID >= 0) {