Because when your sensor goes into a fault condition it should report "unavailable" or "unknown", the energy dashboard knows to ignore this.
However your template sensor uses a float filter that has a default of 0. So if it can't convert the state of the watched sensor to a number it reports 0. So unavailable or unknown or none becomes 0.
This causes your energy to go from 4445 kWh to 0kWh when your watched sensor in the template goes off-line for whatever reason (including restarts). Then when the sensor comes on-line again it shoots back up to 4445 kWh. 0 to 4445 causes the energy dashboard to record that massive spike in energy use.
The availability template will return false when your template drops below 1400kWh, and this will change the template sensor state to unavailable protecting you from the massive spike in the energy dashboard when the sensor comes back on line as it will change from unavailable to 4445 kWh, and this will be ignored.
Yes but it is not trivial: