You have posted unformatted code so it’s difficult for others to detect syntax errors because all formatting is missing.
What I can see is that the last line of the Template Sensor is missing outer quotes and, in the calculation, fails to convert the sensor’s state value from a string to a number. It should be like this: