openshwprojects / OpenBK7231T_App

Open source firmware (Tasmota/Esphome replacement) for BK7231T, BK7231N, BL2028N, T34, XR809, W800/W801, W600/W601, BL602 and LN882H
https://openbekeniot.github.io/webapp/devicesList.html
1.48k stars 276 forks source link

Default color when enabling "Smooth transitions for LED" (flag 18) #532

Closed Bacto closed 1 year ago

Bacto commented 1 year ago

Hi,

First I want to thank you for the awesome work on this project. It's a game changer to me and my home automation 🤩

The "Smooth transitions for LED" flag is awesome:

There is only one problem: the default color on start is cold (RGBCW is set to #000000FF00). And I haven't found a way to change it.

I use this startup command: backlog ; BP5758D_Map 1 0 2 3 4 ; led_dimmer 100 ; led_basecolor_rgbcw #000000FFFF ; led_enableAll 1. On start the bulb fade-in to cold white and then the script is executed and bulb fades to cold+warm white.

Is it possible to have a way to define the default color?

Adrien

openshwprojects commented 1 year ago

Hello, I will try to help. When looking at code I can see that default start color seems to be all off: _float ledrawLerpCurrent[5] = { 0 }; which doesn't seem to explain the behaviour you observed.

My first question now would be.... does the same happen for PWM lights?

rianadon commented 1 year ago

I have PWM lights so have been playing around with the code. Below are some observations I've found with the flag:

Without flag 18 (expected behavior):

  1. I configure 5 PWMs for RGB and CW
    • The LEDs are turned off at startup
  2. I configure only 2 PWMs on channels 0 and 1. I enable flag 8 (I'm doing this because this executes different code inside the color interpolation).
    • The LED is turned off at startup.
    • Clicking "Toggle Light" toggles the light on and off

With flag 18:

  1. I configure 5 PWMs for RGB and CW
    • The LEDs remain off after enabling flag 18, and I can toggle them on and off with "Toggle Light"
    • After a restart, some LEDs turn on immediately
    • The board boots into safe mode after the restart (possibly due to overcurrent?)
  2. I configure only 2 PWMs on channels 0 and 1. I enable flag 8.
    • The LED turns on immediately after enabling flag 18
    • After a restart, the LED turns on immediately
    • Clicking "Toggle Light" does not toggle the light on and off. However, moving the brightness slider still adjusts brightness.
rianadon commented 1 year ago

Looking through the code I think I know why this is:

RGB mode interpolates to finalColors[i] This array is initialized to all 255s, so when the light first boots, all LEDs will be turned on. When the LED is toggled on and off with "Toggle Light", apply_smart_light will write finalColors[i] to 0 if the LED is disabled, or the correct color if it is enabled.

However, the 2-PWM alternate CW mode interpolates the brightness to led_current_value_brightness. This variable does not depend on whether the LED is toggled on or off, so this is why "Toggle Light" does not work with this mode.

I'll write up a PR quickly.

openshwprojects commented 1 year ago

Thanks. Can anyone else check this PR with both CW and RGBCW lights before I merge?

Bacto commented 1 year ago

Hi,

Tested on a RGBCW (BK7231T with BP5758D) and a CW (BK7231T with PWM). It works, there is no default color set anymore. Thank you :)

The negative point is that there is a small delay between powering-up the light and having it fade-in. When finalColors[i] was fill with 255s, the fade-in started immediately.

Is there a way to speed-up the startup command or define the default color (via finalColors[i]) on start?

My startup command is this one: backlog ; BP5758D_Map 1 0 2 3 4 ; led_dimmer 100 ; led_basecolor_rgbcw #000000FFFF ; led_enableAll 1.

I tried to improve it by setting color first but the delay seems to be the same: backlog ; led_basecolor_rgbcw #000000FFFF ; led_enableAll 1 ; BP5758D_Map 1 0 2 3 4

openshwprojects commented 1 year ago

Thank you for your input, @Bacto . I am not sure at this moment if that's the good solution, but maybe I could just add a command that allows you to set finalColors field directly? It sounds hacky, but adding command is easy and I could get it ready for you in 5 minutes and you'd check if it works...

NOTE: the order of command won't change anything here

IDEA 2: I could add a command something like "led_applyColorNow" that would skip whole interpolation at the time of execution (it would set instantly lerp values to targets...)

GravityRZ commented 1 year ago

what do you need testing.

i have the same light and never experienced those problems but if have save color settings enabled. so it is on warm white and when i reboot it stays on warm white

rianadon commented 1 year ago

It looks like the delay from the startup commands is because the commands run once WiFi has been successfully started. Whereas the option that saves the color settings will apply these before wifi is set up.

I wonder if as an alternative to making a command that sets finalColors, there could be two startup command options: one that runs before the wifi is set up (for setting LED values) and one that runs afterwards (for mqtt publishing or other wifi-dependent commands).

Bacto commented 1 year ago

@rianadon interesting. Is waiting for WiFi to start mandatory to accept MQTT and other commands?

Waiting for a better solution, having a second startup commands field seems great to me. What do you think @openshwprojects?

btsimonh commented 1 year ago

two startup lines may be a good thing. note that early.bat is now called early, and autoexec.bat is called after delay (which is still before wifi...).

github-actions[bot] commented 1 year ago

:tada: This issue has been resolved in version 1.15.178 :tada:

The release is available on GitHub release

Your semantic-release bot :package::rocket:

openshwprojects commented 1 year ago

Sorry, github automatically closed it with PR merge. The question is - did that PR help?

Two startup commands are not needed, you already have:

also added command: "led_finishFullLerp". If you have lerp enabled, and you do backlog led_basecolor_rgb FF0000; led_finishFullLerp; , it fill apply color fully at the execution of led_finishFullLerp

Bacto commented 1 year ago

Hi,

Sorry my late reply, didn't got time to check this.

I confirm that using the early.bat file it works like a charm :)

For those who would have the same problem:

Thank you to all of you for the patch and the explanations! 🥰

Adrien

openshwprojects commented 1 year ago

Thank you!