 
     pirOnOff = digitalRead(PIR_IN_PIN);
 
-    if (DEBUG_PRINT) {
-      Serial.println("PIRp called");
-    }
-
     pir_Mills = millis();
   }
 }
 
 void tvOnTimer()
 {
-  long time_o_tvOnTime = o_tvOnTime * 1000 * 60 ;
+  //long time_o_tvOnTime = ( long(o_tvOnTime) * 1000 ) * 60 ;
+  long time_o_tvOnTime = ( o_tvOnTime * 1000 ) * 60 ;
   tvIsOnEvent = t.after(time_o_tvOnTime , doTvOffTimer);
+
+  if (DEBUG_PRINT) {
+    Serial.println(time_o_tvOnTime);
+    Serial.println("tvOnTimer called");
+  }
 }
 
 
 void doTvOffTimer()
 {
-  lcd.setCursor(15, 0);
-  lcd.write(6);
+  if (DEBUG_PRINT) {
+    Serial.println("doTvOffTimer called");
+  }
+  t.stop(tvIsOnEvent);
   irSendTvOutbytimer(0);
 }
 
 //
 void doTvControlbyPir(int onoff)
 {
-  // if ( o_wrkMode == 1 && o_startMode == 1 ) {
-  switch (onoff) {
-    case 1:
-      lcd.setCursor(15, 0);
-      lcd.print(" ");
-      irSendTvOutbypir(1);
-      break;
-    case 0:
-      lcd.setCursor(15, 0);
-      lcd.write(6);
-      irSendTvOutbypir(0);
-      break;
-  }
-  // }
+  if ( o_wrkMode == 1 && o_startMode == 1 && tvPowerStatus == 1) {
+    switch (onoff) {
+      case 1:
+        lcd.setCursor(15, 0);
+        lcd.print(" ");
+        irSendTvOutbypir(0);
+        break;
+      case 0:
+        lcd.setCursor(15, 0);
+        lcd.write(6);
+        irSendTvOutbypir(1);
+        break;
+    }
+  }
   r = !r;
 }
 

        break;
      case 0xFF9867: // remote off
        if ( timerStatus == 1 ) {
        } else {
          tvOnTimer();
          temp_Mills = millis();
        }
        timerStatus = ! timerStatus;
        r = !r;
        break;
      case 0x20DF10EF: // tv remote on/off
        if ( tvPowerStatus == 1 ) {
          timerStatus = 0;
        } else {
          timerStatus = 1;
          tvOnTimer();
          temp_Mills = millis();
        }
        tvPowerStatus = ! tvPowerStatus;
        r = !r;

{
  tempCinside = getdalastemp();
  displayTemperature(tempCinside);
  displaytimeleft();
}

// update every 5 mins
