diff --git a/.yeelight_bs2.h.swp b/.yeelight_bs2.h.swp index 6a2a316..fb0d167 100644 Binary files a/.yeelight_bs2.h.swp and b/.yeelight_bs2.h.swp differ diff --git a/example-device.yaml b/example-device.yaml index 2ebda53..864f255 100644 --- a/example-device.yaml +++ b/example-device.yaml @@ -3,7 +3,6 @@ substitutions: name: bedside_lamp_office friendly_name: Bedside Lamp Office - transition_length: 1s # Configuration options to connect the device to the network. # The api is used for allowing connections from Home Assistant. diff --git a/yeelight_bs2.h b/yeelight_bs2.h index ebdd02a..daf08dd 100644 --- a/yeelight_bs2.h +++ b/yeelight_bs2.h @@ -123,11 +123,17 @@ class YeelightBedsideLampV2LightOutput : public Component, public LightOutput { ESP_LOGD("temperature_mode", "Activate TEMPERATURE %f, BRIGHTNESS %f", temperature, brightness); - float volt_scaler = 3.23f; + // Empirically determined during programming the temperature GPIO output + // code from below, by checking how far my outputs were off from the + // original lamp firmeware's outputs. This scaler is used for correcting + // my output towards the original output. + float volt_scaler; // Temperature band 370 - 588 if (temperature <= HOME_ASSISTANT_MIRED_MAX && temperature >= 371) { + volt_scaler = 3.23f; + float start = 371; float end = 588; float band = end - start; @@ -160,6 +166,8 @@ class YeelightBedsideLampV2LightOutput : public Component, public LightOutput // Temperature band 334 - 370 else if (temperature >= 334) { + volt_scaler = 3.23f; + float red_volt = (1.0f - brightness) * 2.86f; float red = red_volt / volt_scaler; @@ -192,6 +200,8 @@ class YeelightBedsideLampV2LightOutput : public Component, public LightOutput // for this bug-by-bug-compatible. else if (temperature >= 313) { + volt_scaler = 3.23f; + float red_volt = 2.89f - brightness * (2.89f - 0.32f); float red = red_volt / volt_scaler; @@ -201,9 +211,9 @@ class YeelightBedsideLampV2LightOutput : public Component, public LightOutput float blue = 1.0f; float white_volt = 0.42f + brightness * (2.43f - 0.42f); - float white = white_volt / volt_scaler; + float volt_scaler_white = 3.45f; + float white = white_volt / volt_scaler_white; - ESP_LOGD("temperature_mode", "LED voltages : RGBW %f, %f, %f, %f", red_volt, green_volt, 3.3f, white_volt); ESP_LOGD("temperature_mode", "LED state : RGBW %f, %f, %f, %f", red, green, blue, white); red_->set_level(red); @@ -217,6 +227,24 @@ class YeelightBedsideLampV2LightOutput : public Component, public LightOutput // Temperature band 251 - 312 else if (temperature >= 251) { + volt_scaler = 3.48f; + + float red = 1.0f; + float green = 1.0f; + float blue = 1.0f; + + float white_volt = 0.5f + brightness * (3.28f - 0.5f); + float white = white_volt / volt_scaler; + + ESP_LOGD("temperature_mode", "LED state : RGBW %f, %f, %f, %f", red, green, blue, white); + + red_->set_level(red); + green_->set_level(green); + blue_->set_level(blue); + white_->set_level(white); + master2_->turn_on(); + master1_->turn_on(); + return; } // Temperature band 223 - 250 else if (temperature >= 223) diff --git a/yeelight_bs2.yaml b/yeelight_bs2.yaml index 56f39c9..3a4182a 100644 --- a/yeelight_bs2.yaml +++ b/yeelight_bs2.yaml @@ -48,4 +48,4 @@ light: return {bs2light}; lights: - name: ${friendly_name} RGBW Light - default_transition_length: ${transition_length} + default_transition_length: 0s