 void loop() {
   esp.process();
 
-  // Only fetch new sensor data if it's been long enough since the last reading.
-  if ((unsigned long)(millis() - readingInterval) >= lastReading) {
-    // Read new data from sensors
-    readSensors();
-
-    // Respond ot sensor data
-    handleSensorReadings();
-  }
-
-  // Move the door as needed
-  doorMove();
-
-  // Update door LEDs as needed
-  doorLEDs();
-
-  // Update the LCD display
-  updateLCD();
-}
+    // Only fetch new sensor data if it's been long enough since the last reading.
+    if (lastReading == 0 ||
+        ((unsigned long)(millis() - remoteLockStart) > remoteOverride &&
+        (unsigned long)(millis() - lastReading) > readingInterval)) {
+      // Read new data from sensors
+      readSensors();
+  
+      // Respond ot sensor data
+      handleSensorReadings();
+    }
+  
+    // Move the door as needed
+    doorMove();
+  
+    // Update door LEDs as needed
+    doorLEDs();
+  
+    // Update the LCD display
+    updateLCD();
+
+}

            if (Debugging) {
              debugger.println("Door open.");
            }
            mqtt.publish(pStatus, "door|open");
          }
        }
      }

const int           nightLockEnd   =        4; // Hour (in 24hr time) to end night time lockout (4am)

// Runtime variables
unsigned long lastReading        = 0;
unsigned long lastDebounce       = 0;
unsigned long lastRTCSync        = 0;
unsigned long lastLEDBlink       = 0;
unsigned long remoteLockStart    = 0;
String        doorState          = "open"; // Values will be one of: closed, closing, open, opening
boolean       heaterState        = false;
boolean       lampState          = false;
boolean       fanState           = false;
float         tempC              = 0;
float         tempF              = 0;
int           brightness         = 0;
int           doorTopVal         = 0;
int           doorTopVal2        = 0;
int           doorTopState       = 0;
int           doorTopPrev        = 0;
int           doorBottomVal      = 0;
int           doorBottomVal2     = 0;
int           doorBottomState    = 0;
int           doorBottomPrev     = 0;

RTC_DS1307 RTC;
OneWire ds(tempSense);
LiquidCrystal lcd(lcd_4, lcd_5, lcd_6, lcd_11, lcd_12, lcd_13, lcd_14);

ESP esp(&espPort, &debugger, chpdPin);
MQTT mqtt(&esp);
boolean wifiConnected = false;

