Flux Led/MagicLight don't work since few updated

Hi,

I integrated my Flux Led/MagicLight into HA and everything worked fine in the beginning. I use the LED controller to switch my aquarium lights. In the automation the lamps are switched on at a certain time and switched off again later. This worked fine until a few updates ago.
But now the lamps cannot be switched on any more. Switching them off still works. If I switch the entity over the lovelace surface, the button goes briefly to the right and goes after a certain time again to the left, without the lamp was switched on. If I switch the LED controllers via services with ā€œlight.turn_onā€ or ā€œhomeassistant.turn_onā€, the lamp flickers briefly and then goes out again immediately.
What is my problem here?
Every now and then the following message appears in the log files:

2019-10-29 19:20:18 WARNING (MainThread) [homeassistant.components.light] Setup of platform flux_led is taking over 10 seconds.

As I said, switching it off works without any problems.

light:
  - platform: flux_led
    devices:
      192.168.1.67:
        name: LED Controller RGB 60 - 1
        mode: "w"

images

Just wanted to add that Iā€™m in the same boat. Everything was working smoothly a while ago. But after some downtime with the LED strips while getting new power supplies for them, now Iā€™m getting the same usage issues as Sƶren

I realized something last night. I can easily control my LED strip via HA. Switch on, switch off, change the colour of the white light, set the colours ā€¦

Iā€˜m using this MagicHome controller:

That controller looks different to the one in the first post, have you had to replace the controllers to get the lights working properly again?

This is caused by an issue with the Home Assistant flux_led component. I was able to patch it to resolve this by doing the following:

Edit light.py in your homeassistant/components/flux_led folder and change the following:

Comment out or delete these lines in the def turn_on(self, **kwargs) method:

#        if not self.is_on:
#            self._bulb.turnOn()

Further down in this method, below these lines:

        # Preserve current brightness on color/white level change
        if brightness is None:
            brightness = self.brightness

Add in the following:

        # If these are 0 then bulb.isOn will return false, not what we want
        if hs_color is None or (hs_color[0] == 0 and hs_color[1] == 0):
            hs_color = (1, 1, 1)
        
        if brightness is None or brightness == 0:
            brightness = 100

Iā€™ve uploaded the modified light.py with the above changes made here:

So you can either make the edits above or just download the updated light.py file from the gist above and drop it in your homeassistant/components/flux_led folder and restart HA to solve the issue. The location of your homeassistant/components/flux_led folder will vary based on your Python setup, for me it was at /srv/homeassistant/lib/python3.7/site-packages/homeassistant/components/flux_led

The issue seems to be caused because setting the brightness or colors to zero immediately after calling self._bulb.turnOn() (which the Home Assistant component is doing) causes the state in the library to be changed to off which causes the turn on and immediately turn off behaviour.

Also, this is the configuration I have for the LED Strip in my configuration.yaml

light:
  - platform: flux_led
    devices:
      192.168.1.100:
        name: LED Strip
        protocol: 'ledenet'
        mode: rgb

This was tested under Home Assistant 0.103.0.

5 Likes

Hey @john32
I tested your script and controlling the lights works now, so thanks!
But it does not seem to be able to get a proper light name. It used to be light.mac_ip-address, but now it just says light.name in the entity list on the States page.
So if I use multiple v8ā€™s, that might give issues since they will have the same name. Or will hassio rename duplicates?

@Glenn_Ruysschaert Great to hear that fixed it for you! Iā€™m not to sure about the entities name issue - I did notice you can rename an entity by going to the configuration section in the web interface and then clicking on the device. I think HA will automatically add _1 _2 etc. to avoid duplicate names if you have multiple lights.

Hi @john32

First of all thanks for your help!

Iā€™m using HASS.io and i think itā€™s not possible to modify the light.py fileā€¦ how can i fix this issue?

Thank you so much!

1 Like

@Blai89 You canā€™t fix this without changing the light.py file as this is the component causing the problem. But I think you can modify the HASS.io files - someone did it here: How to edit components in Hass.io?

So you could try that. Good luck!

1 Like

Hi @john32.

I almost got it thanks to the link you sent me.

Iā€™ve found te directory with all the components in /usr/local/lib/python3.7/site-packages/flux_led, but there is no light.py file, only main.py and this is not the same content as your fileā€¦

Again, thank you so much for your help! have a nice year!

@Blai89 See if you have /usr/local/lib/python3.7/site-packages/homeassistant/components/flux_led/light.py and replace this with the one I provided instead.

The /usr/local/lib/python3.7/site-packages/flux_led one you have found is the flux_led library used by HA but it is the HA component itself that you need to edit. I think it should be in the path Iā€™ve given above.

Ohhh i found it! itā€™s in /usr/src/homeassistant

Thank you so much! with your code it works but sometimes when i turn on the leds hassio takes a few seconds to refresh de stateā€¦ even soā€¦ it works!

Thank you so much!

I canā€™t find the homeassistant folder in my configuration so I canā€™t replace the light.py script. Any ideas?

At the moment I canā€™t even get the flux_led component to find any devices.

I installed flux_led by just doing a ā€˜pip3 install flux_ledā€™ and Iā€™m able to control the LED strip again using the cli ā€˜flux_ledā€™. I tried putting the new light.py in place but its still not working. Iā€™m guessing if the flux_led python library is updated in home assistant it will start working again correctly. For now Iā€™ve had to make a custom shell_script in the configuration.yaml to call the flux_led python by hand and it all works again. Quite frustrating.

Hi again @john32,

After HA update the light.py file returns to the original codeā€¦

Do you know hot to avoid this? Thanks so much!

Thanks for all your help!

I canā€™t fix the problem.

So I decided to flash ESPhome to the wifi controllers and now I have no more problems.

@Blai89 My fix was really only a bandaid fix to get things running and an HA developer probably needs to look at this next. I had a look on github and it looks like there are a few devs aware of the issues with the flux_led component already and I would be surprised if this doesnā€™t get fixed soon in an update.

Until it gets fixed properly in the HA codebase youā€™ll have to copy over the light.py after each update for now Iā€™m afraid.

Rather than edit the original component, make a copy as a custom component. Create the folder (if it does not exist) /config/custom_components/flux_led and then copy the original files from source in to the new folder. Then overwrite light.py with @john32ā€™s version and restart Home Assistant.
Home Assistant will detect the flux_led component in the custom_components folder during boot and override the original component.

Many thanks @john32, the edited code worked great for me :grinning:

1 Like

I couldnā€™t find the original HA config files on the server. Iā€™m not very good with linux style OSā€™s so thatā€™s probably why. So, I just tried the fix suggested by @Siytek but that actually made it worse. Now I donā€™t have ANY control via HA. The switch still just turns on then right back off (the light doesnā€™t turn on at all) but now I have no controls for color at all. Not that they worked anywayā€¦

@HotRod50m what is in your configuration.yaml file? Did you try with and without the ledenet protocol? Did it ever work for you with previous versions or are you configuring it for the first time?