LIFX Developer Zone

Newbie Question


#1

I am new to python and to smart lights. I’m trying to connect an Lifx bulb through python code running on a laptop to change colors based on a set of external data. I’m having trouble with the connectivity. Can you help?
thanks


#2

I am not a pro on python coding but I could help you with your communication with a LIFX device.

First, you have to choose how you want to communicate with it:

  • HTTP API: you need to be connected to Internet (working with LIFX cloud)
  • LAN Protocol: you can use it locally

I let you choose.


#3

Thanks

We are using LAN/ wifi


#4

And what’s wrong with your connectivity?


#5

I’m using python package lifxlan. The class within the module should be lifxLAN (according to GitHub)

My statement

Lifx=lifxlan(1) (creating an instance of the class)

Gives me an error module object is not callable

Importing the class from lifxlan

(from lifxlan import lifxLAN)

Gives me an error: No Module names lifxLAN

I think I might be missing a step. Or this there an ‘official’ python package I should be using?

I was a programmer many years ago and technology has changed a bit since then. I have the logic for changing the color I need to, but its connecting my code to the light bulb I’m having trouble with.

Karen

Mail](https://go.microsoft.com/fwlink/?LinkId=550986) for Windows 10


#6

I think it is a good practice to start with Photons - Opensourcing a new framework for interacting with LIFX lights

Good luck


#7

Photons is indeed another option :slight_smile:

As for lifxlan, are you sure you’re running the same python you installed lifxlan into?


#8

actually, I think I know what your problem is.

LifxLAN is capitalized.

So try something like

from lifxlan import LifxLAN
lifx = LifxLAN(num_lights)

#9

Hi Stephen

I’ve tried that

import requests

import time

from lifxlan import lifxLAN

def connect_light_source():

num_lights=1

print(“before connect”)

lan=lifxLAN(num_lights)

kp_lifx=lan.get_lights()

print(“after connect”)

return kp_lifx

error:

import requests

import time

from lifxlan import lifxLAN

ImportError: cannot import name lifxLAN

Mail](https://go.microsoft.com/fwlink/?LinkId=550986) for Windows 10


#10

python is case sensitive.

You want

from lifxlan import LifxLAN
lan = LifxLAN(num_lights)

instead of

from lifxlan import lifxLAN
lan = lifxLAN(num_lights)

The difference is LifxLAN starts with a capital L


#11

Have a look at the source code. There are samples including hello world script.
This will help immensely.
download the code from Github and have a good look.

Do you have Python 2 and 3 installed ? Which is your primary ? What pip command did you use to install it ?
If you have both 2 and 3 installed and you run pip then it may have installed into 2 but your path may go to python 3 and thus when you use the python command it can’t find the resources it needs.

pip3 will install into python 3 if you are unsure.


#12

thanks. Got program working but think I need to switch to the HTTP API protocol. The bulb needs to travel for client’s presentations. Setting up and resetting the hardware with every new wifi network is cumbersome. Any tips?


#13

Buy a wifi router. Cheap one will do. You don’t need internet access if you use the local lan and once onboarded to the router wifi you are good to go.


#15

If I create a mobile hotspot on the laptop, will that work?


#16

It might, but it’ll be difficult because you can’t easily configure the DHCP settings on a mobile hotspot. A cheap wifi router is going to have a higher chance of success.

A colleague of mine does this with his sound desk to avoid having to deal with patchy wifi at venues. They can be had for under £20. In fact we were discussing doing this with smart bulbs just the other week.

You simply fire up the wifi router, then connect your phone to it, and set up the light as normal. Then to make everything easier next time, in the router settings set a DHCP reservation for the light so it’s always given the same IP.

In future, it’s a simple case of switching on the router, waiting for it to start up, then switching on the light.