I am currently trying to integrate my 6 bulbs into my home automation system. Thanks to the HTTP API, I can send command like “turn this bulb on” or off.
However, I struggle into finding a way to retrieve the state of a bulb. I can’t program things like “Turn light on if they are off” because it can’t know if it’s actually on or off.
Would you have any idea on how to do such thing? A script?
Thanks a lot for your help on this.
The List Lights endpoint includes the state of each matched bulb. Use can use the selector to get the state of all, or just a few lights.
Thanks for your clear answer Daniel. However, “power” can not be a selector, right? When I send a list command, I would like to get only the state in my result, because my home automation can not interpret the whole list answer.
I don’t know if it’s possible yet.
Well that depends on what scripting language you can use. Generally though you will want to write something that parses the JSON data you get back from the API, and removes the things you don’t care about.
What are you using for your home automation?
Thanks for that! I found how to do retrieve my bulbs state!
I don’t know why but my mind was stuck on the PHP side of things and I completely forgot that the data was interpreted in JSON.
I use Jeedom as my home automation system, and it can interpret scripts. I did the following:
$json = shell_exec('curl -H "Authorization: Bearer MYTOKEN" "https://api.lifx.com/v1beta1/lights/id:XXXX"');
$state = json_decode($json);
As simple as that
Excellent! Glad to see you got it going!
I should probably point out that using
shell_exec in PHP isn’t a great idea for security reasons. That’s mainly an issue if there is user entered data being added to the command, which doesn’t seem to be the case for you. However if you do want to avoid a
shell_exec, we have a PHP example using
libcurl in the API docs.