Category Archives: Machine Learning

Preemptive Greenhouse Cooling with Machine Learning

In order to improve cooling, I added a 1/2 HP water chiller to my system.  When used with the geothermal, it cools pretty well.  This is evident by the amount of condensation I can see on the pipes and the HVAC water reservoir:

 

and the heat exchanger:

The chiller, however, is only a bit over 400W consumption.  This means at 100% efficiency, I can remove 400W of energy.  That’s not good enough.  Using pysolar I estimate I need to remove an average of 1764W of solar energy.  Combining the chiller with geothermal, however, I have so far been able to maintain sub-40C temperatures with 22% shadecloth (1375W average solar input) at up to 30C outside.  However, near the end of the day, the reservoir sensors claims the water temperature is 30C.  I think this is higher than it actually is (sensor may be polluted by outside air due to its location), but it’s warm enough that condensation stops.  Condensation represents a nice boost in cooling because it takes more energy to phase change water gas to liquid and that energy will be pulled from the ambient air.

How much energy can my reservoir absorb?

Doing the math, I can estimate how much my 151L reservoir can absorb at different starting temperatures.  If I can start my reservoir at 9C, it can absorb around 245W of energy throughout the day (15 hours until it reaches 30C).

This is more than enough even without any bonuses from condensation.  So how do I get my reservoir that cool at the beginning of the day?  One established method is to pre-cool the reservoir during the night.

Pre-cooling and saving energy

It would be relatively easy to pre-cool the reservoir at night.  I just keep the geothermal pump and HVAC pumps going at night until I reach the desired temperature.  However, if I want to maximize efficiency, I need to understand the next day’s needs.  I need to preemptively decide whether or not pre-cooling is necessary.  If it’s going to rain the following day, and solar radiation drops below 400-500W/m^2, I don’t need to pre-cool.  How do I understand my future needs so that I can be efficient in how I pre-cool?

Weather forecast is inadequate

I can easily get tomorrows estimated maximum temperature.  However, this is not adequate.  In a greenhouse, it may be 15C outside, but if there’s high solar radiation, it will easily be 30C or higher inside the greenhouse.   I cannot use predicted outside temperatures alone in my preemptive decision.  If I knew the forecast for solar radiation, I could base my preemption on that.  However, the Weather Underground (WU) forecast API, the API I’m currently using, doesn’t have solar radiation estimates/predictions.

Machine learning to predict greenhouse temperature

I can get tomorrows and historic atmospheric conditions from the WU API.  This will give me a rough idea how much solar radiation I’ll have.  I also have a couple years worth of greenhouse temperature data.  Using Tensorflow, I should be able to train a neural network linear regression model using historic weather data and data for my greenhouse and use that model to predict future temperatures using weather forecasts.

To start out with, I used 2 months worth of data.  The data retreival process was the slowest part.  With a free WU API account, I can only get 10 API calls per minute.  Once complete, I have 3700+ data points to work with.  I can expand this to more data as needed (depending on accuracy requirements).

Machine learning prediction results

Looks like my prediction results are within about 4-5C.  I selected 3 recent temperature points and associated conditions over the past week to test:

Outside Temperature: 15.1C
Condition: “Overcast”
Prediction: 18.5C
Actual: 17.9C

Outside Temperature: 17.7C
Condition: “PartlyCloudy”
Prediction: 21C
Actual: 25.8C

Outside Temperature: 27.2C
Condition: “Clear”
Prediction: 32.5C
Actual: 36.6C

This level of accuracy might be fine.  If it predicts anything over 23 (which is my typical setpoint), I’ll know I need to preemptively cool during the night.

Efficient Method of preemptive cooling

I have up to three sources of cooling at night.  The air using the HVAC heat exchanger and fans, the geothermal system, and finally the chiller.  Understanding when to use which will help me cool most efficiently.  My algorithm is roughly this:

  • Use HVAC heat exchange fans and all pumps until reservoir is within 1C of the air temperature
  • Disengage the HVAC fans (180W savings)
  • Continue using geothermal pump until water is within 1C of geothermal battery temperature (I estimate at 12C)
  • Disengage the geothermal pump (60W savings)
  • Continue using chiller pump until water reaches 4C.

Measuring success

The entire system is just about in place.  There’s a few bugs to work out with using the machine learning model and I still need to separate the pumps onto different power supplies.  I have, however, been doing well using only the forecast max temperature to decide preemption and I believe it’s been working.  To determine this objectively, I should be able to look at non-preemptive cooling minimum and maximum deltas between the indoor and outdoor temperatures.  The smaller the difference should mean better cooling.  I started preemptively cooling using the temperature method on 6-6, 2017.  I started preemptively cooling using machine learning on 6-18.  Let’s pull min/max data from may, and compare it to data between 6-6 and 6-15 (a few days before any changes for good measure).  The results look promising:

5-6 to 6-5:

  • min delta: -3.8
  • max delta: 30.0
  • mean delta: 4.0

After 6-6:

  • min delta: -1.0
  • max delta: 15.6
  • mean delta: 3.1

The max of 30 may be anomalous (ie, during a power out), but doing a mean should weed those out.  After implementing preemptive cooling, I’m getting almost 1C better temperatures.  Once I have the machine learning and other improvements made, I’ll check again and see if I see additional improvements.

UPDATE (7/18/2017):

Math about how much energy a 151kg could absorb over a day was incorrect.  Fixed math to cover 15hr period instead of merely 1hr.

Also fixed greenhouse estimated solar input.  New estimate computed with pysolar.