I’m just starting out with this so sorry if the question is basic, but how to I construct a URL I can put into a browser to send commands to LIFX? I’m thinking if I can work out the structure I can make a few pre-cooked URLs and build some simple utilities.
I’ve created a ‘Token’ and visited the page here for example: https://api.developer.lifx.com/docs/toggle-power
and there I can toggle my lights, and I’ve also set up commands to change colour etc. and it works ok. I’ve read some of the docs but I’m still confused about the structure of a command I can just put into a browser.
It says for instance: curl -X POST “https://api.lifx.com/v1/lights/all/toggle”
-H “Authorization: Bearer *******************************************************”
(I’ve taken out the token) but what do I do with that to make it an actual URL?
Edit: I’ve even just set up Wireshark in case it can show me what’s happening but I can’t see anything that looks like a command line URL. I can see some commands sent my my lights locally so I guess the original command is from LIFX and not from the web page? Don’t know??
So, the curl command is run in the terminal, rather than the browser. And wireshark is a diagnostic tool, it’s complicated even for me, you won’t need that.
So to run the command, let’s start with what your environment is. Are you on Windows, MacOSX, or Linux?
Oh I see, thanks. I’ve got the toggle command to work in the command console. (I copied the curl from the window and took out the carriage return, and made a space before the -H) I’ll have to go read up what a ‘curl’ is, thank you for getting it working.
I can now see my 5 lights listed in the returned result, but there is one extra one listed and shown as ‘offline’. What would that be?
Also, in the console I can see the last line is 'curl: (6) Could not resolve host: ', but that doesn’t happen in the window in the LIFX page. Is that telling me anything?
I wonder if it’s thinking I have 6 lights? I did have to send a faulty one back so perhaps I need to delete it’s footprint somewhere?
Edit: BTW, if I figure out some way to use this, will that ‘token’ keep working or will it time out after a period?
I’m confused how it would work but also complain about resolving the host. Is that with a different command you ran?
Do you see 6 lights in the mobile app?
And the token will work forever, until you manually revoke it from cloud.lifx.com
No, it’s just one command. That line is just tagged on the end of the response like this:
==== some more here
"label": "Rear Right",
}curl: (6) Could not resolve host: \
That shows the first and last few lines as copied from the console. That first one is the only one that has blank label as “”. All the others have an ID. (I asterisked out that last one)
No, I can only see 5 lights anywhere in the app. My guess is that as I’m trying to ‘toggle all’ then I have 6 lights registered on the system but only 5 are active.
Although that is just a oddity. The post was about how to make the curl work and you’ve done that thanks.
Hmm, weird. It looks like that offline light is registered but it’s never been able to connect to us. You can delete it from https://cloud.lifx.com/devices
What is the specific curl command you are using?
Also, in the forum posts, you can use triple backticks (the button to the left of the 1 on your keyboard, the `) to do code
so, without the spaces
Thanks, I’ve just edited my last post and added those ```. It looks better now
I’ve used that link and deleted that device. Now that first item with a blank ID has disappeared so now I have the correct number of devices. That line is still appearing though.
}curl: (6) Could not resolve host: \
The command I’m using in the console (with the token removed) is
curl -X POST "https://api.lifx.com/v1/lights/all/toggle" \ -H "Authorization: Bearer *********"
I just Googled that line and it seems to be some curl problem to do with dns or ipv6 or something. Probably not a big deal. It’s working anyway
I can immediately see what’s happening!
It thinks the
\ is another url to try.
In the examples that slash is there to break up the command across multiple lines. But on windows that doesn’t work (I’m not sure what the equivalent for windows is). If you remove the
\ then it’ll stop complaining
Aha, that’s fixed it, nicely spotted. I thought that backslash looked just slightly odd there but didn’t dwell on it.
I think that’s it all sorted for now. I’ll try out some other commands and see how I get on. Thanks a lot.
Don’t be afraid to ask more questions
If you are looking for a browser interface for your LIFX bulbs and also other home automation systems and don’t want to hand over control of your life to Google or Apple, running an Openhab server takes very little investment. The LIFX binding requires no cloud connection at all!
Thanks that sounds interesting. I guess control without needing a cloud connection should be faster. I just tried out an app, LifxTools, that can control my lights by just being on the local network and not needing any passwords or anything and that seems to work fine too.