Skip to content

Commit

Permalink
Fixed problem with dimmer not turning off
Browse files Browse the repository at this point in the history
Fixes this issue JeffResc#9 by actually turning the light off when brightness reaches zero.
Also removes some unnecessary serial writes by updating the lastBinary and lastBrightness variables.
  • Loading branch information
larsenglund authored Oct 6, 2021
1 parent 0f5fb85 commit a2a2a7f
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion d1_dimmer_no_rf/d1_dimmer_no_rf.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ class Sonoff_D1_Dimmer : public Component, public LightOutput
// 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
uint8_t buffer[17] = {0xAA, 0x55, 0x01, 0x04, 0x00, 0x0A, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00};

lastBinary = binary;
lastBrightness = brightness;

buffer[6] = binary;
buffer[7] = brightness;

Expand All @@ -87,8 +90,13 @@ class Sonoff_D1_Dimmer : public Component, public LightOutput

// Convert ESPHome's brightness (0-1) to the device's internal brightness (0-100)
const int calculatedBrightness = round(brightness * 100);

if (calculatedBrightness == 0)
{
binary = 0;
}

ESP_LOGD("custom", "Interpreting brightness %f as %d", brightness, calculatedBrightness);
control_dimmer(binary, calculatedBrightness);
}
};
};

1 comment on commit a2a2a7f

@yanpol199
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank for fix it)

Please sign in to comment.