RavenSystem / esp-homekit-devices

Advanced firmware to add native Apple HomeKit and custom configurations, compatible with any SoC based on ESP32, ESP32-S, ESP32-C and ESP8266 series. (Shelly, Sonoff, Electrodragon, Tuya...)
Other
2.76k stars 361 forks source link

Support for RGB+CCT (RGBWW, RGB+WW+CW) LED controllers #1124

Closed kevinjohncutler closed 4 years ago

kevinjohncutler commented 4 years ago

Not quite a duplicate of #631, #638, #800, as the first one never got resolved (I bet they were successful only for the use of a RGB controller replicating color temperature) and the other two are just for bulbs, which I am guessing are a lot harder to test and debug than this controller. I bought a couple of them and have flashed HAA onto them successfully. I see that in the Wiki there is syntax available for addressing each of the 5 channels, and this post seems to indicate that it is possible to get it working at present. I'm still learning the json syntax and looking at examples in haa-configurator, but please let me know if I will be toiling in vain haha.

@RavenSystem I saw in #638 that all you need is a better algorithm to mix colors, and this should be easy for me to debug with this controller (I can simply disconnect the leads to isolate whichever LEDs we need to test). Let me know how I can help.

Update: by studying the board, I figured out that my particular LEDENET controller has CW connected to GPIO5 (traced along the back side) and the rest followed the layout of the pins: red 14, green 12, blue 13, WW 15. I'm following the following schematic for ESP82885: image I edited the Magic Home RGBW controller template accordingly via haa-configurator: { "c": { "b": [ { "g": 0, "t": 5 } ] }, "a": [ { "t": 30, "r": 14, "g": 12, "v": 13, "ww": 15, "cw": 5, "b": [ { "g": 0 } ], "s": 5, "p": 1024, "d": 1, "e": 10, "fr": 1, "fg": 1, "fv": 1 } ] }

The result is essentially the same as with the default RGBW template - despite addressing the CW channel, it never turns on, so I'm guessing that it is still unsupported by the firmware. I have two of these controllers flashed with HAA and another couple on their way that I may just keep connected via Homebridge for a while - the Dynamic Magic Home plugin just got an update that might give it correct RGBWW functionality, and so it might allow us to debug further.

kevinjohncutler commented 4 years ago

I'm not sure if the json I posted above actually stuck - I thought so because it was giving me different behavior than a different controller, but minor modifications to it no longer would apply (invalid json keeps it in setup mode). However, the following works:

{"c":{"n":"LEDENET 5in1 Controller"},"a":[{"t":30,"r":14,"g":12,"v":13,"cw":5,"ww":15}]}

This was a modification of the post mentioned in the OP (the json for the "Deta Grid Connect Smart 10W LED Downlight - RGB-WW-CW"). Note that all I had to do was remap the channels to match my device. At first I included the following secondary accessory,

,{
        "i":0.5,
        "1":{"s":[{"a":1}]}
    }

but I removed it hoping that it was the cause of the latency I am observing. It was not - there is still a lot of lag when selecting a color. Trying to get it to land on a specific color (say, red) causes it to stutter and get stuck on the wrong nearby color (magenta in this case). But the aforementioned "i" and "1" lines above don't affect the behavior. I would very much like some help understanding what this is doing - the documentation doesn't quite get me there.

It would also be informative to try to understand what was wrong with my original json. I used a json verification and formatting tool to put it into compact form and make sure no bad characters made it in etc.

Could this stuttering that I see in the color wheel selection be fixed by changing any of the other parameters (like color transition step), or do you think there is another reason?

Edit: The responsiveness is just fine when setting scenes in homekit, so unless there is a super obvious reason why I am seeing the stuttering behavior, I can hold off on fixing that. @RavenSystem I'd like to help fine-tune the color mixing algorithm. I have a bunch of native homekit bulbs that match the color+temperature selection in the Home app quite well - while there will always be variation in color output between different manufacturers, I think it would be a really good start to try to match my LED strips to those LED bulbs (color temperature is the main issue). I'm guessing that the RGBW factors are intended to make it possible to tune the color output, but I have no idea how they are actually used. Can you point me to the code that is responsible for the color mixing?

jasongoldsmith commented 4 years ago

@kevinjohncutler Are you in the Discord Server? There's a channel dedicated to this topic there - I can fill you in on my research so far and share some papers on the topic.

The short answer is that the current algorithm is pretty naive with it's assumptions about the LEDs and uses a fairly simplistic mixing algorithm that doesn't take into account perceptive color and a few other things. I'm also looking at the code.

The relevant lightbulb code is in devices/HAA/main.c starting at line 1384.

kevinjohncutler commented 4 years ago

@jasongoldsmith I'm not, but I'll head over there! Thanks so much for the info.

wayn3 commented 4 years ago

https://discord.gg/v8hyxj2

stale[bot] commented 4 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

KoCMoHaBTa commented 5 days ago

Hi @RavenSystem , I'm currently playing with this MINI-WF-5CH-A _v1.0 MagicHome controller. It is RGB-CCT 5 channel controller.

The JSON i'm using is

{"c":{"io":[[[0],6],[[4,5,12,13,14],7]],"b":[[0,5]]},"a":[{"t":30, "s": 1, "g":[5,4,14,13,12],"b":[[0]]}]}

So far so good, i have everything I need, but I noticed that

I'm seeing this behavior in led strip controllers for first time - all other controllers i've been using are switching between either RGB channels or CCT channels. I would agree that having all 5 channels up is a nice way to achieve more luminance, however this crew up the colors totally.

My question is - is there some sort of configuration i'm missing (cause it's 2:25 AM atm and i need a sleep) or this is intentional or a bug? If there is no configuration yet:

Update: I've figured out a way to workaround this by splitting the RGB and CCT channels into separate accessories

{"c":{"io":[[[0],6],[[4,5,12,13,14],7]],"b":[[0,5]]},"a":[{"t":30, "s": 1, "g":[5,4,14],"b":[[0]]}, {"t": 30, "g": [13,12],"b":[[0]]}]}

Still the button is now problematic, but will figure that out later