LIFX Developer Zone

Lifxlan issues (lights not being found)

Hi, I’m trying to develop with the LifxLAN python package but half the time it just won’t find my lights at all or give workflow exceptions whilst trying to perform actions. Is this an issue with the library or how the lights connect over the network?

I’m trying to create something using the lights and it’s really annoying when half the time it just doesn’t work and I have to keep refreshing over and over for up to 2/3 minutes just to get them recognised by the library. Any ideas would be much appreciated.

Thanks!

Describe your development environment, i.e. how is the code you’re running connect to the network itself?

Though, it’s weird that just refreshing over and over makes it work. I would’ve thought it would either respond or not.

Have tried both with a desktop PC connected through ethernet to the router, and a laptop with a wireless connection. The light doesn’t appear in the list of devices for a 1/2 minutes and then will randomly appear again. The times where it does pick it up on creation of the LifxLAN object, I assume it loses connection again as I often get workflow exceptions.

Can’t figure out whether it’s an issue with my network, the light itself or the library :confused:

How many bulbs do you have? Is it just one that it doesn’t find or all of them? If your code is on GitHub, or you can DM it to me, I’d be happy to test it on my fleet of 50+ bulbs. :slight_smile:

Thinking about it actually, it could just be the LIFX Z that I’m testing on because it always has behaved slightly weird, the app sometimes has trouble connecting to it as well.

Honestly it’s pretty easy to test, literally just install the lifxlan package in Python and create a LifxLAN object and call get_lights() and have a look at the size of the array. Would be interesting to know how many of yours it picks up and if you have any issues with the Z?

Working on this local smart home control system and the lights not showing up is a bit of an issue, may have to resort to the HTTP API (if that’s any better?) if I can’t find a way to resolve it.

Thanks :slight_smile:

Yeah, the Z is a known iffy device, usually because of the placement of the controller and its proximity to power. I have a couple of LIFX Z that are fairly stable now though, so I’ll give it a try in later today as I’m out for the next 4 hours or so.

1 Like

Ah, didn’t know that was a known issue with the Z. That might be it, and thanks for offering to test! Your Zs that you think are stable now, did you do anything to help or is it just random?

I did a lot of trial and error of placement of the controller and alignment and cable layout so that the controller was either vertical or horizontal depending on the alignment of the closest AP.

1 Like

Alright thanks, I might try to see if I can get it a little more stable. In the mean time, I do have a Mini Colour which I might be able to try testing on, I’ll see how it goes. Thanks!

Tried it with a Mini Colour and has similar issues, the library wouldn’t reliably pick up the light. I have ended up switching to using the HTTP API which, although it’s slower, seems to much more reliably communicate with the lights I own. This works with with my project as I don’t need many API calls so I shouldn’t get rate-limited.

Interested to know if other people experience the same issues though.

Sorry, I completely forgot about this. Can you send me some sample code? I can then run it on my network for you. Happy to clone a git repo, but I don’t have enough cycles today to create the code from scratch (as I’m busy working on my own project on the side).

The git repo is private at the moment, but you just paste this into a python file and run it, that should work. Use pip install lifxlan first.

from lifxlan import LifxLAN

lifx = LifxLAN()
print(len(lifx.get_lights()))

That should print out the number of lights it has found on your network, would be interesting to see how many it finds. Thanks for offering to test!

➜ $  for i in {1..10}; do time python3 lifxtest.py; done
44
python3 lifxtest.py  0.44s user 0.03s system 19% cpu 2.365 total
43
python3 lifxtest.py  0.42s user 0.02s system 18% cpu 2.416 total
44
python3 lifxtest.py  0.43s user 0.02s system 18% cpu 2.420 total
44
python3 lifxtest.py  0.46s user 0.03s system 19% cpu 2.511 total
44
python3 lifxtest.py  0.43s user 0.03s system 18% cpu 2.513 total
44
python3 lifxtest.py  0.43s user 0.03s system 18% cpu 2.394 total
44
python3 lifxtest.py  0.43s user 0.02s system 18% cpu 2.456 total
44
python3 lifxtest.py  0.45s user 0.03s system 19% cpu 2.420 total
44
python3 lifxtest.py  0.42s user 0.03s system 19% cpu 2.233 total
44
python3 lifxtest.py  0.42s user 0.02s system 18% cpu 2.389 total

However, there is something weird going on because Photons finds all 48 devices:

for i in {1..10}; do time lifx lan:find_devices 2>/dev/null | wc -l; done
      48
lifx lan:find_devices 2> /dev/null  0.34s user 0.07s system 45% cpu 0.900 total
wc -l  0.00s user 0.00s system 0% cpu 0.899 total
      47
lifx lan:find_devices 2> /dev/null  0.38s user 0.06s system 28% cpu 1.530 total
wc -l  0.00s user 0.00s system 0% cpu 1.529 total
      48
lifx lan:find_devices 2> /dev/null  0.38s user 0.06s system 28% cpu 1.534 total
wc -l  0.00s user 0.00s system 0% cpu 1.533 total
      48
lifx lan:find_devices 2> /dev/null  0.38s user 0.06s system 28% cpu 1.544 total
wc -l  0.00s user 0.00s system 0% cpu 1.544 total
      48
lifx lan:find_devices 2> /dev/null  0.32s user 0.06s system 41% cpu 0.918 total
wc -l  0.00s user 0.00s system 0% cpu 0.917 total
      48
lifx lan:find_devices 2> /dev/null  0.33s user 0.06s system 42% cpu 0.921 total
wc -l  0.00s user 0.00s system 0% cpu 0.920 total
      48
lifx lan:find_devices 2> /dev/null  0.32s user 0.06s system 41% cpu 0.915 total
wc -l  0.00s user 0.00s system 0% cpu 0.915 total
      46
lifx lan:find_devices 2> /dev/null  0.37s user 0.06s system 28% cpu 1.537 total
wc -l  0.00s user 0.00s system 0% cpu 1.537 total
      47
lifx lan:find_devices 2> /dev/null  0.37s user 0.06s system 27% cpu 1.533 total
wc -l  0.00s user 0.00s system 0% cpu 1.533 total
      48
lifx lan:find_devices 2> /dev/null  0.38s user 0.06s system 28% cpu 1.546 total
wc -l  0.00s user 0.00s system 0% cpu 1.545 total

Yeah, does seem to be missing some then, but your tries were still quite consistent (most were 44) whereas mine can be pretty random regarding how many of my 3 lights it picks up, and even if it gets all these if often loses connection and gives me exceptions.

Still not really sure what’s causing it, maybe a congested network or something… I’ll probably stick with the HTTP API for now, but if anyone has any similar issues with the library / your lights please let me know.

Thanks for testing for me @Djelibeybi :slight_smile:

Why not switch away from using LifxLAN across to using Photons, though: https://github.com/delfick/photons-core – at least this is maintained and by a LIFX developer.

1 Like

That’s actually the first I’ve heard of Photons, I’ll have a look, thanks :slight_smile:

1 Like