         if(isOn == MODE_OFF)
         {
           // assume current air conditioning is OFF
-          // temperature priority
-          if((float) currentTemp >= (float) TEMP_HIGH)
+          // heat index (temperature) priority
+          if((float) curHeatIndex >= (float) HEAT_INDEX_HIGH)
           {
             resend = 0;
             resend_attempts = 1;

unsigned int teim = timeElapsed / (long) 60000;
qmoteCmd = "ATBN=0x0A,\"";      // using click combination code 0x0A
qmoteCmd += isOn;
qmoteCmd += teim;
qmoteCmd += currentRhInt;
qmoteCmd += ",";
qmoteCmd += currentTemp;
qmoteCmd += ",";
qmoteCmd += currentHeatIndex;
qmoteCmd += "\"\r\n";
portOne.write(qmoteCmd.c_str());
delay(3000);

      // Calculate Heat Index
      float curHeatIndex = heatIndex((double) currentTemp, (double) currentRh);
      
      // the following conditions will ignore the ON-OFF timer
      if(
         (((float) curHeatIndex) >= ((float) HEAT_INDEX_TOO_HIGH)) ||                                       // heat index too high
         (((float) currentTemp) <= ((float) TEMP_TOO_LOW)) ||                                               // temperature too low
         (isOn == MODE_COOLING && ((float) currentTemp) < ((float) TEMP_LOW) && currentRh > RH_LOW) ||      // cooling -> dehumidifier
         (isOn == MODE_DEHUMIDIFIER &&                                                                      // dehumidifier -> cooling
          ((((float) currentTemp) > ((float) TEMP_LOW) && currentRh < RH_LOW) ||
           ((float) curHeatIndex >= (float) HEAT_INDEX_HIGH)))
        )
      {
        // ambient condition exceeds the limit, skip the KEEP_ONOFF_TIMER
        timeElapsed = (long) KEEP_ONOFF_TIMER * (long) 60000;
      }

      // once the air conditioning mode is switched, keep the state for a certain amount of time
