derjayjay / homebridge-keylights

Yet another Homebridge plugin for Elgato Key Light and Key Light Air. https://homebridge.io
MIT License
45 stars 4 forks source link

Add homekit adaptive lighting support #68

Open albertvisuals opened 3 years ago

albertvisuals commented 3 years ago

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!

derjayjay commented 3 years ago

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.

albertvisuals commented 3 years ago

Great :) Thanks for the fast answer!

mariusstrom commented 3 years ago

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

derjayjay commented 3 years ago

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 :)

porcherie commented 3 years ago

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!

nLamprok commented 2 years ago

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).

derjayjay commented 2 years ago

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.

nLamprok commented 2 years ago

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.

derjayjay commented 2 years ago

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 🙂

nLamprok commented 2 years ago

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.

derjayjay commented 2 years ago

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

AngryMooses commented 2 years ago

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?

derjayjay commented 2 years ago

@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.

nLamprok commented 2 years ago

/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"
        }
    }
}
AngryMooses commented 2 years ago

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.

derjayjay commented 2 years ago

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.