more G-Labs products

Author Topic: Hue light parameters  (Read 3419 times)

April 20, 2014, 08:33:16 AM
Read 3419 times

mvdarend

  • *****
  • Information
  • Hero Member
  • Posts: 431
Hi there all, new here, and HomeGenie is my first try at home automation. After buying a set of Hue lights I got bitten by the Home automation bug and decided on HomeGenie. My Raspberry Pi with Razberry is on its way, so as I wait I am playing around with HomeGenie on my PC (Windows)

There are two things I really want from HomeGenie with the Hue Bulbs, but I'm having trouble getting them to work, basically I want variations on a 'Sunrise' effect.

1: Setting the color from C# code:
I can't work out how to set the color from C# code, I've found Command("Control.COLORHSB") but I don't know how to implement it : So I recorded a Macro and set a color for the lamp, it gave the following:

COLORHSB 0.01215686274509949,0.04979724608205468,0.7814937442928166

I tried converting that to this, but it's not doing anything (there's also not feedback from HomeGenie when I run the script):

Code: [Select]
Modules.WithName("Hallway").Command("Control.COLORHSB").Set("0.01215686274509949,0.04979724608205468,0.7814937442928166");
(Modules.WithName("Hallway").On() works, so I know the light is 'listening')

2: Setting a transition time
In the Philips Hue API there is a variable transitiontime, I have added an instruction in the following way:

+ Add Instruction -> Philips Hue -> 4 (Hallway) -> Control On

In the Command Arguments box I was hoping that I could do something as follows, but this doesn't work:

{"transitiontime":100} (I've also tried different variations, without quotes, etc)

I've been able to mimic this functionality by having a loop, but it feels like I'm re-inventing the wheel, heres a crude example:

Code: [Select]
var light = Modules.WithName("Hallway");
for(int i = 0; light.Level < 100; i++)
{
  Pause(.5);
  light.Level += 1;
}

So after that long post, my question is: Is what I want possible? Am I doing it wrong or is there something else I have missed somewhere?

Thanks in advance for any help.
« Last Edit: April 20, 2014, 08:36:22 AM by mvdarend »

April 20, 2014, 11:00:57 AM
Reply #1

Gene

  • *****
  • Information
  • Administrator
  • Posts: 1472
  • Tangible is the future!
    • Yet Another Programmer
Did you try by using:

Code: [Select]
Modules.WithName("Hallway").Command("Control.ColorHsb").Set("0.01215686274509949,0.04979724608205468,0.7814937442928166");

it's case sensitive =)

For adding the transition parameter, you should change the Philips Hue Bridge program you find in the Configure->Automation->Devices and Things section.

g.

April 20, 2014, 11:26:23 AM
Reply #2

mvdarend

  • *****
  • Information
  • Hero Member
  • Posts: 431
Quote
it's case sensitive =)
Haha, thanks Gene, I am an idiot... I tried ColorHSB as wel, but not ColorHsb

Quote
For adding the transition parameter, you should change the Philips Hue Bridge program you find in the Configure->Automation->Devices and Things section
Perfect, I'm still finding may way around the system, hadn't found this yet.

Thanks for the help, and thanks for HomeGenie I'm really liking it so far. I can't wait for the Raspberry Pi to arrive.

One more question, if I export my settings from the Windows version will I be able to import them in the RPi version?

April 20, 2014, 03:01:39 PM
Reply #3

Gene

  • *****
  • Information
  • Administrator
  • Posts: 1472
  • Tangible is the future!
    • Yet Another Programmer
Yes you can restore settings from Windows to Raspberry.

Cheers,
g.

April 20, 2014, 08:13:07 PM
Reply #4

mvdarend

  • *****
  • Information
  • Hero Member
  • Posts: 431
Quote
For adding the transition parameter, you should change the Philips Hue Bridge program you find in the Configure->Automation->Devices and Things section

If anyone's interested, after playing around with some different ideas I came up with this. Probably not the most elegant of solutions, but it does exactly what I need.

I added a new switch, Control.ColorHsb.Transition. It is basically the same as Control.ColorHsb but expects one more parameter, transitiontime (in seconds)

Code: [Select]

        case "Control.ColorHsb.Transition":
        values = parameter.Split(',');
        bridgeapicall(lightnumber, "{ "on" : true" +
                          ", "hue" : " + (int)(double.Parse(values[0], System.Globalization.CultureInfo.InvariantCulture) * 65536) +
                          ", "sat" : " + (int)(double.Parse(values[1], System.Globalization.CultureInfo.InvariantCulture) * 255) +
                          ", "bri" : " + (int)(double.Parse(values[2], System.Globalization.CultureInfo.InvariantCulture) * 255) +
                          ", "transitiontime" : " + ((int)(double.Parse(values[3]) * 10)).ToString() +  "}");
            Program.RaiseEvent(module, "Status.Level", (double.Parse(values[2], System.Globalization.CultureInfo.InvariantCulture)).ToString(), "Hue Light");
            Program.RaiseEvent(module, "Status.ColorHsb", parameter, "Hue Light");
        break;
 

And here's a simple 20 second sunrise  :P
Code: [Select]
var light = Modules.WithName("Hallway");
light.Off();
// First transition to red, 5 seconds
light.Command("Control.ColorHsb.Transition").Set("0,1,.8,5");
Pause(5);
// Second transition to orange, 5 seconds
light.Command("Control.ColorHsb.Transition").Set("0.08,1,.8,5");
Pause(5);
// Last transition to bright white, 10 seconds
light.Command("Control.ColorHsb.Transition").Set("0.13,0,1,10");

After every command there needs to be a pause of the same amount of time as the transition, otherwise only the last command will be noticeable.
« Last Edit: April 20, 2014, 08:15:00 PM by mvdarend »

April 20, 2014, 08:37:41 PM
Reply #5

Gene

  • *****
  • Information
  • Administrator
  • Posts: 1472
  • Tangible is the future!
    • Yet Another Programmer
I just tried it and the effect is very cool =)
I will include this in next releases as optional parameter of the standard Control.ColorHsb command:

Code: [Select]
        case "Control.ColorHsb":
        string[] values = parameter.Split(',');
        double transition = 5;
        if (values.Length > 3) transition = ((int)(double.Parse(values[3]) * 10));
        bridgeapicall(lightnumber, "{ "on" : true" +
                        ", "hue" : " + (int)(double.Parse(values[0], System.Globalization.CultureInfo.InvariantCulture) * 65536) +
                        ", "sat" : " + (int)(double.Parse(values[1], System.Globalization.CultureInfo.InvariantCulture) * 255) +
                        ", "bri" : " + (int)(double.Parse(values[2], System.Globalization.CultureInfo.InvariantCulture) * 255) +
", "transitiontime" : " + transition.ToString() +  "}");
            Program.RaiseEvent(module, "Status.Level", (double.Parse(values[2], System.Globalization.CultureInfo.InvariantCulture)).ToString(), "Hue Light");
            Program.RaiseEvent(module, "Status.ColorHsb", parameter, "Hue Light");
        break;

This is the Javascript equivalent of your sunrise script:

Code: [Select]
var light = hg.Modules.WithName("Light 1");
light.Off();
// First transition to red, 5 seconds
light.Command("Control.ColorHsb").Set("0,1,.8,5");
hg.Pause(5);
// Second transition to orange, 5 seconds
light.Command("Control.ColorHsb").Set("0.08,1,.8,5");
hg.Pause(5);
// Last transition to bright white, 10 seconds
light.Command("Control.ColorHsb").Set("0.13,0,1,10");

Raspberry takes up to 20 seconds to save a C# program, so sometimes it's better using other languages =)

g.
« Last Edit: April 20, 2014, 08:52:48 PM by Gene »

April 20, 2014, 08:49:37 PM
Reply #6

mvdarend

  • *****
  • Information
  • Hero Member
  • Posts: 431
Quote
Raspberry takes up to 20 seconds to save a C# program, so sometimes it's better using other languages
Thanks for the tip.

April 20, 2014, 08:54:14 PM
Reply #7

Gene

  • *****
  • Information
  • Administrator
  • Posts: 1472
  • Tangible is the future!
    • Yet Another Programmer
See my previous message, I unified your code into the Control.ColorHsb.

Thanks for sharing this =)

g.

April 20, 2014, 10:51:34 PM
Reply #8

mvdarend

  • *****
  • Information
  • Hero Member
  • Posts: 431
No worries, Gene. Glad you like it and have added it to the code :)