I would like to control the lights around my house according to the temperature. I live in the south of the US and when it gets close to freezing I would like to turn on Christmas lights to ward off the somewhat colder temperatures...
I wrote a new program (borrowing heavily, well exclusively, from the HG application) and, I can apply it to a specific module or modules that apply by name, I cannot figure out how to apply it to all of the modules in a group, with out their names...
PROGRAM CODE:
int onTemp = int.Parse (Program.Option("onTemp").Value);
int offTemp = int.Parse (Program.Option("offTemp").Value);
string onCondition = (Program.Option ("onCondition").Value);
// Modules.InGroup(PROGRAM_OPTIONS_STRING).OfDeviceType("Light,Dimmer,Switch").Each (mod => {
int temperature_f = int.Parse (Program.WithName("Weather Underground").Parameter("Conditions.TemperatureF").Value);
var light = Modules.WithName("Outside Front");
if (onCondition == "TRUE") {
if (temperature_f < onTemp) {
light.On();
} else if (temperature_f > offTemp) {
light.Off();
}
} else {
if (temperature_f > onTemp) {
light.On();
} else if (temperature_f < offTemp) {
light.Off();
}
}
light = Modules.WithName("Citrus Tree Lights");
if (onCondition == "TRUE") {
if (temperature_f < onTemp) {
light.On();
} else if (temperature_f > offTemp) {
light.Off();
}
} else {
if (temperature_f > onTemp) {
light.On();
} else if (temperature_f < offTemp) {
light.Off();
}
}
//});
TRIGGER CODE:
// this Setup delegate will be executed once, when program become active
Program.Setup(()=>{
// set input fields parameters
// <field_name>, <default_value>, <description>
// Program.AddOption(<field>, <defaultValue>, <description>, <type>)
Program.AddOption("offTemp", "42", "The temperature to turn off the lights.", "int");
Program.AddOption("onTemp", "38", "Temperature to turn on the lights", "int");
Program.AddOption("onCondition", "TRUE", "For instance: to keep lights from flickering TRUE if lights come 'ON' < 38 and 'OFF' > 42", "bool");
});
//
return true; // execute "Code To Run"