Skip to content

Commit

Permalink
fix edge case where turn on fails
Browse files Browse the repository at this point in the history
If the m_rgb_red, m_rgb_green and m_rgb_blue are all three equal to 0 which can happen if listining to an UDP stream.
you can get in a state in which the turn_on command allone will not turn the LEDs back on since the color value is all 0, therefore it turns on to all colors 0 wich is off, therefore the state will be reproted off and you are unable to turn the LEDs on from HomeAssistant.
The way to get out of this state would be to issue a color command together with an on command, that works, but that can not be done through the HomeAssistant default frontend, you then need to use the light.turn_on service.

This PR fixes this edge case and will make sure the LEDs turn on.
  • Loading branch information
starkillerOG authored Apr 27, 2020
1 parent 0bf3636 commit 562b863
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions h801-mqtt-json.ino
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,7 @@ void publishRGBJsonState() {

if (UDP_stream) {
m_effect = "HDMI";
root["state"] = LIGHT_ON;
} else {
m_effect = "color_mode";
}
Expand Down Expand Up @@ -319,6 +320,7 @@ void publishCombinedJsonState() {

if (UDP_stream) {
m_effect = "HDMI";
root["state"] = LIGHT_ON;
} else if (m_white_state && !m_rgb_state) {
m_effect = "white_mode";
} else if (!m_white_state && m_rgb_state) {
Expand Down Expand Up @@ -452,6 +454,15 @@ bool processRGBJson(char* message) {
if (root.containsKey("state")) {
if (strcmp(root["state"], LIGHT_ON) == 0) {
m_rgb_state = true;
//check brightness and color not to be 0
if (m_rgb_brightness == 0) {
m_rgb_brightness = 255;
}
if (m_rgb_red == 0 && m_rgb_green == 0 && m_rgb_blue ==0) {
m_rgb_red = 255;
m_rgb_green = 255;
m_rgb_blue = 255;
}
}
else if (strcmp(root["state"], LIGHT_OFF) == 0) {
m_rgb_state = false;
Expand Down Expand Up @@ -537,6 +548,10 @@ bool processWhiteJson(char* message) {
if (root.containsKey("state")) {
if (strcmp(root["state"], LIGHT_ON) == 0) {
m_white_state = true;
//check brightness not to be 0
if (m_white_brightness == 0) {
m_white_brightness = 255;
}
}
else if (strcmp(root["state"], LIGHT_OFF) == 0) {
m_white_state = false;
Expand Down Expand Up @@ -599,6 +614,21 @@ bool processCombinedJson(char* message) {
m_white_state = false;
m_rgb_state = true;
}
//check brightness and color not to be 0
if (m_rgb_brightness == 0) {
m_rgb_brightness = 255;
}
if (m_white_brightness == 0) {
m_white_brightness = 255;
}
if (m_combined_brightness == 0) {
m_combined_brightness = 255;
}
if (m_rgb_red == 0 && m_rgb_green == 0 && m_rgb_blue ==0) {
m_rgb_red = 255;
m_rgb_green = 255;
m_rgb_blue = 255;
}
}
else if (strcmp(root["state"], LIGHT_OFF) == 0) {
if (m_white_state) {
Expand Down

0 comments on commit 562b863

Please sign in to comment.