diff --git a/code/espurna/config/general.h b/code/espurna/config/general.h index d7b4aa48..bc314071 100644 --- a/code/espurna/config/general.h +++ b/code/espurna/config/general.h @@ -235,6 +235,7 @@ PROGMEM const char* const custom_reset_string[] = { #define MQTT_TOPIC_RELAY "relay" #define MQTT_TOPIC_LED "led" #define MQTT_TOPIC_COLOR "color" +#define MQTT_TOPIC_WHITE "white" #define MQTT_TOPIC_BRIGHTNESS "brightness" #define MQTT_TOPIC_COLORTEMP "color/temperature" #define MQTT_TOPIC_BUTTON "button" diff --git a/code/espurna/light.ino b/code/espurna/light.ino index e2dfd0bf..42d6faf0 100644 --- a/code/espurna/light.ino +++ b/code/espurna/light.ino @@ -247,12 +247,29 @@ void lightColor(bool save, bool forward) { // Report color & brightness to MQTT broker if (forward) { + + // Color char rgb[8]; _color_array2rgb(_lightColor, 1.0, rgb); mqttSend(MQTT_TOPIC_COLOR, rgb); - char buffer[5]; - sprintf(buffer, "%d", (int) (brightness * LIGHT_MAX_BRIGHTNESS)); - mqttSend(MQTT_TOPIC_BRIGHTNESS, buffer); + + if ((_lightColor[0] == _lightColor[1]) & (_lightColor[1] == _lightColor[2])) { + + // White + char buffer[5]; + sprintf(buffer, "%d", (int) _lightColor[0]); + mqttSend(MQTT_TOPIC_WHITE, buffer); + + + } else { + + // Brightness + char buffer[5]; + sprintf(buffer, "%d", (int) (brightness * LIGHT_MAX_BRIGHTNESS)); + mqttSend(MQTT_TOPIC_BRIGHTNESS, buffer); + + } + } // Report color to WS clients @@ -303,6 +320,7 @@ void lightMQTTCallback(unsigned int type, const char * topic, const char * paylo mqttSubscribe(MQTT_TOPIC_BRIGHTNESS); mqttSubscribe(MQTT_TOPIC_COLORTEMP); mqttSubscribe(MQTT_TOPIC_COLOR); + mqttSubscribe(MQTT_TOPIC_WHITE); } if (type == MQTT_MESSAGE_EVENT) { @@ -324,6 +342,12 @@ void lightMQTTCallback(unsigned int type, const char * topic, const char * paylo lightColor(true, mqttForward()); } + // White + if (t.equals(MQTT_TOPIC_WHITE)) { + parseColor(payload); + lightColor(true, mqttForward()); + } + // Brightness if (t.equals(MQTT_TOPIC_BRIGHTNESS)) { brightness = (float) atoi(payload) / LIGHT_MAX_BRIGHTNESS;