function onAreaArm(area){
switch (area.mode) {
case 0:
// So even though we say it's armed, mode 0 is off. So we do nothing.
helper.log (controller,"Armed but now in off mode");
break;
case 1:
// This is the day mode, so we don't need to do anything.
helper.log (controller,"Armed into Day Mode");
break;
case 2:
// This is the night mode, also do nothing.
helper.log (controller,"Armed into Night Mode");
break;
case 3:
// Away mode. Now we are interested.
helper.log (controller,"Armed into Away Mode");
// We are going to see if we have temp setback configured. If so, we will perform the setback and then
// store the old values into user settings somewhere.
if (controller.unitWithName("Temp Setback").isOn == true){
// OK, the Temp Setback flag is on, so we need to set back temps
helper.log(controller,"Temp Setback is enabled");
// Read the current cool setpoints
helper.log(controller,"Current raw cool setpoint is "+controller.thermostatWithNumber(1).coolSetpoint);
helper.log(controller,"Current descriptive cool setpoint is "+controller.thermostatWithNumber(1).coolSetpointDescription);
currentCoolTemp = convertHAITempToF(controller.thermostatWithNumber(1).coolSetpoint);
// Store the cool setpoint on the panel with a user setting
helper.log(controller,"Settting the Cool Setting on the panel to "+currentCoolTemp);
controller.userSettingWithName("Cool Setting").setValue(currentCoolTemp);
// Read the current heat setpoints
helper.log(controller,"Current raw heat setpoint is "+controller.thermostatWithNumber(1).heatSetpoint);
helper.log(controller,"Current descriptive heat setpoint is "+controller.thermostatWithNumber(1).heatSetpointDescription);
currentHeatTemp = convertHAITempToF(controller.thermostatWithNumber(1).heatSetpoint);
// Store the heat setpoint on the panel with a user setting
helper.log(controller,"Settting the Heat Setting on the panel to "+currentHeatTemp);
controller.userSettingWithName("Heat Setting").setValue(currentHeatTemp);
// Read the current thermostat mode
helper.log(controller,"Current HVAC mode is "+controller.thermostatWithNumber(1).mode);
// Store the mode on the panel with a user setting
helper.log(controller,"Settting the HVAC Mode on the panel to "+controller.thermostatWithNumber(1).mode);
controller.userSettingWithName("HVAC Mode").setValue(controller.thermostatWithNumber(1).mode);
// All right... we have snagged all of the thermostat information. Now let's perform setbacks.
// If there is a dog at home we won't want to turn the system off entirely, just bring up the temps.
if (controller.unitWithName("Dog in House").isOn == true){
helper.log(controller,"Showing armed away with a dog at home");
// Just set the cool to 80 degrees, which is the HAI native temp of 134
helper.log(controller,"Setting thermostat cool setpoint to 80 degrees");
controller.thermostatWithNumber(1).setCoolSetpoint(80);
// Just set the heat to 50 degrees, which is the HAI native temp of 100
helper.log(controller,"Setting thermostat heat setpoint to 50 degrees");
controller.thermostatWithNumber(1).setHeatSetpoint(50);
// Set the thermostat to automatic
helper.log(controller,"Setting thermostat to automatic mode");
controller.thermostatWithNumber(1).setMode(3);
// Now set the flag so that we know we mucked with the temps
controller.unitWithName("Temp Adjust").on();
}
if (controller.unitWithName("Dog in House").isOn == false) {
// OK so there isn't a dog at home, so we can just turn off the HVAC.
helper.log(controller,"Showing armed away and no dog at home.");
helper.log(controller,"Turning off HVAC");
controller.thermostatWithNumber(1).setMode(0);
// Don't forget to set the adjusted flag
controller.unitWithName("Temp Adjust").on();
}
}
if (controller.unitWithName("Temp Setback").isOn == false){
// The Temp Setback flag is not on, so we won't mess with the temps
helper.log(controller,"Temp Setback is NOT enabled.");
}
break;
case 4:
// Vacation mode. What is this anyway?
helper.log (controller,"Armed into Vacation Mode");
break;
case 5:
// Day Instant Mode
helper.log (controller,"Armed into Day Instant Mode");
break;
case 6:
// Night delayed mode
helper.log (controller,"Armed into Night Delayed Mode");
break;
}
}
function onAreaDisarm(area) {
// OK, so now the alarm is disarmed.
if (controller.unitWithName("Temp Adjust").isOn == true) {
// OK, so we adjusted the temps when we armed the alarm.
helper.log(controller,"Showing alarm disarmed, and temps were adjusted");
// Let's pull the stored temps, restore them to the thermostat
helper.log(controller,"Resetting cool setpoint to "+convertHAITempToF(controller.userSettingWithName("Cool Setting").value));
controller.thermostatWithNumber(1).setCoolSetpoint(convertHAITempToF(controller.userSettingWithName("Cool Setting").value));
helper.log(controller,"Resetting heat setpoint to "+convertHAITempToF(controller.userSettingWithName("Heat Setting").value));
controller.thermostatWithNumber(1).setHeatSetpoint(convertHAITempToF(controller.userSettingWithName("Heat Setting").value));
// Now set the existing operating mode
helper.log(controller,"Resetting HVAC mode to "+controller.userSettingWithName("HVAC Mode").value);
controller.thermostatWithNumber(1).setMode(controller.userSettingWithName("HVAC Mode").value);
// Last, clear the flag that shows we adjusted things
helper.log(controller,"Clearing Temp Adjust flag");
controller.unitWithName("Temp Adjust").off();
}
if (controller.unitWithName("Temp Adjust").isOn == false) {
// Alarm is disarmed, but we didn't adjust temps when we left.
helper.log(controller,"Temps were not adjusted when originally armed");
// clear the flag just to be sure
controller.unitWithName("Temp Adjust").off();
}
}
function convertHAITempToF(temperature) {
// This function takes the funky HAI temperature format and turns it into something useful.
// First thing to do is get it into degrees celsius.
tempInC = Math.round((-40)+(temperature*.5));
helper.log(controller,"The Convert Routine thinks that the temperature in C is "+tempInC);
// Then convert that to Farenheit.
tempInF = Math.round((tempInC*1.8)+32);
helper.log(controller,"The Convert Routine thinks that the temperature in F is "+tempInF);
// Write the result back to the funcion
return tempInF;
}