Obtaining cloud connection status from API

Is it possible to find out whether a light is connected to the Lifx cloud using the LAN API or perhaps some other way?


You can do this with the HTTP API.

First, get a token from https://cloud.lifx.com/settings

and then run

curl https://api.lifx.com/v1/lights -H"Authorization: Bearer $TOKEN"

You can also specify a particular device using a selector

curl https://api.lifx.com/v1/lights/label:den -H"Authorization: Bearer $TOKEN"

And look for the connected property for each device.

Thanks but I am getting an error about an untrusted root certificate (SSL). Is there a way to do this through Python directly?

Well that’s strange. If you’re on Linux you may need to apt install ca-certificates

In Python you can do something like

$ python3 -m venv .requests
$ source .requests/bin/activate
$ pip install requests
$ python -c "\
import os, requests; \
res = requests.get('https://api.lifx.com/v1/lights/label:den', headers={'Authorization': 'Bearer ' + os.environ['PROD_API_TOKEN']}); \
print(res.content.decode()) \

I am on a Mac (El Capitan) and I have no clue why this is happening.

In Python i get a KeyError when i input the res = … line. I have substituted PROD_API_TOKEN
with my token of course.

Any ideas?

Running the curl commands provided by @delfick-employee above on macOS Catalina work just fine.

The api.lifx.com endpoint uses Let’s Encrypt certificates with the DST Root CA X3 which is listed on List of available trusted root certificates in OS X El Capitan - Apple Support for El Capitan. You may want to make sure you have all available updates (though El Capitan was last updated over 21 months ago).

Note that upgrading to at least High Sierra (10.13) is definitely recommended. Apple tend only to support N-2 versions of their OS, so currently that’s Catalina (10.15), Mojave (10.14) and High Sierra (10.13).

I am aware but my Mac is old sadly. That said, I am not sure why the requests on Python complains.

High Sierra at least is available for Macs that are ~10 years old: https://en.wikipedia.org/wiki/MacOS_High_Sierra

As for the Python, it assumes you’ve run export PROD_API_TOKEN=<token> and you have a light with the label of den.

Changing the res line to this should get you all your lights:

res = requests.get('https://api.lifx.com/v1/lights', headers={'Authorization': 'Bearer <LIFX_TOKEN>'})

The key error comes from the environment variable not being available (you replaced the key of the os.environ dictionary, instead of replacing the entire thing. Note that if you do replace the entire thing, you don’t have to import os either.

1 Like

Thanks, this does the trick. Regarding High Sierra, again I am aware but it is a major resource hog. I tried it on my laptop and things have slowed down a lot.

1 Like

Glad it’s working for you. Hope you’re able to get your Mac upgraded soon, too as you’re going to start hitting more issues with security-related fixes and such not being published for El Cap.

Though, I do highly recommend visiting the real El Capitan in Yosemite National Park. It’s quite beautiful. :slight_smile:

1 Like