home-assistant / core

:house_with_garden: Open source home automation that puts local control and privacy first.
https://www.home-assistant.io
Apache License 2.0
72.59k stars 30.36k forks source link

Color of light changes after turn off / on with flux_led #63421

Closed iskiselev closed 2 years ago

iskiselev commented 2 years ago

The problem

If I change color for flux_led controlled light and switch it off and on (either though lovelace or by calling service), it changes the color in unexpected way. If that new color is not touched, on next turn off/on cycle the color will be preserved.

Example1, original:

color_mode: rgbw
brightness: 32
hs_color:
  - 0
  - 0
rgb_color:
  - 64
  - 64
  - 64
rgbw_color:
  - 0
  - 0
  - 0
  - 64
xy_color:
  - 0.323
  - 0.329

Example1, after turn off/on:

color_mode: rgbw
brightness: 204
hs_color:
  - 253.585
  - 62.353
rgb_color:
  - 132
  - 96
  - 255
rgbw_color:
  - 59
  - 0
  - 255
  - 153
xy_color:
  - 0.219
  - 0.126

Example 2, original:

brightness: 128
hs_color:
  - 0.235
  - 100
rgb_color:
  - 255
  - 1
  - 0
rgbw_color:
  - 255
  - 1
  - 0
  - 0
xy_color:
  - 0.7
  - 0.299

Example 2, after turn off/on:

color_mode: rgbw
brightness: 192
hs_color:
  - 254.118
  - 66.667
rgb_color:
  - 125
  - 85
  - 255
rgbw_color:
  - 59
  - 0
  - 255
  - 128
xy_color:
  - 0.212
  - 0.113

What version of Home Assistant Core has the issue?

2021.12.7

What was the last working version of Home Assistant Core?

No response

What type of installation are you running?

Home Assistant OS

Integration causing the issue

flux_led

Link to integration documentation on our website

No response

Example YAML snippet

No response

Anything in the logs that might be useful for us?

No response

Additional information

I'm not sure if it is flux_led only issue - or more generic one (I have only flux_led controlled rgbw led).

bdraco commented 2 years ago

References

https://community.home-assistant.io/t/configure-flux-led-to-rgbw-with-addressable-v3-controller/374966

bdraco commented 2 years ago

Likely only affects sk rgbw strips

bdraco commented 2 years ago

I'm trying to replicate this but without success

Before

supported_color_modes:
  - rgbw
color_mode: rgbw
brightness: 240
hs_color:
  - 107.206
  - 53.333
rgb_color:
  - 148
  - 255
  - 119
rgbw_color:
  - 54
  - 255
  - 0
  - 224
xy_color:
  - 0.273
  - 0.545
ip_address: 192.168.106.28
friendly_name: Addressable v3 5v 912DDD
supported_features: 36

Off

supported_color_modes:
  - rgbw
ip_address: 192.168.106.28
friendly_name: Addressable v3 5v 912DDD
supported_features: 36

After:

supported_color_modes:
  - rgbw
color_mode: rgbw
brightness: 240
hs_color:
  - 107.206
  - 53.333
rgb_color:
  - 148
  - 255
  - 119
rgbw_color:
  - 54
  - 255
  - 0
  - 224
xy_color:
  - 0.273
  - 0.545

Does it only happen on a specific RGB value? Can you include a video?

bdraco commented 2 years ago

I think it might be a brightness calculation issue

service: light.turn_on
data:
  rgbw_color:
    - 64
    - 64
    - 64
    - 64
target:
  entity_id: light.addressable_v3_5v_912ddd

The above seems to trigger the issue.

Will need to hook up a 0x6 and try it to compare

iskiselev commented 2 years ago

It changes to 59,0,255,W (where W can be different) every time. I recorder a video with it: https://www.youtube.com/watch?v=padK54Zp-UE

bdraco commented 2 years ago

I hooked up a 0x06 RGBW Controller and it does not have the issue.

The A3 uses bifurcated commands for RGB and W so we may it looks like we have some more reverse engineering to do to get it right.

bdraco commented 2 years ago

It looks like A3 uses a scale of 1-100 shifted 128 bytes for the white byte

probot-home-assistant[bot] commented 2 years ago

flux_led documentation flux_led source (message by IssueLinks)

probot-home-assistant[bot] commented 2 years ago

Hey there @icemanch, mind taking a look at this issue as it has been labeled with an integration (flux_led) you are listed as a code owner for? Thanks! (message by CodeOwnersMention)

iskiselev commented 2 years ago

@bdraco, I don't understand a lot - but it set correct RGBW color when I change it from picker / set white brightness. It also select correct color if I pass RGBW argument to light.turn_on:

service: light.turn_on
data:
  rgbw_color:
    - 0
    - 255
    - 0
    - 128
target:
  entity_id: light.cabinet_led

It only set that strange color after sequence of turn off, turn on without argument:

service: light.turn_off
target:
  entity_id: light.cabinet_led
service: light.turn_on
target:
  entity_id: light.cabinet_led

With it, I'm not sure if it is incorrect processing of controller protocol - or some other HomeAssistant related problem

bdraco commented 2 years ago

I've got the white level reporting fixed here https://github.com/Danielhiversen/flux_led/pull/309

As for the color not restoring on turn on, I can replicate the issue in the Magic Home app. If I set the strip to blue aka 0,0,255 and turn it off it reports the RGB as 64,64,64

I don't think we can fix that since the controller is actually reporting the wrong value.

bdraco commented 2 years ago

Its actually pretty easy to replicate in the Magic Home app

Set the strip to blue on the fixed tab with 100% brightness Turn it off Turn if back on (strip will be 25% white) Force close the app, and reopen it so it re-reads the state from the controller It will be white with 25% brightness

This seems like a bug in the firmware.

bdraco commented 2 years ago

I uploaded a new version that fixes the white level reporting

mkdir /config/custom_components
cd /config/custom_components
rm -rf flux_led
git clone https://github.com/bdraco/flux_led_custom flux_led

Then restart

bdraco commented 2 years ago

Testing

bdraco@MacBook-Pro-4 flux_led % flux_led -c red 192.168.106.28      
Setting color RGB:IntegerRGB(red=255, green=0, blue=0)
[red]
bdraco@MacBook-Pro-4 flux_led % flux_led -i 192.168.106.28    
249494912DDD [192.168.106.28] ON  [Color: (255, 0, 0) White: 0 raw state: 129,163,35,97,1,50,255,0,0,0,1,0,144,235,] (Addressable v3 5v (0xA3))
bdraco@MacBook-Pro-4 flux_led % flux_led -i 192.168.106.28 --off
Turning off bulb at 192.168.106.28
Unknown ID [192.168.106.28] OFF  [Color: (64, 64, 64) White: 0 raw state: 129,163,36,97,1,50,64,64,64,0,1,0,144,173,] (Addressable v3 (0xA3))
bdraco@MacBook-Pro-4 flux_led % flux_led -i 192.168.106.28 --on 
Turning on bulb at 192.168.106.28
249494912DDD [192.168.106.28] ON  [Color: (64, 64, 64) White: 0 raw state: 129,163,35,97,1,50,64,64,64,0,1,0,144,172,] (Addressable v3 5v (0xA3))
bdraco@MacBook-Pro-4 flux_led % 

Looks like it doesn't remember red

iskiselev commented 2 years ago

@bdraco - looks like we look into something different issues. On version that you've created yesterday, each time when I set color as rgbw_color argument, it match what I see in attributes and it looks the same on the strip (as I can distinguish them) - so even white level looks good for me - it is turned off at 0, maximum at 255 with 255 visible brighter than 240.

When I turn it on/off though MagicHome or remote control, it always pick the same mode as it was before. So, I was not able to reproduce the problem with turning it of from 100% brightness. At the same time, Magic Home never picks up value for WarmWhite tab - it always show me 0 after Magic Home restart - but it correctly update value when I change it. (I have Android version of it).

But each time when I do turn off/on cycle in Home Assistant without defining RGBW color argument, it reset color into [59,0,255,W], where W is some strange value.

bdraco commented 2 years ago
bdraco@MacBook-Pro-4 flux_led % flux_led -i -w 50 192.168.106.28
Setting warm white mode, level: 50%
249494912DDD [192.168.106.28] ON  [Color: (64, 64, 64) White: 127 raw state: 129,163,35,97,1,50,64,64,64,127,1,127,144,172,] (Addressable v3 5v (0xA3))
bdraco@MacBook-Pro-4 flux_led % flux_led -i 192.168.106.28 --off 
Turning off bulb at 192.168.106.28
249494912DDD [192.168.106.28] OFF  [Color: (64, 64, 64) White: 125 raw state: 129,163,36,97,1,50,64,64,64,125,1,0,144,222,] (Addressable v3 5v (0xA3))
bdraco@MacBook-Pro-4 flux_led % flux_led -i 192.168.106.28 --on 
Turning on bulb at 192.168.106.28
249494912DDD [192.168.106.28] ON  [Color: (64, 64, 64) White: 125 raw state: 129,163,35,97,1,50,64,64,64,125,1,0,144,221,] (Addressable v3 5v (0xA3))

Testing with the latest version, it does appear to remember white (note that 127 and 125 are effectively the same value since conversion between 255 and 100 loses some resolution)

bdraco commented 2 years ago

It seems no matter color I set, it always turns back on at 64,64,64.

I'm going to try a factory reset.

bdraco commented 2 years ago

With this version https://github.com/home-assistant/core/issues/63421#issuecomment-1005520934 its working as expected after the factory reset (unplug / replug 3-4 times and resetup wifi)

iskiselev commented 2 years ago

Tested you latest version. It preserves white channel now. So after turning it off and on, it makes white level same that it was before turning off. But it still set RGB channel to 59,0,255 no matter what it was before turning off.

iskiselev commented 2 years ago

@bdraco, thank you a lot - I found that 59,0,255 is reproducible even with remote control. After finding it, I have restarted the controller and it fixed the issue. Sorry that idea to physically power it off/on have not come up to my mind earlier. It works great now! Issue is resolved for me.

bdraco commented 2 years ago

So it seems like the controller gets into the confused state if we send the RGB and W commands too close together. I'll add a delay between them

bdraco commented 2 years ago

I uploaded a another new version that adds the spacing delay

mkdir /config/custom_components
cd /config/custom_components
rm -rf flux_led
git clone https://github.com/bdraco/flux_led_custom flux_led

Then restart

bdraco commented 2 years ago

I'm not able to get it back into the bad state where it needs the reboot once the delay between RGB and the W command was added.