LIFX Developer Zone

Script Pulsing Lights


#1

Hey Guys,

I’m very new to this and not very good at scripting, though I was wanting to be able to pulse my lights between colours, eg green and red for Christmas.

Can you do this via a python script or http api call? If so, any chance someone could help me out, maybe post an example I can work off. I have 19 lights I want to play around with, :slight_smile:

Thanks.

Dave


#2

Try this:

#!/usr/bin/python
import requests

# Get token from: https://cloud.lifx.com/settings
token = "YOUR_TOKEN_HERE"

headers = {
    "Authorization": "Bearer %s" % token,
}

data = {
    "period": 5,
    "cycles": 5,
    "color": "green",
    "from_color": "red",
}

response = requests.post('https://api.lifx.com/v1/lights/all/effects/breathe', data=data, headers=headers)

The is will breathe all your lights red and green, 5 times, with each cycle taking 5 seconds. Play with the values in here to get different results. I based this off the documentation for the breathe http api call.


#3

Wow, thanks Daniel!

Now forgive the n00b question, but when I try and run it I get the below error;

C:\Users\Dave\Desktop>“Lifx Christmas.py”
Traceback (most recent call last):
File “C:\Users\Dave\Desktop\Lifx Christmas.py”, line 2, in
import requests
ModuleNotFoundError: No module named ‘requests’


#4

Never mind, I did pip install requests and it’s working!!! Thanks heaps!


#5

Actually, one question, how do you make it set 100% brightness also?


#6

The brightness is defined as part of the color, there is a page in the api docs where we document the different options.

So just change the colors to be red brightness:1 and green brightness:1.


#7

Legend !!! Thanks mate.


#8

Hey Daniel,

Do you know of a way to schedule this API call, either via Lifx App, Google Home or iOS? Wanting it to run at like 6pm on certain days.

Thanks.

Dave