HomeGenie Forum
Automation Program Plugins and Wizard Scripting => Help => Topic started by: mvdarend on December 14, 2015, 11:37:57 AM
-
Is there some way to have a global function in HG?
What I'm trying to achieve is to get the correct light values depending on the time of day, currently I'm doing this as follows:
// standard theme is Relax
var command = ".1997,.8346,.8";
var solarAltitude = Modules.WithName("jkUtils - Solar Altitude").Get();
// Get Evening GoldenHour start
DateTime EveningGoldenHourStart = DateTime.Parse(solarAltitude.Parameter("jkUtils.SolarAltitude.Evening.GoldenHour.Start").Value);
DateTime EveningSunsetEnd = DateTime.Parse(solarAltitude.Parameter("jkUtils.SolarAltitude.Evening.Sunset.End").Value);
if (DateTime.Now.Hour == 6)
{
// Energize theme
command = "0.52635,.9133,.8";
}
else if (DateTime.Now.Hour >= 7 && DateTime.Now < EveningGoldenHourStart)
{
// Concentrate theme
command = "0.51649,.1732,.8";
}
else if (DateTime.Now >= EveningGoldenHourStart && DateTime.Now < EveningSunsetEnd)
{
// Reading theme
command = ".23393,.4763,.8";
}
Modules.WithName("Dining table light").Command("Control.ColorHsb").Set(command);
The problem is that I'm using this code for every single light (they're linked to seperate Z-Wave wall switches), what I'd prefer is to move the 'Get correct theme' code to a central location and just use something like this:
var command = HomeGenie.GetCurrentLightTheme();
Modules.WithName("Dining table light").Command("Control.ColorHsb").Set(command);
-
I could save the correct values in a global parameter, which I can get when needed.
Settings.Parameter("CurrentHSB").Value = ".1997,.8346,.8";
I can then set the correct values at set times of the day (Sunset, Sunrise, GoldenHour etc.) but then I still have one question. How can you make a program run at HomeGenie startup?
-
The right way would be having a webservice api method to call.
Then you can probably query the value using something like this:
var currentHsb = Modules.WithName("My Program").Command("Variables.CurrentHsb").GetValue();
If you want your value to be persistent (eg. exists even after a restart, use Program.Store to store it).
http://genielabs.github.io/HomeGenie/api/ape/a00009.html#a111c3e247c9a22cf44e032bfb568f876 (http://genielabs.github.io/HomeGenie/api/ape/a00009.html#a111c3e247c9a22cf44e032bfb568f876)
http://genielabs.github.io/HomeGenie/api/ape/a00014.html (http://genielabs.github.io/HomeGenie/api/ape/a00014.html)
To run a program when HG starts use this:
http://genielabs.github.io/HomeGenie/api/ape/a00001.html#afcf0d379d8dd2da00c2adf1c3c9996f3 (http://genielabs.github.io/HomeGenie/api/ape/a00001.html#afcf0d379d8dd2da00c2adf1c3c9996f3)
Cheers,
g.
-
That's great, thanks Gene.