Sunday, June 10, 2018

Wrapping Up The Water Heater Monitor (and control)

For the present, I'm going to claim that (as the British say) the water heater monitor is, "All done and dusted." There's a few tiny items I'll mention that I may do in the future to make is a little easier for other folk to understand, but it does what I set out to do with it.

It monitors the temperature at the top and bottom of the tank, the power usage of the entire system and controls the power applied to the internal heating element. I save the data on my house data base and can chart anything I want. It has been a cool project that I got to use new things on and implement some software that I haven't dealt with yet.

To measure the temperature I made a couple of sensors out of discrete 18B20 temperature sensors and installed them under the insulation against the tank at the top and bottom. No, I wasn't going to drill into the tank to install them, and I wasn't going to tap into the existing sensors that drive the tank. Tapping into the existing sensors might break them and drilling into the tank would have been a disaster. I want this thing to be capable of working if the new electronics ever fail.

Here's one of the sensors:

I thought about using one of the 18B20 sensors that are enclosed in a waterproof stainless steel enclosure, but I wanted as much sensitivity as possible and jamming the sensor up against the tank and securing it with metal tape seemed like the best way to do it.  It was a bit of a pain getting through the insulation to the tank, and the tank itself was covered with a high density insulation as well. I didn't dig into the tank coating; I just secured the sensor to the top of it. This made my reading low as compared to the temperature of the water inside, but if necessary in the future, I can correct for that by adding a little to the reading in the code.

With two sensors, the PZEM-004 power monitor, power supply and control wire for 220VAC power to the heating element, I ran into a little problem with available connectors for power ground and the sensors. After considering electrical tape, hot glue, shrink tubing and such, I just soldered some more power, ground and sensor connectors on the XBee shield I used.

Those three vertical black things are where I tap off and supply the various power and signals. I'm going to have to remember this trick in the future. It turned out to be a really convenient way to get extra connections. I even put the pull up resistor that one-wire devices need in there. You can barely see the 4.7K resistor in there between the rows of connections.

But, you ask, what did you discover after all this work? Well, I discovered how annoying working on a step stool over the top of a working solar hot water system is. Up, down, dropping things, wires too short to reach, taking it apart, putting it back together, all were inconvenient. It probably added several hours of pure frustration to the process, but all of us folk that do this around the house should be used to that ... right?

Here's a chart of actual operation that I pulled today:

In this the solar is running at around 80 watts and then reaches temperature and shuts off. The top of the tank was at 129F and the bottom at 118F for a differential of 11 degrees over the height of the tank. The actual water temperature measured at a nearby faucet was 138F, so it looks like the tank coating was keeping 9F of temperature away. To me, that's OK since I understand what is going on.

I also caught this where I turned on the dishwasher after the sun went down:

You can clearly see where I turned on the dishwasher and the cold (well tepid) water came into the bottom of the tank. Then a little later the rinse cycles of the dishwasher removed some more hot water from the tank. The temperature at the top of the tank didn't drop that much though, only down to 127F. It wasn't even enough to turn on the heating element (it was dark outside). Here's the entire chart for the same period:

Ok, it's a mess. That's because the power being used is only 3-10 watts and that auto expands to cover most of the chart. But, you can see that it isn't using 80 watts circulating the solar or over 4000 watts running the heating element, and that the grid power was available by the green line at the bottom.

That means that I ran the dishwasher a full cycle with hot water and didn't pay anything for heating the water since it was still hot from the solar cycle during the day. I've seen this several times now; the dishwasher, shower, various faucets, don't use enough to cause the heating element to turn on. Especially since the incoming water is probably close to 100F already during the day.  Hang on a minute, I'll go measure the water temperature coming into the house right now.

It was 89.6F. So, the incoming water is 90F and the solar will take it up to 138 making the differential only 48 degrees or so. It will show up as 129 on the graph due to the loss I described above, but that's a known thing. As a matter of fact, the heating element hasn't come on at all in the last 72 hours. I can't show you a graph to prove it because I've had the thing taken apart too many times. I may post an update later after a few days of operation. But, as a consolation, let's take a look at the cooling rate of the water heater:

Here is a period between cycles of the solar heat running. The bottom temperature is affected by the solar running, so it is higher than the incoming water temperature; the heat transfer coils are at the bottom. That makes the bottom temperature drop at the beginning. The top temperature  drifts down over time at a reasonable rate of about a degree every hour that decreases to less than a degree every two hours when it gets around 125F or so. This thing will keep 80 gallons of hot water all night this time of year. I'll have to wait a few months to see what it does in colder weather. If it gets too cold, the heating element will turn on and raise it back up anyway.

Which brings up a point I didn't realize until I did this. The temperature for solar heated water is 138 degrees. I set that back when I got the heater and it is controlled by a differential controller separate from all the other stuff. The electrical heater is set lower; how much lower I don't know yet. I'll experiment a bit to find out, but I suspect it's about 10 degrees or so. That's why the mains power isn't used much. The solar keeps the water above the temperature where the heating element kicks in. I don't know where that control is, but it's worth looking for at some point.

Software wise, it wasn't particularly hard to put together. I used the arduino library for one-wire sensors like I did for my room temperature sensor project. What I did was to read the sensors, then read the power, then send the data using timers. Since the water isn't changing very fast due to the nature of water and the mass of 80 gallons, I only read it every minute. I read the power every 15 seconds. The report is sent every 30 seconds right now, but that may change in the future when the new wears off the project. In the remaining CPU cycles, I watch the XBee for incoming items.

I only respond to the time signal and a command to turn on the mains power. The mains power was easy, I just picked a digital pin on the arduino and set it high to turn on the 100 amp solid state relay in the box. I watch the time for obvious reasons, I turn off the mains power at noon (soon to be 3 PM) to avoid the peak period charges. It doesn't get to turn back on until 8PM.

I used the timeAlarm library for the arduino to handle both timers and alarms. Timers control the readings and report while alarms turn the mains power on and off.

See how previous projects where I used time and various libraries are paying off? As one works with this stuff it gets easier to put things together and create something new.

It didn't work first try though. Most of it did, but the darn thing quit sending data every day at noon when it turned off the mains power to the heater. The problem turned out to be that 'on' has one less letter than 'off', and I was overflowing the buffer that I build the JSON report string in. That simple little problem took almost a day to isolate. I kept trying to blame it on the pin controlling the SSR.

There you are, the most comprehensive water heater controller I've ever seen. Probably more than I'll ever actually need.

But, exactly what I wanted.

Edit: I just put the code in Github so you can take a look if you want to.


  1. Nice!
    32ºC cold intake is hot!! :)

    Just one note, though: if your water temp is at 60ºC / 140ºF at the top (max), then it's not hot enough to kill the Legionella bacteria. The bacteria are dormant below 20°C and do not survive above 60°C, so going up to at leat 80ºc would be desirable.
    What season are you at your place? spring to summer?

    1. Summer here. And, yes the cold water is already warm when it reaches the house. That's why I'm looking at the water heater; get there before I need it badly.

      I did not know about the temp for that bacteria, but it's well water so it should be safe. Also, I don't drink it unprocessed, it goes through filters and stuff first.

      I hope I'm safe...

  2. All water heaters in France and uk are set to 60c. IIRC, there has never been a single reported case of Legionella in domestic uk hot water. For the last 8 years I have kept my tank around 40c. On a good day it might hit 55 if I have a lot of surplus PV. Rain all day today, so around 38c. As mainstream european dishwashers and washing machines are all cold fill, the only thing I do with hot water is shower, and 40c is plenty.
    Be wary of increasing your stored water above 60c as domestic appliances may not like it. Pumps in particular.

    1. I keep it down there because of scalding. I worry about the grandkids and outdoor showers.

    2. For that I have a mixturer (?) (the hot water is mixed with cold water at a preset temp - 55ºC in my case)

      About Legionella in US:

      About Legionella in UK: about 8% of studied homes have'em - probably not enought to kill, but it's so easy to prevent...

  3. Another great project and article. I've known the basics of water heaters, but now I'm going to have to look into how they sense temperature. I can understand not wanting to drill through the tank shell, but tapping into the existing sensors seems, on the surface, more satisfying. The exterior sensors will never be accurate as I'm sure their readings depend on the surrounding environment temperature and humidity.

    An alternative to using the existing (factory) sensors would to be to T-off the hot water outlet right at the water heater with 1/4 or 1/8 tubing and a solenoid to "sample" the hot water at intervals. Same for input water. Not sure how much water that would "waste" over a month or what one would do with the sampled water.

    On second thought, perhaps your method IS the best compromise.

    1. I thought about actually using the built in sensors, but there's not enough current in them to supply two things, the existing differential controller and my stuff. So, to do that I'd have to take over the control of the temperature of the water heater in code. I may do that some day, but not now.

      I kinda like having the regular stuff do the work and just keep checking on it.

  4. I don't monitor mine as much, but I thought about it. My tank is heated to 160F most every day and the electric element is on a timer to run 1 hour a night, if needed. As it's set at 130F or so, it doesn't see much use. As for monitoring the tank temp, I have a ZWave sensor that has a DS18B20 attached to it connected to the top of the tank. I can see the tank temp top and bottom on the controller, but I track it only at the top.