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:

1
2
3
4
5
6
$ docker run --name=photons \
    --detach \
    --restart=always \
    --net=host \
    -e TZ=Australia/Melbourne \
    delfick/photons-interactor:0.6.2

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:

1
2
3
$ curl -X PUT -H 'Content-Type: application/json' \
  -d '{"command": "transform","args": {"transform": {"hue": 0,"saturation": 1,"brightness": 1,"kelvin": 3500,"duration": 3,"power": "on"}}}' \
  http://<docker_host_ip>:6100/v1/lifx/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.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
{
  "command": "transform",
  "args": {
    "matcher": {
      "cap": "variable_color_temp"
    },
    "refresh": true,
    "transform": {
      "hue": 0,
      "saturation": 0,
      "brightness": 0.03,
      "kelvin": 2000,
      "duration": 30,
      "power": "off"
    }
  }
}

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.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
{
  "command": "transform",
  "args": {
    "matcher": {
      "label": "My Bulb"
    },
    "refresh": true,
    "transform": {
      "effect": "pulse",
      "color": "red",
      "cycles": 3,
      "period": 1,
      "power": "on"
    }
  }
}

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.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
{
  "command": "animate/start",
  "args": {
    "matcher": {
      "product_identifier": "lifx_tile"
    },
    "refresh": true,
    "animation": "tile_pacman",
    "power": "on"
  }
}

Example: Stop all animations on all Tiles

The following JSON will target all Tiles on the network and stop any Photons-controlled animations:

1
2
3
4
5
6
7
8
9
{
  "command": "animate/remove_all",
  "args": {
    "matcher": {
      "product_identifier": "lifx_tile"
    },
    "refresh": true
  }
}

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:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
{
  "command": "set",
  "args": {
    "matcher": {
      "product_identifier": "lifx_beam"
    },
    "refresh": true,
    "pkt_type": "SetMultiZoneEffect",
    "pkt_args": {
      "type": "<MultiZoneEffectType.MOVE: 1>",
      "parameters": {
        "speed_direction": "<Direction.LEFT: 1>"
      }
    }
  }
}

While the following will stop any running firmware effect by switching to the “OFF” effect:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
{
  "command": "set",
  "args": {
    "matcher": {
      "product_identifier": "lifx_beam"
    },
    "refresh": true,
    "pkt_type": "SetMultiZoneEffect",
    "pkt_args": {
      "type": "<MultiZoneEffectType.OFF: 0>"
    }
  }
}

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.