CorneliousJD / Flux_LED

Modifies homeassistant/components/flux_led/light.py to fix issue where LED lights using MagicHome controller turn off immediately after turning them on with V8 firmware.
25 stars 11 forks source link

Single colour (monochrome) LED controller not reporting brightness #11

Closed aheath70 closed 3 years ago

aheath70 commented 3 years ago

I have a single colour (monochrome) controller, and reporting and setting brightness does not work. It constantly reports the brightness as 0, and if I try to set the brightness in HA, no errors happen but it does not set the brightness. I suspect that it is because the "w" mode is trying to set the brightness via the white level rather than brightness itself.

I hacked around with the code a little, and managed to get the brightness reporting correctly and setting it if it is below 40%. If I try to adjust the brightness via HA above 40% it simply doesn't work. If I adjust it using the MagicHome app it works perfectly, and it reports the correct brightness to HA.

I got the brightness working by changing the code at approximately line 452-353:

if self._mode == MODE_WHITE:
            self._bulb.setRgbw(0, 0, 0, w=white, brightness=brightness)

and commenting out the following lines at approximately line

        # if self._mode == MODE_WHITE:
        #     return self.white_value

I am completely lost as to why the brightness cannot be set from within HA to higher than 40%.

CorneliousJD commented 3 years ago

Sorry to say that this repo is more so just to document the fix that ended up working for me personally and leave it open to updates/revisions by me, bugfixing someone else's issue isn't something I can do here. you will probably have better luck on the actually integrated/supproted Flux_LED, or another fork.

I will leave this open as an issue though incase someone else comes along and has something to add to the conversation, you'll be alerted (assuming you have e-mail alerts on for replies to your issues)

aheath70 commented 3 years ago

No worries.

FYI, I figured it out. On the monochrome controller brightness is not actually controlled with the brightness attribute. It is solely controlled by the value of the Red channel. Set it to 127, and you get 50% brightness. Set it to 26 and you get 10% brightness. I figured this out by installing the python flux-led package on a Linux box, and just playing around with the different commands to set colours, brightness, white values, etc.

So I changed the following:-

if self._mode == MODE_WHITE:
            self._bulb.setRgbw(0, 0, 0, w=white, brightness=brightness)

to

        if self._mode == MODE_WHITE:
            self._bulb.setRgbw(r=brightness, g=0, b=0, w=0, brightness=brightness)

and it is now working perfectly.

CorneliousJD commented 3 years ago

Awesome, thanks for posting your findings! Great resource for others who might come looking in the future :)