Setting a Scene with LIFX and Node-RED via Web API Call
Firstly you need to install LIFX node.
Please follow the instructions on this site to get your install registered with LIFX. The process is relatively straight simple to follow.
You will notice however that there is no ability to activate a predefined LIFX scene. The latest version does have a node to do this but I can’t currently make it work. That aside this post is still helpful in making calls to cloud API’s via Node-RED.
From the setup you need to gather your key. Be sure to record this as it is only given to you once. This is used later under the name of ‘Bearer’.
You will have also needed to have setup a LIFX scene via the various apps. I’ll expand this post if anyone is interested in how you get the UUID of this scene. From memory I think I had to do extra queries to get the list of scenes and UUID.
The flow looks like this
The start scene is just a simple injection.
The set token and headers is a function node and looks like this.
I have cut off the bearer details as they are my own. There is a space there so it is like ‘Bearer xxxx’;
What we are doing here is setting up the msg.payload details to hold the duration of starting the scene and the headers to hold the Authorization key needed to call the scene via the LIFX Cloud API.
Next node is the actual web call.
The scene ID is the one I found for my own setup of ‘Warm House’.
Last node is just a debug which is all worked should return a JSON object showing the number of bulbs which have responded to the scene call.
Now using this technique to set a scene about 10 mins before sunset and feed in duration to gradually bring my lights on when it gets darker. That workflow involves a presence check which I’ll show shortly.
As mentioned the LIFX API node has been updated to include the ability to activate a scene, however when I feed it the correct selector details it did not work so staying with this process. Sure it is a couple of extra steps but also a handy bit of nodeCode to show how to call make a Web API call with headers etc.
Hope this is helpful for others.