The management of wastewater systems constitutes a complex problem in the environmental engineering field. The variability and uncertainty of the inflows of wastewater treatment plants involve a real risk of reducing the effectiveness of the treatments and worsen the ecological state of river basins. An adequate reduction of contaminants requires an optimal combination of wastewater contributions that must constitute the treatment inflow. The problem is complex because of different dynamics and casuistics of wastewater generation, especially when the waste is from industrial activities. In addition, a realistic focus requires consideration of the temporal component due to the distances from the treatment. This paper presents a new optimization model for planning the wastewater inflow in a consistent way, with the novelty from the inclusion of this temporal component. Under the assumption of a complete knowledge of the future, the problem can be expressed as a quadratically constrained program (QCP). With growing problem size, solvers such as CONOPT have increasing difficulties to find good solutions to such problems. Therefore, we propose solving this problem as an online optimization problem in which the quadratic terms are eliminated. Our approach was applied to a virtual case study based on a high number (200) of industrial wastewater generators (located in 4 different zones) and a single wastewater treatment plant. The results obtained evidence the applicability of the model to plan favourably the operation of treatments and contribute to sustainability in the context of the internet of things.