Calculating energy
The water in the cylinder will be hotter than the water that was originially fed into it. But the water within the cylinder will not be at a constant temperature, water at the top of the cylinder will be hotter than water at the bottom of the cylinder. The temperature that the water has been raised by is a measure of the amount of energy held in the tank.
I have 6 temperature sensors attached to my hot water cylinder:
1  is placed as low on the tank as I could get
2  is placed between the solar feed inlet and outlet
3  is placed half way up the tank
4  is placed between the gas feed inlet and output
5  is placed about 30cm from the top of the tank
6  is placed next to the hot water outlet pipe on the top of the tank.
This effectively divides the cylinder into 5 zones, where the temperature of a zone is the average of the 2 sensors that bracket that zone.
As I know how far the sensors are places about I can make a rough calculation of the volume of water in each zone. This won't be exact because it doesn't take into account the volume that is displaced by the two heating coils.
The volume of my 5 zones, from the bottom up is :
1  20.5 litres
2  56.75 litres
3  72.5 litres
4  78.8 litres
5  63.1 litres
I have a further sensor on the cold water tanks in the loft, this provides my baseline temperature, the amount of energy in the tank is calculated relative to this.
As it takes one calorie of energy to raise the temperature of one litre of water by one degree celcius I can quite easily calculate the energy represented by each zone of my hot water cylinder. Adding the zone figure together will then give an approximation of the amount of energy stored in the cylinder.
Calories are converted to Joules by multiplying by 4186
Joules are converted to KiloWatt/Hours by dividing by 3600 and then dividing again by 1000.
kWH = calories/*4186/3600/1000
The volumes of each of my 5 cylinder zones are incorporated into an SQL command takes the temperature data from the database and performs the calculations, so that for each set of temperature measurements, the total energy in the cylinder is calculated.
set @vol1=20.49;
set @vol2=56.75;
set @vol3=72.5;
set @vol4=78.8;
set @vol5=63.1;
select date,
((TwixtSolar + TankBottom)/2  ColdWaterTank)*@vol5
+ ((MidTank + TwixtSolar)/2  ColdWaterTank)*@vol4
+ ((TwixtGas + MidTank)/2  ColdWaterTank)*@vol3
+ ((TopOfTank + TwixtGas)/2  ColdWaterTank)*@vol2
+ ((HotWaterOut + TopOfTank)/2  ColdWaterTank)*@vol1 AS TankEnergyCalories,
(((TwixtSolar + TankBottom)/2  ColdWaterTank)*@vol5
+ ((MidTank + TwixtSolar)/2  ColdWaterTank)*@vol4
+ ((TwixtGas + MidTank)/2  ColdWaterTank)*@vol3
+ ((TopOfTank + TwixtGas)/2  ColdWaterTank)*@vol2
+ ((HotWaterOut + TopOfTank)/2  ColdWaterTank)*@vol1)*4186 AS TankEnergyJoules,
(((TwixtSolar + TankBottom)/2  ColdWaterTank)*@vol5
+ ((MidTank + TwixtSolar)/2  ColdWaterTank)*@vol4
+ ((TwixtGas + MidTank)/2  ColdWaterTank)*@vol3
+ ((TopOfTank + TwixtGas)/2  ColdWaterTank)*@vol2
+ ((HotWaterOut + TopOfTank)/2  ColdWaterTank)*@vol1)*4186/3600/1000 AS TankEnergykWHr
from HouseTemperature where date > curdate();
When plotted, the trend of the energy data looks a little rough.
For to make this data more useful I smooth if using a simple moving average. The averaged data is then used to calculate the amount of energy that has been added to the cylinder.
The amount of energy added is calculated by looking for troughs, i.e. low points, in the smoothed data, once a trough has been found, characterised by a data point being less than the 2 data points adjacent to it, the software will look for a peak.
Here is the software I use for doing this
C code for smooth.c
Adding together the daily energy gain I can calculate the total amount of energy that has been added to the hot water cylinder by the solar panels and by the gas boiler. Since the system was since I started monitoring in early March the solar panels are adding more than the gas boiler
