Advanced LIFX LAN control for Flic with Photons Interactor
The Flic Hub LR has local LIFX LAN support, but the functionality is quite limited. It only allows you to toggle power state, turn a bulb on/off or change its colour. The only other option is the ability to trigger a scene via the LIFX Cloud. This post details a third option, which is leveraging a local Photons Interactor server to do complex transfomations triggered by a Flic.
Thse examples should work just fine using the either original Flic or new Flic 2 buttons because it’s all done with the phone app or Hub LR and not the buttons themselves.
Prerequisites
This is pretty advanced configuration and assumes an understanding of JSON formatting and submitting HTTP requests. If you’re unfamiliar with either of those, it may be a little too advanced for you right now.
I highly recommend the use of Postman to play with this stuff to see what it can do, before trying to implement it with your Flic(s).
Install Photons Interactor. The simplest way to get this working is via a Docker container. You can grab the official Photons Interactor image. The official image has been updated for muilt-arch support so it’ll work on things like a Synology NAS or a Raspberry Pi.
If you have Docker installed, the following command will start a Photons Interactor container:
|
|
Note: This doesn’t work on Docker for Mac or Docker for Windows. You will need to run Docker on a device running some flavour of Linux, including NAS and Pi devices.
You can test if Photons is working by running the following curl
command:
|
|
If all your bulbs just turned on and went bright red: congratulations! Photons is working.
Flic Configuration Examples
Photons accepts PUT
requests with a JSON payload to perform tasks on the local network, including HTTP-like transforms, triggering firmware effects (like morph, flame and move) as well as Tile animations driven by the Photons server itself. Below are just a couple of examples of what’s possible.
Photons supports the use of the
matcher
argument that uses several filters to find devices dynamically. The following examples will use different filters as examples of how to find devices at run time.
To configure the Flic:
Field | Value |
---|---|
Hub Action | Internet Request |
URL | http://<docker_host_ip>:6100/v1/lifx/command |
Content Type | application/json |
Body | JSON derived from one of the examples below |
Trying to type JSON on an iPhone is really tedious, so I recommend using hand-off from a Mac to cut and paste instead. The examples below are just the JSON required for each request.
Example: Night Lights
The following JSON will target all bulbs that have variable colour temperature and slowly transition them to Sunset (2000K
) at 3% brightness over 30 seconds and then turn the bulbs off. I use this at night so that if my lights come on unexpectedly, they will not be bright enough to disturb any one.
|
|
Example: Pulse a light three times
The following JSON will target a specific bulb named My Bulb
and make it flash red three times. If the bulb is off, it will be turned on first and will remain on afterwards.
|
|
Example: Animate a Tile
The following JSON will target all Tiles on the network and start the Pacman animation. Note that this is very noisy on the network as the Photons server is sending lots of state change messages to your Tiles. If you already have a busy network, you should review the documentation on adjusting animations for noisy networks.
|
|
Example: Stop all animations on all Tiles
The following JSON will target all Tiles on the network and stop any Photons-controlled animations:
|
|
Note: the command will not clear the final animation frame from the Tile, so you may want to send a second Internet Request that performs a Transform to change the Tile back to a solid colour.
What else can I do?
Photons can do a whole lot more wtih your LIFX devices, so it’s worth reading the Photons Interactor documentation to see what other commands are available.
In particular, you can use the set
command to send low-level binary packets and payloads to your bulbs. For example, the following JSON will start the Move firmware effect on all LIFX Beams:
|
|
While the following will stop any running firmware effect by switching to the “OFF” effect:
|
|
These sorts of payloads need to be well-crafted and tested, which is where Postman comes in handy for being able to quickly and easily modify and test JSON permutations.