LIFX Developer Zone

How to create two separate switch for lifx Z zones

hello, I have a question. on a lifx Z is possible to create two or more separate switch (for example first 16 zones switch 1 and second 16 zones switch 2) and expose them to homekit?
if not it is possible with http command or other?

noone can help me?

Hello, this forum is pretty low traffic :slight_smile:

I’m not sure I understand what you mean by “switch”

I need to switch on and off the lifx Z in two separate sections

switch 1 : zone 1 to 16
switch 2: zone 17 to 32

and reproduce it in homekit.

thanks

Unfortunately homekit does not allow selection sections of a strip.

Also, you can’t turn off/on parts of the strip. You can however set the brightness to zero to make it look like sections are off.

For example, with the HTTP API, if you have the following states.json file

{
  "states": [
    { "selector": "label:strip", "power": "on" },
    { "selector": "label:strip|0-15", "brightness": 0 },
    { "selector": "label:strip|16-31", "brightness": 1 }
  ]
}
curl -XPUT https://api.lifx.co/v1/lights/states -d @states.json -HContent-Type:application/json -H"Authorization: Bearer $PROD_API_TOKEN"

but it is possible to use it with homekit? or homebridge?

unfortunately those two do not know about the LIFX HTTP API as far as I’m aware, so nope.

You could probably do it with Homebridge by using the https://www.npmjs.com/package/homebridge-http-lightbulb plugin, but you’d need to determine all the endpoint states yourself.

thanks for help but with this plugin (as I read config examples) seems not possible to call local states.json or I am wrong?

You would have to define that in the plugin configuration instead of relying on a file.

thanks for help but arab for me… if you have some instructons to share… I appreciate…

Ok, install the homebridge-http-lightbulb plugin and use the following configuration. You’ll need to change id:d073d5XXXXXX to the actual serial of your LIFX Z strip and replace <LIFX Token> with your personal access token from cloud.lifx.com.

{
	"accessory": "HTTP-LIGHTBULB",
	"name": "Partial Beam",
	"onUrl": {
		"url": "https://api.lifx.com/v1/lights/states",
		"method": "PUT",
		"headers": {
			"Content-Type": "application/json",
			"Authorization": "Bearer <LIFX_Token>"
		},
		"body": "{\"states\": [{\"selector\": \"id:d073d5XXXXXX\",\"power\": \"on\"},{\"selector\": \"id:d073d5XXXXXX|0-15\",\"brightness\": 0},{\"selector\": \"id:d073d5XXXXXX|16-31\",\"brightness\": 1}],\"defaults\": {\"duration\": 1}}"
	},
	"offUrl": {
		"url": "https://api.lifx.com/v1/lights/id:d073d5XXXXXX/state",
		"method": "PUT",
		"headers": {
			"Content-Type": "application/json",
			"Authorization": "Bearer <LIFX_Token>"
		},
		"body": "{\"power\": \"off\"}"
	},
	"statusUrl": {
		"url": "https://api.lifx.com/v1/lights/id:d073d5XXXXXX",
		"headers": {
			"Content-Type": "application/json",
			"Authorization": "Bearer <LIFX_Token>"
		},
		"statusPattern": "\"power\": \"on\""
	}
}

This virtual bulb will turn the entire strip on, but set the brightness of zones 16-31 to 0, effectively turning those zones off. You will need to adjust the "body" string to match the actual configuration you want for the strip when it turns on. When the bulb is turned off, the entire strip will turn off. And the status of the bulb should be accurately reflected in HomeKit.

Note that because this uses LIFX Cloud, expect some delays even up to 3-5 seconds before the action occurs.

I don’t know how to thank you… you lose part of you free time to help me… thanks…
if you come to italy I offer you a coffee… a good espresso that I produce…

I have to ask you a thing… when I on it for first time it is ok,
but if I switch on/off for second time


this is the result… It can be a lifx problem?

You will need to adjust the |0-15 and |16-31 values in the onUrl string to specify the actual zones you want to turn on and off. Each LIFX Z strip has 8 zones. The strip closest to the controller has zones 0-7, the next strip, 8-15, etc.

The sample config I gave you would turn the first two strips off (zones 0-15) and the second two strips on (zones 16-31).

What I should’ve asked is: how many sections are you using on your Z strip and which zones do you want to turn on and off? We will have to tweak the settings accordingly.

yes I know it… and your config is ook…

but see that zone 0-15 after first switch on that is ok… (they are off) at second time … they are not off… see the picture… zone 0-15 are up and 15-31 down… the middle is where there is the extension connected.

I didn’t do a lot of testing. :slight_smile: You may have to adjust the offUrl to actually change brightness (like the onUrl does) instead of just powering off the strip.

I think it is a problem on onUrl
if I try to use onUrl from link directly… also with curl call… the result is the same.

first onUrl is ok
then offUrl is ok
second onUrl keep zones 15 to 31 partially on…

@delfick any ideas here? I don’t know the HTTP API that well, so I’m not sure if the setStates needs to be tweaked at all.

I’m struggling to follow tbh.

Are you able to post each request with a picture an explain what you expect vs what you get?

so, first switch on is correct:

switch off is correct:

second switch on is not correct as it is with zone 0-15 partially on…