unsigned long lastRun = 0;
int count100ms = 0;
int countSeconds = 0;
int countMeasureInterval = 0;
int countDisplayInterval = 0;

void checkMillis() {
  if ( (millis() - lastRun) > 100 ) {
    lastRun = millis();
    every100ms();
  }
}

void every100ms() {
  if (count100ms < 10) count100ms++;
  else {
    count100ms = 0;
    everySecond();
  }

  checkSaveConfigTriggered();

}

void everySecond() {
  if (countSeconds < 60) countSeconds++;
  else {
    countSeconds = 0;
    everyMinute();
  }

  checkUseDomoticz();
  handleDisplayTimeout();
  checkValuesChanged();

  if (countMeasureInterval < measureInterval) countMeasureInterval++;
  else {
    countMeasureInterval = 0;
    measureTempHum();
    thermostat();
  }

  if (countDisplayInterval < displayInterval) countDisplayInterval++;
  else {
    countDisplayInterval = 0;
    updateDisplay();
  }


}

void everyMinute() {
  publishStatus();
  publishCurrentSensorValues();
  publishCurrentThermostatValues();
  updateDomoticzDevices();
}


