A method of treating wastewater in a wastewater system; the wastewater system comprising a treatment plant comprising a treatment space and a sewer system comprising a sewer space, the treatment plant further comprising a treatment inlet for supplying wastewater to the treatment system from the sewer system; the method comprising the step of: - providing a treatment parameter by continuous measurement in the treatment plant, the treatment parameter being significant for purification of wastewater in the treatment plant, wherein the treatment parameter is selected from a group consisting of: Total-N, NH 4 -N, NH 4 -N + NO 3 -N, N 2 O, Total-P, PO 4 -P, COD (Chemical Oxygen Demand), BOD (Biochemical Oxygen Demand), TOC (Total Organic Carbon), TSS (Total Suspended Solids), MLSS (Mixed Liquor Suspended sludge), DO (Dissolved Oxygen), turbidity, OUR (Oxygen Uptake Rate), sludge blanket, settling properties, sludge composition, and combinations thereof, to thereby provide an online treatment parameter, wherein the treatment parameter is provided by a parameter structure comprising one or more measuring devices configured to measure the treatment parameter, and mathematically modelling the treatment parameter by including online measurement of the treatment parameter, whereby the mathematical model continuously receives measured data to provide a treatment parameter based on real time values, - determining an actual spare plant capacity indicating an amount of wastewater which can be supplied to the treatment space, wherein the step of determining the actual spare capacity is based on prediction of at least one of the amount of wastewater treated and the amount of wastewater supplied through the treatment inlet, and wherein the actual spare plant capacity is determined by use of a mathematical model, - determining an actual spare wastewater storage volume indicating an amount of wastewater which can be retained in the sewer space, wherein the actual spare wastewater storage volume is determined based on registration of and/or calculation of information obtained from the sewer space, and - varying the amount of wastewater supplied through the treatment inlet to the treatment plant based on the treatment parameter, the actual spare plant capacity, and the actual spare wastewater storage volume by use of a control structure for controlling fluid flow of the wastewater. - providing a treatment parameter by continuous measurement in the treatment plant, the treatment parameter being significant for purification of wastewater in the treatment plant, wherein the treatment parameter is selected from a group consisting of: Total-N, NH 4 -N, NH 4 -N + NO 3 -N, N 2 O, Total-P, PO 4 -P, COD (Chemical Oxygen Demand), BOD (Biochemical Oxygen Demand), TOC (Total Organic Carbon), TSS (Total Suspended Solids), MLSS (Mixed Liquor Suspended sludge), DO (Dissolved Oxygen), turbidity, OUR (Oxygen Uptake Rate), sludge blanket, settling properties, sludge composition, and combinations thereof, to thereby provide an online treatment parameter, wherein the treatment parameter is provided by a parameter structure comprising one or more measuring devices configured to measure the treatment parameter, and mathematically modelling the treatment parameter by including online measurement of the treatment parameter, whereby the mathematical model continuously receives measured data to provide a treatment parameter based on real time values, - determining an actual spare plant capacity indicating an amount of wastewater which can be supplied to the treatment space, wherein the step of determining the actual spare capacity is based on prediction of at least one of the amount of wastewater treated and the amount of wastewater supplied through the treatment inlet, and wherein the actual spare plant capacity is determined by use of a mathematical model, - determining an actual spare wastewater storage volume indicating an amount of wastewater which can be retained in the sewer space, wherein the actual spare wastewater storage volume is determined based on registration of and/or calculation of information obtained from the sewer space, and - varying the amount of wastewater supplied through the treatment inlet to the treatment plant based on the treatment parameter, the actual spare plant capacity, and the actual spare wastewater storage volume by use of a control structure for controlling fluid flow of the wastewater.