Wednesday, April 5, 2017

Node-RED + F.lux

With the newest release of f.lux beta for Windows, f.lux adds support for a LAN API to tell devices when f.lux changes, along with support for Philips Hue and ColorKinetics. Since I don't have any of those devices, I decided to give the API a try to get it working with Node-RED.

f.lux will perform an HTTP POST to the specified URL when f.lux changes



Since I had used Peter Scargill's "the script" to install Node-RED (along with a lot of other awesome tools) on my Raspberry Pi 3, HTTP is secured by default (2021 update: nowadays I just use the "optimized software install" feature of DietPi to install Node-RED). Since the f.lux POST request doesn't support authentication, I had to comment out ("//") the "httpNodeAuth:" line in my ~/.node-red/settings.js file, and restart the Node-RED service (sudo service nodered restart):



After this, my HTTP in node was able to pass messages over to the debug output. After digging through the entire message object, I realized "msg.req.query" would provide a JSON message with color temperature and brightness values:




From there, it should be pretty much self explanatory if you've experimented with Node-RED a little bit. One could use msg.req.query, and process the JSON message, or just use "msg.req.query.bri" and "msg.req.query.ct" for values of brightness and color temperature, respectively. This could easily be incorporated into a function or other nodes, but for now I've just used the debug output:



As far as implementation goes, I could have it turn on/off a lamp at a certain brightness level (say, with MQTT and the ESPurna firmware, change the brightness of some NeoPixels (I don't have any of those in an IOT setup quite yet, just an awesome Ambilight clone), or control a wide array of devices that are accessible with Node-RED. At this point it's up to the reader's imagination to figure out what to do with this, I just wanted to report my findings on this awesome new feature.