more G-Labs products

Author Topic: Philips Hue and Ambilight  (Read 5862 times)

October 25, 2014, 01:12:08 PM
Read 5862 times

mvdarend

  • *****
  • Information
  • Hero Member
  • Posts: 431
Are there any users with Philips Hue Lighting and an Ambilight television that would be interested in a HomeGenie App for syncing the lights with the TV?

I'm thinking of trying to make one, but I'll probably never use it myself (apart from testing)

October 26, 2014, 09:26:35 AM
Reply #1

mvdarend

  • *****
  • Information
  • Hero Member
  • Posts: 431
I decided to try it anyway, but I'm running into the following problem. The JointSpace API gives the following json reply:

Code: [Select]
{
"layer1": {
"left": {
"0": {
"r": 254,
"g": 96,
"b": 0
},
"1": {
"r": 255,
"g": 192,
"b": 114
},
"2": {
"r": 254,
"g": 205,
"b": 113
},
"3": {
"r": 132,
"g": 255,
"b": 64
}
},
"top": {

},
"right": {
"0": {
"r": 167,
"g": 255,
"b": 42
},
"1": {
"r": 137,
"g": 255,
"b": 32
},
"2": {
"r": 65,
"g": 254,
"b": 0
},
"3": {
"r": 254,
"g": 120,
"b": 0
}
},
"bottom": {

}
}
}

And I'm trying to retrieve the data as follows:

Code: [Select]
   
var ambilightData = Net.WebService(webserviceurl).GetData();
   
string leftR = ambilightData.layer1.left.0.r.ToString();

HomeGenie won't allow the integer here (won't compile), so I tried to work with indexes:

Code: [Select]
   
string leftR = ambilightData.layer1.left[0].r.ToString();

This compiles, but results in the runtime error "Accessed JObject values with invalid key value: 0. Object property name expected."

Anyone know what I'm doing wrong?



Edit: Found the problem, by querying the data as follows it works

Code: [Select]
string leftR = ambilightData["layer1"]["left"]["0"]["r"];
string leftG = ambilightData["layer1"]["left"]["0"]["g"];
string leftB = ambilightData["layer1"]["left"]["0"]["b"];
« Last Edit: October 26, 2014, 07:59:28 PM by mvdarend »

October 28, 2014, 10:40:21 AM
Reply #2

mvdarend

  • *****
  • Information
  • Hero Member
  • Posts: 431
OK, I've managed to get it to control my Fibaro RGBW LED strip, but I'm having trouble finding an elegant way to convert RGB to HSB for the Hue Lights in C#.

It can be done via the System.Drawing namespace, but that's not included in HomeGenie at the moment. Does anyone know another way?

October 28, 2014, 07:09:49 PM
Reply #3

dani

  • *****
  • Information
  • Global Moderator
  • Posts: 535
For Fibaro RGBW, you have the module Fibaro RGBW that I wrote. Then you can look at the source code of the fictive Node, to know how to code RGB. We don't need HSB value.

Cheers
Dani
« Last Edit: October 28, 2014, 07:12:17 PM by dani »

October 28, 2014, 07:25:00 PM
Reply #4

mvdarend

  • *****
  • Information
  • Hero Member
  • Posts: 431
Hi Dani, Thanks for your reply.

Unfortunately, the Philips Hue lights expect HSB values. Controlling your Fibaro RGBW module was the easy part, as I didn't have to convert anything :)

October 29, 2014, 08:09:50 PM
Reply #5

dani

  • *****
  • Information
  • Global Moderator
  • Posts: 535
Yes, that's right.

Cheers
Dani

October 29, 2014, 08:10:43 PM
Reply #6

dani

  • *****
  • Information
  • Global Moderator
  • Posts: 535
Yes, that's right.

Cheers
Dani

October 30, 2014, 09:14:58 PM
Reply #7

mvdarend

  • *****
  • Information
  • Hero Member
  • Posts: 431
Philips Hue also accepts an XY value, after a bit of searching I found a way to convert RGB to XY here:
http://stackoverflow.com/questions/22564187/rgb-to-philips-hue-hsb

Using that code, and the following added to the Philips Hue Bridge App. I managed to get it working (sort of)
Code: [Select]
       
case "Control.ColorXY":
    bridgeapicall(lightnumber, "{ "on" : true" +
              ", "xy" : [" + parameter.ToString() + "], "transitiontime" : 3}");
        Program.RaiseEvent(module, "Status.ColorXY", parameter.ToString(), "Hue Light");
        break;

Unfortunately the colours don't match half the time which basically makes it useless :)

Back to the drawing board....
« Last Edit: October 30, 2014, 09:38:08 PM by mvdarend »

January 26, 2015, 05:13:09 PM
Reply #8

RogerCox

  • *
  • Information
  • Newbie
  • Posts: 2
I use Hambisync to synchronize my hue lights and my ambilight tv from my windows mediacenter. Since it's written in java it could perhaps be integrated or called from Homegenie?

I would be very interested if it could!

January 27, 2015, 08:27:48 AM
Reply #9

mvdarend

  • *****
  • Information
  • Hero Member
  • Posts: 431
HI Roger,

I use Hambisync too, which is how I got the idea to try it for HomeGenie.

The test code I have works fine with reading the values from the television and then controlling, say, an RGB lamp (I tested it with a RGB led strip)

But I'm having trouble converting the RGB values from the TV to HSB or XY values for the Philips Hue lights. Maybe I'm missing something really simple, but as no-one showed any interest in getting this to work I haven't really put much effort into it.


January 27, 2015, 08:39:03 AM
Reply #10

Gene

  • *****
  • Information
  • Administrator
  • Posts: 1472
  • Tangible is the future!
    • Yet Another Programmer

January 27, 2015, 09:23:01 AM
Reply #11

mvdarend

  • *****
  • Information
  • Hero Member
  • Posts: 431
Thanks Gene, unfortunately I cannot find the correct namespaces for Rgb and Hsv.

I've found a lot of good examples implementing the System.Drawing.Color class, which I can get to work in a simple Visual Studio Test project, but I can't get them to work in Mono. (I'm assuming it's a Mono thing, please correct me if I'm wrong.)


January 27, 2015, 10:00:47 AM
Reply #12

Gene

  • *****
  • Information
  • Administrator
  • Posts: 1472
  • Tangible is the future!
    • Yet Another Programmer
System.Drawing works with mono, but it's not allowed in HG by design.
You can still use code from the link by just adapting it.
Rgb and Hsv are most likely struct/classes, so what you will have to do is replacing them with standard variables.
Eg. Rgb.Green will just become rgbGreen in your code, and so on.

g.

January 27, 2015, 09:21:23 PM
Reply #13

RogerCox

  • *
  • Information
  • Newbie
  • Posts: 2
I for one think it would be great if this function could be fully integrated into HG and I'm very much interested!

But before this is a reality, is it possible to simply run the hambisync.jar file from HG? It runs fine on my bananapro when I start it manually, I just need a way to start and stop it from within HG.

Or is this a very newbie thing to ask?



January 28, 2015, 08:08:14 AM
Reply #14

mvdarend

  • *****
  • Information
  • Hero Member
  • Posts: 431
You can still use code from the link by just adapting it.
Rgb and Hsv are most likely struct/classes, so what you will have to do is replacing them with standard variables.
Eg. Rgb.Green will just become rgbGreen in your code, and so on.
You're right, I was so fixed on trying to find the correct namespaces each time, that I completely forgot to see if the code was easily modifiable.

I'll give it a shot, thanks.

Quote
But before this is a reality, is it possible to simply run the hambisync.jar file from HG? It runs fine on my bananapro when I start it manually, I just need a way to start and stop it from within HG.
I think this is possible, but I'm not sure how to go about it.