Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added support for entertainment api v2 (hue gradient strips) #471

Merged
merged 20 commits into from
Feb 1, 2023

Conversation

gibahjoe
Copy link
Contributor

@gibahjoe gibahjoe commented Dec 27, 2022

Summary
This PR adds support for Philips hue entertainment API version 2. Version 1 of the API does not support the gradient light strip showing multiple colors of light. In the entertainment API v2, the concept of channels was introduced. This means that a hue light could have multiple channels (e.g the gradient light strip)and a channel could have multiple lights and it's these channels that are addressed when coloring the lights. This feature can be enabled as described in the attached image.

sshot

What kind of change does this PR introduce? (check at least one)

  • Bugfix
  • Feature
  • Code style update
  • Refactor
  • Docs
  • Build-related changes
  • Other, please describe:

If changing the UI of web configuration, please provide the before/after screenshot:
Before
IMG_6875

** After **
IMG_6874

Does this PR introduce a breaking change? (check one)

  • Yes
  • No

If yes, please describe the impact and migration path for existing setups:

The PR fulfills these requirements:

To avoid wasting your time, it's best to open a feature request issue first and wait for approval before working on it.

Other information:

  • Because a hue light can have multiple channels, the Power off on black has been removed when using API v2
  • Because a hue light can have multiple channels as well as a channel having multiple lights, the color space calculation has been removed. Also, its also documented by hue that if a color out of the color space of a light is selected, it resolves it to the closest color within its color space
  • Philips hue documentation https://developers.meethue.com/develop/hue-api-v2/migration-guide-to-the-new-hue-api/

Disclaimer
This is the first time I have programmed in c++ since the days of BlackBerry 10 OS. So if there are any issues, let me know.

@gibahjoe gibahjoe marked this pull request as ready for review December 27, 2022 20:50
@awawa-dev awawa-dev added this to the v20 milestone Dec 28, 2022
@dbell669
Copy link

dbell669 commented Jan 14, 2023

Initial Tests show the V2 API working successfully, with some changes from the V1 API. When running the entertainment set up, lights no longer appear to be added to the list indiividually, appearing as quadrants.
image.

This means some extra tweaking had to be done as the light tests would light up multiple lamps/strips.

@dbell669
Copy link

As another note, it seems that the light ids no longer appear to match up to a single light. This may be because I have multiple gradient lights, but they seem to affect different zones instead of the individual lights. This makes placing light locations much more difficult.

@awawa-dev
Copy link
Owner

You can blink the particular LED to identify it using this:
obraz

@dbell669
Copy link

dbell669 commented Jan 14, 2023

That's what I've been using to try to place them the best I can. The issue I'm having is that a single light id is affecting multiple separate lights. I'd 0 will blink my play strip, my gradient floor lamp, and table lamp. As a result I can't separate each light segment into its own channel .

@awawa-dev
Copy link
Owner

awawa-dev commented Jan 14, 2023

I think for API v2 when settings the color for the lamp in the wizard, new format command should be used: httpX://ipaddress/clip/v2/resource/light/[v2-id] instead of API v1 httpX://ipaddress/api/[appkey]/lights/[v1-id]/state (it generates old behavior where the gradient strip is one lamp). And the passed json has also different format.
void LedDevicePhilipsHueV2::identify(const QJsonObject &params) in PR is rewritten so I also think it is a Philips Hue user configuration issue. @gibahjoe could you take a look?

@gibahjoe
Copy link
Contributor Author

That's what I've been using to try to place them the best I can. The issue I'm having is that a single light id is affecting multiple separate lights. I'd 0 will blink my play strip, my gradient floor lamp, and table lamp. As a result I can't separate each light segment into its own channel .

The only way that will happen is if you have multiple lights on the same channel.

Would you mind making an api call and sharing the response here? I can prepare it and send to you if you are interested.

@dbell669
Copy link

Sure, happy to help. May take me a day or two to run it but I'm more than happy to.

@gibahjoe
Copy link
Contributor Author

gibahjoe commented Jan 14, 2023

@dbell669

  • Please make the below api calls on your terminal and share the response.
  • what is the name of the entertainment area you are trying to configure?
  • You can get the ip address and the username from the configuration page for the Philips Hue
curl --location --request GET 'https://{{HUE_IP_ADDRESS}}/clip/v2/resource/entertainment_configuration' \
--header 'hue-application-key: {{HUE_USERNAME}}'
curl --location --request GET 'https://{{HUE_IP_ADDRESS}}/clip/v2/resource/entertainment' \
--header 'hue-application-key: {{HUE_USERNAME}}'

@gibahjoe
Copy link
Contributor Author

I think for API v2 when settings the color for the lamp in the wizard, new format command should be used: httpX://ipaddress/clip/v2/resource/light/[v2-id] instead of API v1 httpX://ipaddress/api/[appkey]/lights/[v1-id]/state (it generates old behavior where the gradient strip is one lamp). And the passed json has also different format.
void LedDevicePhilipsHueV2::identify(const QJsonObject &params) in PR is rewritten so I also think it is a Philips Hue user configuration issue. @gibahjoe could you take a look?

I am on it

@dbell669
Copy link

dbell669 commented Jan 14, 2023

Running the commands with https gives me

root@LGwebOSTV:~# curl --location --request GET 'https:/(IP_Address)/clip/v2/resource/entertainment_configuration' --header 'hue-application-key: (HUE_KEY)'
curl: (35) error:1408F10B:SSL routines:ssl3_get_record:wrong version number

removing https and placing http gets me

image

(Apologies for the photo. it wouldn't post the code without turning to links)

Did I do something wrong on the install?

@gibahjoe
Copy link
Contributor Author

gibahjoe commented Jan 14, 2023

HI, I have added the insecure flag to ignore ssl. see updated commands below

curl --insecure --location --request GET 'https://{{HUE_IP_ADDRESS}}/clip/v2/resource/entertainment_configuration' \
--header 'hue-application-key: {{HUE_USERNAME}}'
curl --insecure --location --request GET 'https://{{HUE_IP_ADDRESS}}/clip/v2/resource/entertainment' \
--header 'hue-application-key: {{HUE_USERNAME}}'

@dbell669
Copy link

@dbell669

  • Please make the below api calls on your terminal and share the response.
  • what is the name of the entertainment area you are trying to configure?
  • You can get the ip address and the username from the configuration page for the Philips Hue
curl --location --request GET 'https://{{HUE_IP_ADDRESS}}/clip/v2/resource/entertainment_configuration' \
--header 'hue-application-key: {{HUE_USERNAME}}'
curl --location --request GET 'https://{{HUE_IP_ADDRESS}}/clip/v2/resource/entertainment' \
--header 'hue-application-key: {{HUE_USERNAME}}'

Enertainment zone is called Game Zone. I am aslo getting the same messages with the --insecure tag.

@dbell669
Copy link

Was able to get the files. Turns out I just needed to change the port to 443 in the curl command. Entertainment zone is called Game_Zone.
hue_output_Entertainment_Configuration.txt
hue_output_Entertainment.txt

@gibahjoe
Copy link
Contributor Author

You have multiple lights in a channel. I suspect this is due to how you positioned your lights in the entertainment configuration so there is some overlap.

This means that when you click that identification button, whichever device that lights up have channels that will show the same color.

If you could send a screenshot of your game zone light placements from the hue app, that will help me confirm or disprove my hypothesis.

If I am correct about the above,
A workaround if you need full control (you don't want channels to be grouped) will be to create an entertainment area and place the lights in completely different locations where they won't overlap.

In the meantime, I will update this PR to identify channels instead of lights for v2 (only the channels will light up instead of the entire light).

@dbell669
Copy link

Screenshot_20230116-102358_Hue

Does that work?

@dbell669
Copy link

It seems I have too many lights for the placement workaround to work. Is there a way to seperate the channels back to lights in the v2 api?.

@gibahjoe
Copy link
Contributor Author

Did you try placing them very far apart even towards the couch in the image above?

Please note that this issue you are experiencing is just for initial placement. Just complete the wizard, everything should work as usual. If the placements are off, you can correct this in the "led layout" tab in HyperHDR.

Please try that and let us know the outcome.

I will update this PR so that it's just the channels (segments) of gradient strips/lamps that flash not the entire light/lamp. This should cause less confusion than flashing the entire device

@dbell669
Copy link

Yeah, I made another test entertainment area that had everything as spread out height and placement wise as I could . And it still grouped by channel and not lights, as seen by the screenshot below.
Screenshot_20230117-100158_Hue

Even with this is was still combining my gradient lamps and ceiling gradient strips

@gibahjoe
Copy link
Contributor Author

If you complete the wizard and start syncing, what behavior do you experience?

@dbell669
Copy link

Same as before unfortunately. Multiple lights light up when testing channels

@gibahjoe
Copy link
Contributor Author

@awawa-dev I just pushed up an update to the identify for v2 api. This update flashes the channels (segments) of a gradient strip for instance instead of the entire light. This should help with Identification. Please review

@dbell669 Please update to the latest push and let us know what you experience.

@gibahjoe
Copy link
Contributor Author

Will take a look.

I have pushed up adding an identify to led layout tab.

Now, this is expected to work with other led devices please take a look. I had to update the signature of some other files. I am happy to change it if you have any issues

@awawa-dev
Copy link
Owner

As far as global signals go, I don't plan any changes there just for the single API method which doesn't need to be propagated further than the single instance: just add new method to the HyperHdrInstance to set some new properties like index of the LED to blink and timeout (please use internal timers, you have direct communication from JsonAPI/API to HyperHdrInstance each running on different thread, preferably set new properties asynchronously instead of the blocking invoke) and later include them both in HyperHdrInstance ->updateResult processing which already includes similar solution for disabled LEDs.

@awawa-dev
Copy link
Owner

I think to use new identifyLed from HyperHdrInstance for that purpose.

@gibahjoe
Copy link
Contributor Author

gibahjoe commented Jan 24, 2023

This line $('#btn_wiz_save').click(); causes the wizard to close prematurely. Once I click on Identify, the wizard closes and reloads the page. Sometimes, the application recovers properly, sometimes it shows a blank page and I have to restart it. Either way, I am unable to identify from the wizard

I tested out the identify you just pushed and it works well on v2.

If I comment out the line above, I am able to identify only if I have an existing Philips hue v2 configuration and I select the same entertainment configuration (group).

I also made some adjustments to workaround the lightscount errors.

I think a combination of this and the other one that initialized the UDP connection in identify should give us a working solution.

@awawa-dev
Copy link
Owner

awawa-dev commented Jan 24, 2023

This line $('#btn_wiz_save').click(); causes the wizard to close prematurely. Once I click on Identify, the wizard closes and reloads the page. Sometimes, the application recovers properly, sometimes it shows a blank page and I have to restart it. Either way, I am unable to identify from the wizard

Thanks for the fix. This need to be investigates further in such case, cant reproduce it on my system...maybe some differences between our configurations and I tested it for API v1 (moved that part to v1 section in same function and changed caller id for the Identify) I will take a look tomorrow. Which browser do you use ?

@awawa-dev
Copy link
Owner

OK, I think I have fixed it.

@dbell669
Copy link

Any other tests needed from my end before I start tinkering with the other types of led strips?

@awawa-dev
Copy link
Owner

@dbell669 it would be great if you could test again newest version. Beside changed 'identify' button in the wizard there is also a new 'identify' button in the context menu (#379). Try both if they work fine for your setup.

@gibahjoe
Copy link
Contributor Author

I have confirmed they both work for my setup

@awawa-dev
Copy link
Owner

Yes, but @dbell669's configuration is/was more problematic and started these numerous changes in the wizard ;) It would be good to know the final result.

@dbell669
Copy link

dbell669 commented Jan 30, 2023

Ok. Just tested. It seems like the lag issues on identification are gone, and the identify button in the led layout page works well. The channels are still blending though. Is that just how the V2 API operates?

@awawa-dev
Copy link
Owner

awawa-dev commented Feb 1, 2023

Thanks @dbell669 for the feedback. @gibahjoe I refactored the code reducing shared code between 2 Philips Hue classes (finally ~550 new lines instead of ~1700 in single class, it will be easier for me in future to maintain that driver) and fixed some minor issues e.g. saving/restoring state when V2 is used. You've done a really great job 👍 I have reviewed and refactored all the code and have no plans to make any further changes on my part. I'm wondering whether to include this PR in v19 or in the next v20. I freeze v19beta2 ahead of final release, but we still have some time to test this PR. What do you think?

@gibahjoe
Copy link
Contributor Author

gibahjoe commented Feb 1, 2023

Thank you. I think releasing earlier rather than later is better so we can get feedback from a wide range of users. So, v19.

@awawa-dev awawa-dev merged commit 96617ba into awawa-dev:master Feb 1, 2023
@awawa-dev
Copy link
Owner

OK, merged into the master branch

@gotschi
Copy link

gotschi commented Feb 5, 2023

works really good for me, thanks!
is there a definitive go-to layout for the gradient? I'm seeing mismatches to the zone alignment and seem to not be able to make the top corner zones as wide as they really are.
maybe I'm doing something stupid here
https://imgur.com/a/6oRXYS1

@awawa-dev
Copy link
Owner

awawa-dev commented Feb 5, 2023

@gotschi did you try to use the context menu later in the LED layout designer to correct it later? You can resize them and change their position as you want. Usage: #379 In the wizard where you configure the hue options, the lamp position & size options are limited. I can add later few predefined lamps but I must know their size/location...beside the list is long and it's hard to find a proper element already.

@gotschi
Copy link

gotschi commented Feb 5, 2023

oh yes, changing the values in the properties menu works, I think it glitched out earlier for me
awesome! thanks

@awawa-dev
Copy link
Owner

awawa-dev commented Feb 7, 2023

@gibahjoe I post a short post on my blog for each version. May I use your photos(https://user-images.githubusercontent.com/9147147/209718749-43eb2d07-2d36-4db5-9120-86ae0ed60f06.png) in the description of the API v2 feature that you implemented in version 19?

@gibahjoe
Copy link
Contributor Author

gibahjoe commented Feb 9, 2023

@awawa-dev Yes that's fine. Sorry just saw this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants