#!/usr/bin/env python
import requests
import time
token = ''mytokenhere''
headers = {
"Authorization": "Bearer %s" % token,
}
def restore_state(state):
selector = 'id:%s' % state['id']
# Color is sent as one string, so we have to convert it
color_items = state['color'].items()
color_strings = map(lambda x:'%s:%s' % x, color_items)
data = {
'power': state['power'],
'brightness': state['brightness'],
'color': ' '.join(color_strings),
}
response = requests.put('https://api.lifx.com/v1/lights/%s/state' % selector, data=data, headers=headers)
def fetch_states(selector='all'):
response = requests.get('https://api.lifx.com/v1/lights/' + selector, headers=headers)
return response.json()
print 'Storing the current state of the bulbs'
orig_states = fetch_states()
print 'Waiting 10 seconds, change the color of the bulbs now'
time.sleep(10)
print 'Restoring lights to the state they were 10 seconds ago'
for state in orig_states:
restore_state(state)
I am pretty sure you don’t need the “@@” for spaces when using executeCommandLine. And even if you did, I don’t think it is needed in this case.
make sure python is in /usr/bin
replace the line at the top with #!/usr/bin/python
I have a number of executeCommandLine calls, all of which have spaces, none of which use @@. So I can say it is not always required and in my experience not required as often as it is when using the Exec binding.
OK now I haev it all working - I will pull them out and see if it still does - would certainly make the code tidier. Perhaps Im getting confused with curl commands.