This study introduces a temperature swing method for simultaneously producing biodiesel and ethyl levulinate through in-situ transesterification of spent coffee grounds. Effects of temperature and the amounts of catalyst and ethanol were investigated and it was found that the temperature predominantly affects the yield. Response surface methodology was employed to find the optimal conditions for maximizing biodiesel and ethyl levulinate yield. The highest biodiesel yield of 14.91 +/- 0.83 wt% was found at 140 degrees C, while the highest ethyl levulinate yield of 3.29 +/- 0.15 wt% was found at 160 degrees C. The maximum ethyl levulinate yield occurs at higher temperature than biodiesel due to decomposition of cellulose to produce ethyl levulinate, while the biodiesel yield decreases at elevated temperature due to unwanted humin formation. The proposed swing operation of the optimal temperature from 160 to 140 degrees C gives the highest yield of 15.02 wt% biodiesel and 2.76 wt% ethyl levulinate in the single-pot process.