     coldTesting = status;
   }
 }
+
+/*******************************************************************************
+ * Function Name  : setFan
+ * Description    : sets the status of the Fan on or off
+ * Return         : 0, or -1 if the parameter does not match on or off
+ *******************************************************************************/
+int setFan(String status)
+{
+  //update the fan status only in the case the status is on or off
+  if ( status == "on" ) {
+    fanStatus = true;
+    Particle.publish(PUSHBULLET_NOTIF, "Fan on", 60, PRIVATE);
+    return 0;
+  }
+  if ( status == "off" ) {
+    fanStatus = false;
+    Particle.publish(PUSHBULLET_NOTIF, "Fan off", 60, PRIVATE);
+    return 0;
+  }
+
+  return -1;
+}

 *******************************************************************************/
int publishTemperature( float temperature, float humidity ) {

 char currentTempChar[32];
 currentTemp = temperature;
 int currentTempDecimals = (currentTemp - (int)currentTemp) * 100;
 sprintf(currentTempChar,"%0d.%d", (int)currentTemp, currentTempDecimals);

 char currentHumidityChar[32];
 currentHumidity = humidity;
 int currentHumidityDecimals = (currentHumidity - (int)currentHumidity) * 100;
 sprintf(currentHumidityChar,"%0d.%d", (int)currentHumidity, currentHumidityDecimals);

 //publish readings into exposed variables
 currentTempString = String(currentTempChar);
 currentHumidityString = String(currentHumidityChar);

 //publish readings
 Particle.publish(APP_NAME, "Home temperature: " + currentTempString, 60, PRIVATE);
 Particle.publish(APP_NAME, "Home humidity: " + currentHumidityString, 60, PRIVATE);

 return 0;

}



********************************************************************************
*******************************************************************************/
void initEnterFunction(){
  Particle.publish(APP_NAME, "initEnterFunction", 60, PRIVATE);
  //start the timer of this cycle
  initTimer = 0;
}
void initUpdateFunction(){
  //time is up?
  if (initTimer > INIT_TIMEOUT) {
    thermostatStateMachine.transitionTo(idleState);
  }
}
void initExitFunction(){
  Particle.publish(APP_NAME, "initExitFunction", 60, PRIVATE);
}

void idleEnterFunction(){
  Particle.publish(APP_NAME, "idleEnterFunction", 60, PRIVATE);
  //turn off the fan only if fan was not set on manually with setFan(on)
  if ( fanStatus == false ) {
    myDigitalWrite(fan, LOW);
  }
  myDigitalWrite(heat, LOW);
  myDigitalWrite(cold, LOW);
}
void idleUpdateFunction(){
  //set the fan output to the fanStatus ONLY in this state of the FSM
  // since other states might need the fan on
  //set it off only if it was on and fanStatus changed to false
  if ( fanStatus == false and fanOutput == HIGH ) {
    myDigitalWrite(fan, LOW);
  }
  //set it on only if it was off and fanStatus changed to true
  if ( fanStatus == true and fanOutput == LOW ) {
    myDigitalWrite(fan, HIGH);
  }

  if ( currentTemp <= (targetTemp - margin) ) {
    Particle.publish(APP_NAME, "Starting to heat", 60, PRIVATE);
    thermostatStateMachine.transitionTo(heatingState);
  }
}
void idleExitFunction(){
  Particle.publish(APP_NAME, "idleExitFunction", 60, PRIVATE);
}

void heatingEnterFunction(){
  Particle.publish(APP_NAME, "heatingEnterFunction", 60, PRIVATE);
  Particle.publish(PUSHBULLET_NOTIF, "Heat on", 60, PRIVATE);
  myDigitalWrite(fan, HIGH);
  myDigitalWrite(heat, HIGH);
  myDigitalWrite(cold, LOW);

  //start the minimum timer of this cycle
  minimumOnTimer = 0;
}
void heatingUpdateFunction(){
  //is minimum time up?
