Hi there, I have written a simple javascript Trigger Code to check for cloudy conditions, basically it will look like this (code is not yet properly tested)
I would like to move the check for cloudy conditions to a function within a library somewhere, where can I best place the code for this?
// Put your trigger code logic here.
// Call 'hg.SetConditionTrue()' when you want
// the 'Code To Run' to be executed.
hg.SetConditionFalse();
// Switch on the Living Room lights
// Runs twice per day, at @Evening.GoldenHour.Start and @Evening.Sunset.Start
// At @Evening.GoldenHour.Start, check for cloudy conditions, if not cloudy (isClear = false) wait for Sunset
if (hg.Scheduler.IsScheduling("@Evening.GoldenHour.Start"))
{
// Get Weather info
var module = hg.Modules.WithName("Weather Underground").Get();
// Get the icon name from IconUrl
var iconName = module.Parameter("Conditions.IconUrl").Value.split("k/")[1];
// Create an array of 'Clear' icon names
var clearArray = ["clear.gif", "mostlysunny.gif", "partlycloudy.gif", "partlysunny.gif", "sunny.gif"];
// Check to see if the iconName is found in the array
var isClear = clearArray.indexOf(iconName) > 0;
if (isClear == false)
{
hg.SetConditionTrue();
}
}
else if (hg.Scheduler.IsScheduling("@Evening.Sunset.Start"))
{
hg.SetConditionTrue()
}