Skip to content
This repository has been archived by the owner on Aug 24, 2022. It is now read-only.

Fixed problem with dimmer not turning off #10

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
}
};
};