   esp.process();
   // 5 second pause on initial startup to let devices settle, wifi connect, etc.
   if (millis() > 5000) {
-    if (lastReading == 0) {
-      // Send default values at initial startup to ensure 
-      // states are in sync at other end of MQTT connection.
+    if (lastPublish == 0) {
+      // Send default values to ensure states are in sync at other end of MQTT connection
       mqtt.publish("coop/status", "fan|off", 2, 0);
       mqtt.publish("coop/status", "light|off", 2, 0);
       mqtt.publish("coop/status", "water heater|off", 2, 0);
-    }
-    // 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();
-
+      if (digitalRead(doorBottom == 0)) {
+        doorState = "closed";
+        mqtt.publish("coop/status", "door|closed", 2, 0);
+      }
+      else if (digitalRead(doorTop == 0)) {
+        doorState = "open";
+        mqtt.publish("coop/status", "door|open", 2, 0);
+      }
+    }
+
+    // Read new data from sensors
+    readSensors();
+   
+    if (remoteLockStart == 0 || 
+        (unsigned long)(millis() - remoteLockStart) > remoteOverride) {
       // Respond ot sensor data
       handleSensorReadings();
     }
-
+    
+    // Only publish new sensor data if it's been long enough since the last reading.
+    if (lastPublish == 0 || (unsigned long)(millis() - lastPublish) > publishInterval) {  
+      if (wifiConnected) {
+        publishReadings();
+      }
+      lastPublish = millis();
+    }
+  
     // Move the door as needed
     doorMove();
-
+  
     // Update door LEDs as needed
     doorLEDs();
 

  }
  esp.wifiCb.attach(&wifiCb);
  esp.wifiConnect(wHost, wPass);

  lcdWrite("Initializing...", "WIFI Connecting");

  /**
   * Setup pin modes

  // Fetch temp and convert to farenheit
  tempC = getTemp();
  tempF = ((tempC * 9.0) / 5.0) + 32;
  // Occasionally get false readings, lets try to prevent that....
  while (tempF > 140) {
    tempC = getTemp();
    tempF = ((tempC * 9.0) / 5.0) + 32;
  }

  if (lastLightRead == 0 || (unsigned long)millis() - lastLightRead > lightReadRate) {
    // Read light sensor and convert to brightness percentage
    brightness = analogRead(lightSense);
    brightness = map(brightness, 0, 1023, 0, 100);  // Remap value to a 0-100 scale
    brightness = constrain(brightness, 0, 100);     // constrain value to 0-100 scale
    lastLightRead = millis();
  }

  // Adjust lcd brightness based on light level
  if (brightness <= 10) {
    analogWrite(lcd_15, 25);
  }
  else if (brightness > 10 && brightness <= 20) {
    analogWrite(lcd_15, 50);
  }
  else if (brightness > 20 && brightness <= 30) {
    analogWrite(lcd_15, 75);
  }
  else if (brightness > 30 && brightness <= 40) {
    analogWrite(lcd_15, 100);
  }
  else if (brightness > 40 && brightness <= 50) {
    analogWrite(lcd_15, 125);
  }
  else if (brightness > 50 && brightness <= 60) {
    analogWrite(lcd_15, 150);
  }
  else if (brightness > 60 && brightness <= 70) {
    analogWrite(lcd_15, 175);
  }
  else if (brightness > 70 && brightness <= 80) {
    analogWrite(lcd_15, 200);
  }
  else if (brightness > 80 && brightness <= 90) {
    analogWrite(lcd_15, 225);
  }
  else {
    analogWrite(lcd_15, 250);
  }
}

/**
