     }
 
 #ifdef CO2_ENABLED
-     if(co2.length() > 0) {
+     if(co2.length() > 0 && co2 != "0" && co2 != "5000") {
+      // discard values where the sensor is not initialized yet
       sonoffNode.setProperty("co2").send(co2);
     }
 #endif
     
     lastSent = millis();
   }
+
+  ArduinoOTA.handle();
 }
 
 

  Homie.setSetupFunction(setupHandler).setLoopFunction(loopHandler);

  Homie.setup();
  
}

void loop() {

#define MQTT_MAX_PACKET_SIZE 400
#include <Homie.h>
#include <ArduinoOTA.h>

// comment in/out if you want to use a MH-Z14 CO2 Sensor
#define CO2_ENABLED
