Creating HomeKit switches for Morph and Flame effects

Hey folks,

I know a bunch of us are HomeKit enthusiasts and many use Homebridge even with LIFX’s native HomeKit support in their newer bulbs. After @delfick-employee and the LIFX team implemented firmware effect calls in the HTTP API, I knew it would be possible to create a HomeKit switch that would turn an effect on and off and here it is.

Edited because @delfick-employee is a legend.

Requirements

  1. Install homebridge-http-switch.
  2. Get a LIFX Cloud Personal Access API token from https://cloud.lifx.com/settings

Configuration Notes

  1. Replace :selector in the configuration with the actual selector of your multizone bulbs.
  2. Replace <api_token> with your Personal Access Token API
  3. If you want to trigger the Flame effect, just change morph to flame (or FLAME in the statusPattern value).

Configuration

{
	"accessory": "HTTP-SWITCH",
	"name": "Tile Morph Switch",

	"switchType": "stateful",

	"onUrl": {
		"url": "https://api.lifx.com/v1/lights/:selector/effects/morph",
		"method": "POST",
		"strictSSL": true,
		"body": "{\"power_on\": true}",
		"headers": {
			"Authorization": "Bearer <api_token>",
			"Content-Type": "application/json"
		}

	},

	"offUrl": {
		"url": "https://api.lifx.com/v1/lights/:selector/effects/off",
		"method": "POST",
		"strictSSL": true,
		"body": "{\"power_off\": true}",
		"headers": {
			"Authorization": "Bearer <api_token>",
			"Content-Type": "application/json"
		}
	},
	"statusUrl": {
		"url": "https://api.lifx.com/v1/lights/:selector",
		"method": "GET",
		"strictSSL": true,
		"headers": {
			"Authorization": "Bearer <api_token>"
		}


	},
	"statusPattern": "\"effect\": \"MORPH\"",
	"debug": true

}

Enjoy!

Post removed because @delfick-employee is a legend.

I’ve added an /effects/off endpoint that can be used to turn off effects. It also has a power_off parameter that will turn off the light at the same time

This works for all effects endpoints, so any breathe or pulse will also be stopped.

1 Like

You’re a legend! :slight_smile: I’ve updated the sample code to reflect the API change.

awesome :slight_smile:

Hello, I have everything running… But I can’t seem to work out what is the “SELECTOR” ? Is it the name of the light ? Thank you

The selector refers to these https://api.developer.lifx.com/docs/selectors

1 Like

good afternoon and happy Sunday everyone, I’m trying to stop my sister form swapping from Lifx to Nanoleaf since apparently there scenes can also include effects. so I have 2 questions - I have managed to keep her happy by setting up home bridge and switches to get things like bias lighting and multi color light strips - but she wants a “candy cane effect” for Christmas and within the lifx app I she can get what she wants with the move effect and I think I’ve sandboxed it at my house as 2 separate switches so what I’m wondering is:

  1. can a json be written so that it triggers both the multi zone strip triggers the white and red color and then apply the 2nd attribute of the effect (in one switch)
  2. can I control the speed of the effect - as it is now set up as 2 separate switches the speed of the move is quite fast.

any help would be great!

on a side note any chance Lifx would entertain the same functionality as nanoleaf in the “near” future so that this can all be more seamless and allow HomeKit users a much easier experience. I for one love your lights over all the others they truly have some of the best color and saturation but with all the competition on the market and just now learning that there an option that makes this way easier I have to admit it is a little tempting to try them out too.

Yes: Creating HomeKit Switches for LIFX Morph and Flame Effects. See also: Triggering LIFX firmware effects with Photons Interactor.

Hello,

I’m both a new LIFX user as well as new Homebridge user so I’m likely doing something wrong but I’m trying to control a ‘Flicker’ effect for my LIFX A19 bulb from Homekit. I followed these instructions and see the Flicker switch tile in homekit, but when I try to turn it on it turns back off and I see this error in homebridge.

Any idea what might be causing this error?

Error code 404 means the URL you configured is wrong. What does your config.json contain?

Thanks for the quick reply! Here it is.

I recommend using the serial of your Tile/Beam/Z instead of using all so that the status is more accurate. However, that doesn’t explain why you’re getting a 404.

The URLs look ok to me, though it would be better if you cut and paste the config.json so we can check for weird hidden characters and other annoyances.

If you’re familiar with and comfortable deploying containers, using Photons is a lot more reliable and doesn’t require an internet connection or cloud service: Triggering LIFX firmware effects with Photons Interactor

Here is my config.json
No I’m not at all familiar with using Photons but I’ll try reading the material to see if I can figure it out.

{
“accessory”: “HTTP-SWITCH”,
“name”: “Tile Flicker Switch”,
“switchType”: “stateful”,
“onUrl”: {
“url”: “https://api.lifx.com/v1/lights/all/effects/flicker”,
“method”: “POST”,
“strictSSL”: true,
“body”: “{“power_on”: true}”,
“headers”: {
“Authorization”: “Bearer personal API token removed”,
“Content-Type”: “application/json”
}
},
“offUrl”: {
“url”: “https://api.lifx.com/v1/lights/all/effects/off”,
“method”: “POST”,
“strictSSL”: true,
“body”: “{“power_off”: true}”,
“headers”: {
“Authorization”: “Bearer personal API token removed”,
“Content-Type”: “application/json”
}
},
“statusUrl”: {
“url”: “https://api.lifx.com/v1/lights/all”,
“method”: “GET”,
“strictSSL”: true,
“headers”: {
“Authorization”: “Bearer personal API token removed”
}
},
“statusPattern”: ““effect”: “FLICKER””,
“debug”: true
}

I’m not sure if this is the problem or just occurred during the cut and paste, but your double-quotes are all fancy. They should be straight quotes, i.e. " not curly ones.

You’ll want to make sure that all the \ characters are maintained in each of the body fields as they were stripped from your post. That’s most likely a forum issue, but I’m pointing it out anyway just in case they got stripped before landing in your config.json:

{
    "accessory": "HTTP-SWITCH",
    "name": "Tile Flicker Switch",
    "switchType": "stateful",
    "onUrl": {
        "url": "https: //api.lifx.com/v1/lights/all/effects/flicker",
        "method": "POST",
        "strictSSL": true,
        "body": "{\"power_on\": true}",
        "headers": {
            "Authorization": "Bearer personal API token removed",
            "Content-Type": "application/json"
        }
    },
    "offUrl": {
        "url": "https: //api.lifx.com/v1/lights/all/effects/off",
        "method": "POST",
        "strictSSL": true,
        "body": "{\"power_off\": true}",
        "headers": {
            "Authorization": "Bearer personal API token removed",
            "Content-Type": "application/json"
        }
    },
    "statusUrl": {
        "url": "https: //api.lifx.com/v1/lights/all",
        "method": "GET",
        "strictSSL": true,
        "headers": {
            "Authorization": "Bearer personal API token removed"
        }
    },
    "statusPattern": "\"effect\": \"FLICKER\"",
    "debug": true
}```

Sorry I didn’t notice the changes while I cut and paste, but yes all my double-quotes are straight and all the \ characters are there as you can see in my first post when I cut & paste the image.

The 404 error wouldn’t have anything to do with the A19 bulb not being multizone would it? I noticed in line 1 of your configuration notes you reference multizone bulbs.

Ah, I totally overlooked that. You’ll need to use Photons if you want to run non-firmware effects. Only the Tile, Candle, Beam and Z strip have built-in firmware effects. The rest all rely on an app (either the LIFX smart phone app or a third-party app) to generate effects.

For completeness: only the Tile and Candle have MORPH and FLAME, while the Beam and Z have MOVE.