homebridge-keylights icon indicating copy to clipboard operation
homebridge-keylights copied to clipboard

Add homekit adaptive lighting support

Open albertvisuals opened this issue 4 years ago • 16 comments
trafficstars

Great Plugin! Really nice to control the lights with Apple HomeKit too. Do yo think it would be possible to add homekit adaptive lighting support for the non-streaming times?

Thanks!

albertvisuals avatar Mar 05 '21 15:03 albertvisuals

I don't want to say to much, but you may want to look forward to the next update 😉

Seriously though, yes, this is on my to-do list since homebridge 1.3 added support for adaptive lighting.

I can't make any promises on a date, but as soon as I get the time I'll implement this.

derjayjay avatar Mar 05 '21 15:03 derjayjay

Great :) Thanks for the fast answer!

albertvisuals avatar Mar 05 '21 16:03 albertvisuals

I'm willing to venmo/paypal/whatever $50 for adaptive lighting support!

mariusstrom avatar Apr 16 '21 19:04 mariusstrom

Preliminary support for adaptive lighting is available in the beta release v1.3.0-1 next

The version should be mostly stable, but there can be some issues when you change the light brightness very quickly.

I'm in the process of rewriting the plugin to also support the Elgato Light Strips, but no harm in allowing you to play around with adaptive lighting :)

derjayjay avatar Apr 21 '21 20:04 derjayjay

Preliminary support for adaptive lighting is available in the beta release v1.3.0-1 next

The version should be mostly stable, but there can be some issues when you change the light brightness very quickly.

I'm in the process of rewriting the plugin to also support the Elgato Light Strips, but no harm in allowing you to play around with adaptive lighting :)

Wow working great so far!! Amazing job!

porcherie avatar Apr 28 '21 19:04 porcherie

I'm in the process of rewriting the plugin to also support the Elgato Light Strips, but no harm in allowing you to play around with adaptive lighting :)

@derjayjay

Is there any update on this? I have the light strips and I can't find a single plugin that can work with Homebirdge. I'm willing to help in writing this but I have no clue where to start (since you're talking about a rewrite).

nLamprok avatar Nov 27 '21 11:11 nLamprok

I haven't had the time to finish working on it and since I recently moved my test setup is also not yet functional. The Light Strips have a different API, so some work is still required.

derjayjay avatar Nov 27 '21 13:11 derjayjay

I happen to have Light Strips and a homebridge instance running on my local NAS. I'll try to see if I can implement something and make a PR if possible. If you have any resources / guides it would greatly help me.

nLamprok avatar Nov 27 '21 19:11 nLamprok

Awesome, much appreciated!

You could start by installing the Elgato Control App on your computer and capture the traffic (e.g. with WireShark) when you change settings, switch the light strip on and off, etc.

That's my main issue in supporting the light strips, since they support color, the API is a bit different.

You can send me a mail if you need any more guiding 🙂

derjayjay avatar Nov 28 '21 09:11 derjayjay

I'm extremely grateful for your immediate responses. I'll try to be as helpful as possible.

So... not sure if this is the right place (maybe we should move it to an other issue) but these are some preliminary results from some captured traffic from the control app:

It seems like it polls the following while you have the app opened (tested from macOS):

HTTP GET elgato-light-strip-b6d7.local.:9123/elgato/lights

{
    "lights": [
        {
            "brightness": 30,
            "hue": 40.0,
            "on": 0,
            "saturation": 49.0,
            "temperature": 0
        }
    ],
    "numberOfLights": 1
}

HTTP GET elgato-light-strip-b6d7.local.:9123/elgato/lights/settings

{
    "colorChangeDurationMs": 150,
    "powerOnBehavior": 1,
    "powerOnBrightness": 40,
    "powerOnHue": 40.0,
    "powerOnSaturation": 15.0,
    "switchOffDurationMs": 400,
    "switchOnDurationMs": 150
}

HTTP GET elgato-light-strip-b6d7.local.:9123/elgato/accessory-info

{
    "displayName": "",
    "features": [
        "lights"
    ],
    "firmwareBuildNumber": 209,
    "firmwareVersion": "1.0.4",
    "hardwareBoardType": 70,
    "productName": "Elgato Light Strip",
    "serialNumber": "EW52J1A******"
}

Now, to the fun part, if we try to just turn it on/off it does a simple PUT request with the following payload:

HTTP PUT elgato-light-strip-b6d7.local.:9123/elgato/lights

{
    "lights": [
        { "hue": 40, "saturation": 49, "brightness": 30, "on": 1 }
     ],
    "numberOfLights": 1
}

It sends the exact same request where on is set to 0 when you try to turn it off from the app

I have mine set to just warm/cold light so I suppose the payload must be different if it's set to a colour. I'll update this with more findings as we move forward, but I don't want to pollute this thread with spam. If you'd like me to open a new investigation issue, let me know.

Off-topic: It's my first time trying to play with Homebridge from a developer's perspective so I'm not familiar yet with what it needs to implement something new. I'll take a deeper look at the source code of this plugin to understand a little bit more.

nLamprok avatar Nov 28 '21 15:11 nLamprok

Thanks for the captures. Let's create a new issue for Light Strip support.

As a starting point, you can have a look at KeyLight.ts

derjayjay avatar Dec 01 '21 13:12 derjayjay

I'm using Homebridge UI with Keylights 1.2.3, and it shows as up to date. Sorry for the basic question, but how would I force an upgrade to the latest version with Adaptive lighting support?

AngryMooses avatar Dec 31 '21 23:12 AngryMooses

@peternear You can do so easily via the web UI. Under plugins, find the keylight plugin. There should be a wrench symbol next to settings. There you have the option "Install previous version" where you can select the v1.3.0-1 with adaptive lighting support.

Please note that adaptive lighting is not perfect because the keylights do not support the full color temperature range required.

derjayjay avatar Jan 01 '22 08:01 derjayjay

/elgato/lights

Unfortunately I had no time to extend the current plugin to be compatible with Elgato Light Strips. For anyone interested in a workaround you can use: https://github.com/staromeste/homebridge-http-advanced-accessory to actually send HTTP payload to elgato light strips. A sample config for on/off controls:

{
    "accessory": "HttpAdvancedAccessory",
    "service": "Lightbulb",
    "name": "Office Lights",
    "forceRefreshDelay": 1,
    "debug": false,
    "urls": {
        "getOn": {
            "url": "http://YOUR_LOCAL_IP:9123/elgato/lights",
            "mappers": [
                {
                    "type": "jpath",
                    "parameters": {
                        "jpath": "$.lights[0].on",
                        "index": "0"
                    }
                },
                {
                    "type": "static",
                    "parameters": {
                        "mapping": {
                            "on": 1,
                            "standby": 0
                        }
                    }
                }
            ]
        },
        "setOn": {
            "httpMethod": "PUT",
            "body": "{ \"lights\": [{ \"on\": {value} }] }",
            "url": "http://YOUR_LOCAL_IP:9123/elgato/lights"
        }
    }
}

nLamprok avatar Mar 07 '22 20:03 nLamprok

An issue I've noticed is that color temperature isn't accurate with dimming. I tend to leave my lights at 20% and 5% for day to day use, and the color temperature at that dim level is wrong (much too warm). Not sure if that's an issue with the lights or the plugin, but thought I'd mention it.

In the end, I've disabled the feature for my key lights as the temperature doesn't match the rest of the lights in the room which are also using adaptive lighting.

AngryMooses avatar Apr 06 '22 14:04 AngryMooses

Thanks for your feedback :)

This is unfortunately an issue with the lights. They do not cover the whole light temperature range covered by adaptive lighting in HomeKit, so they will look wrong when compared to other lights - they are intended as studio lights after all.

derjayjay avatar Apr 06 '22 14:04 derjayjay