The aim of the project

The aim of the project was to create an abstracted model of the temperature inside a house and use it to estimate and decide when heating would be required such that energy isn't wasted by having a radiator on at all times. It also outputs the electrical energy and the resulting carbon emissions of the heating. I also wanted to investigate Euler's method of approximation and understand how accurately it approximates a differential equation.

The main mathematical model used was Newton's law of cooling. This assumes that the rate at which the indoor temperature changes is proportional to the difference between the indoor and outdoor temperatures. i.e

[ \frac{dT}{dt} = -k(T - T_{\text{out}}) ]

where: T = indoor temperature Tout = outdoor temperature k = constant representing heat-loss of the building

Testing Euler's Method

Before using the model, I wanted to test Euler's method of approximation against the exact solutions of Newtons law of cooling obtained by solving the differential equation analytically. I also did this so I could better understand the method of approximation and the law of cooling as this was my first time encountering either.
The exact solution to the differential equation is as follows:

[ T(t)=T_{\text{out}}+(T_0-T_{\text{out}})e^{-kt} ]

where:
T0 = starting indoor temperature

I then approximated the same equation using Euler's method which estimates the next temperature using the rate of change. i.e

[ T_{n+1}=T_n+\frac{dT}{dt}\Delta t ]

so, for Newton's law of cooling, the equation would be:

[ T_{n+1}=T_n-k(T_n-T_{\text{out}})\Delta t ]

I implemented both equations in Python and plotted the resulting predicted temperatures on the same graph. This allowed me to visually compare the two and I was able to see that, although slight, there was a difference between the two and that Euler's method tended to under-estimate the true value. Therefore, I also calculated the error at each timestep using:

[ \text{error}=T_{\text{exact}}-T_{\text{Euler}} ]

In Python, I stored these differences in a list which gave me an estimate of how far Euler's method was from the exact solution after each hour.
Later when creating the final temperature model, I used this error as a correction to the approximation by adding the calculated Euler error to my model.

The purpose of this was to compensate for some of the numerical error caused by using the approximation with a relatively large timestep.

This experiment showed that Euler's method fails at large sizes of deltat because it assumes a constant gradient during each step. In reality, the gradient continuously changes as the indoor temperature gets closer to the outdoor temperature. Therefore, using too large steps in time causes the approximation to become less accurate. I decided to use hourly timestep for the rest of my project because other required data could be represented hourly and it made conversions convenient. However, it does introduce approximation errors which I attempted to account for later.

House Temperature data

I then moved away from the theoretical side to try and implement the models to real temperature data. Due to time constraints, I was unable to obtain real-life indoor temperatures so I was limited to using a free dataset of indoor temperature measurements from a house in Kingston upon Thames.

This data contained measurements at a resolution more frequent than hourly and because my model works with hourly steps, I converted the timestamps into normal timestamps and used pandas to resample the measurements. I then calculated the mean indoor temperature for every hour reducing the effect of random errors.

I then selected one day from the indoor dataset and obtained the outdoor temperatures for Kingston upon Thames for the same day using Open Meteo giving me corresponding indoor and outdoor temperatures.

Estimating heat-loss constant k

I did not want to simply choose an arbitrary value for k, so I attempted to estimate it from the measured house data using a simple Linear Regression model.

I started with:

[ \frac{dT}{dt}=-k(T-T_{\text{out}}) ]

But, approximating the derivative using the definition I also get that the change in temperature to be:

[ \frac{dT}{dt}\approx\frac{T_{t+1}-T_t}{\Delta t} ]

By equating the two we can obtain:

[ \frac{T_{t+1}-T_t}{\Delta t} \approx -k(T_t-T_{\text{out},t}) ]

This can be represented as a straight line of the form

[ y = mx ]

where the left-hand side of the above equation acted as my dependent variable,

[ T_t-T_{\text{out},t} ]

as my independent variable,

and -k as the gradient of the line

So, I calculated T - Tout for every hour and compared it with the observed hourly rate of change. I then used linear regression in Python as the gradient of the relationship approximates -k. This gave me one constant value of k to use in the final model.

A limitation of this method is that the heat-loss in real-life situation is affected by more than the above variables. Windspeed, ventilation and many other factors also affect indoor temperature. Therefore, the calculated k value is only an approximation.

Adding a comfort temperature

I assumed a comfort temperature of (18^\circ C) while the house was occupied and a lower minimum temperature of (14^\circ C) when it was unoccupied. This produced a different required temperature for each hour of the day.

I decided to lower the comfort temperature when the house was empty to avoid using energy to maintain the higher comfort threshold when nobody would benefit from it.

The heat system model

For every hour, I calculated what the next indoor temperature would be without heating using Euler's method i.e:

[

T_{t+1}

T_t-k(T_t-T_{\text{out},t})\Delta t ]

I then compared this value with the comfort threshold.

I also represented the state of the heating using H such that H would be equal to 1 to represent the heating being on and 0 to represent it being off.

If the predicted temperature was below the comfort threshold, the heating was switched on. Otherwise, it remained off.

I also represented the effect of heating using another parameter h. My complete temperature model was:

[

T_{t+1}

T_t-k(T_t-T_{\text{out},t})\Delta t+hH_t ]

h represents the approximate increase in indoor temperature produced by heating during one timestep. It is different from the heater's electrical power because the temperature increase produced by a heater depends on properties such as the building size and insulation. The resulting graph compares the simulated indoor temperature with the comfort threshold. The indoor temperature does not follow the threshold perfectly and does tend to overshoot it. This is a limitation of the model and a reason for it is that it only makes a heating decision once every hour.

Calculating energy use

After producing a heating schedule, I calculated the amount of electrical energy used when following this schedule. If the heater has electrical power P, this is equal to:

[ P=\frac{E}{t} ]

therefore,

[ E_t=PH_t\Delta t ]

where P is measured in kW, H represents the state of the heating (1 or 0) and delta t is measured in hours. This gives energy in kWh.

The total energy used over the day is therefore:

[

E_{\text{total}}

\sum_{t=0}^{23}PH_t\Delta t ]

Calculating carbon emissions

The final stage was to estimate the carbon emissions caused by the electrical heating. I used regional grid carbon intensity data for London because Kingston upon Thames is within the London region. The original carbon intensity data contained one value every 30 minutes, while my temperature model used hourly steps. I therefore used pandas to average the carbon intensity into hourly values again.

The emissions during a particular hour can be calculated using:

[ C=E\times I ]

where I is the grid carbon intensity for that hour.

Since

[ E_t=PH_t\Delta t ]

[ C_t=PH_t\Delta t I_t ]

and so, the total daily emissions are:

[ \boxed{

C_{\text{total}}

\sum_{t=0}^{23} PH_t\Delta t I_t } ]

Built With

Share this project:

Updates

Submission history