From a502c7c7be3e17248bca35077e1ca764854962ee Mon Sep 17 00:00:00 2001 From: Maurice Makaay Date: Fri, 5 Mar 2021 13:54:29 +0100 Subject: [PATCH] Implemented temperature band 251 - 312 --- .yeelight_bs2.h.swp | Bin 20480 -> 20480 bytes example-device.yaml | 1 - yeelight_bs2.h | 34 +++++++++++++++++++++++++++++++--- yeelight_bs2.yaml | 2 +- 4 files changed, 32 insertions(+), 5 deletions(-) diff --git a/.yeelight_bs2.h.swp b/.yeelight_bs2.h.swp index 6a2a3169d32e39a63221aac046e60f61f96fd7c9..fb0d1679d2b24e9b8810a425d6e0e9c78dbebff6 100644 GIT binary patch delta 1403 zcmZ|OPiz!b9KiA4w9`LG3p7O%Ae4u}Keg>{+hvojE0k1-As}r+ikm!Lw7a9#oop`gvq@EDada&`-i%}CJDaMONiQkkG!B_p+2E)5n1gVdU^EMb~&s>9NYHZo!>iu=%adV%wMhV zZfP51l?M$v#{Hfx%ez}=>qH*Z^Pe5YDs8=8<<~cf#Br}xzxk2Y53K&5YJJ5ngeBUgx zhy`556ZV)+xHY{>> zE*{5&df)7OuTEDg9QFsJ*Yxe8f;MUAyt8gHkuw~%UqwRw5r1VMsqa{K+N>Nr@Mbw4 z%!k9uno@SrD-=ED*`sSUi8Be-v3*C?! z&17A*77)FnYowHEJ1S{Aj*;}T`81oAtM9>3%21|bTWZ3{*`;nZF{P3jBl!x8RK_kT zGvWLjpsPxTLujU1yN5U*hIQB~WSuOBkegB|!!sN!o9D5qqEp?e;Mi#=VKJ5tUd}VD ztp&qLcty5*e&opTTJZkY2clY;gTGt-7$oU9mzB*T-{B?}FpZNK!#4ax`u>Q!xPyyG zBZ7W>L)tFkQ@oE7Uc|H5gLbsyXHxhU%3ts^hwGTZBwoT9RP+2kIlYP*yaN{}5XGbT zgZy5>QZ>&phYL85G)(lP8BL%Los$6fslvR3|IH$2zvFpqV*4;iHRQO!8m zv^!}T&B3tH+#<=fvHc%Q^|H+n$z`+o3q@bCecYjmz2FGc)LER$LxYZxy~+J{P3;ed zNNWXaZm?8cQ)A)&GLa&NkU$K6cu=Yp`GyH7Ttqv**NEIk0Ru?m5E}5fntklRb}YC= zzTy>ZjNk2{UPg6LU_H8Qj5HoIxC`uo8<^BEK++VGJRJAUr576?u&ZxQqex z;wTbm!{d*G%4|J#d z)ceG0-@fuHV07ow>0^KAX3)$8jFX3t$rjur26PO(SbO8_`-wcFoO?xf^iI^AA8Y-UD$~z%Ae4yZB383)KuJSPsKNC es==K7XLjrUBRl0zTJ~6Kg{C~Fx55mYe)$bvP@gXV 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