#Smart water heater controller

40 messages · Page 1 of 1 (latest)

boreal gust
#

I wanted to smarten up my geyser, because while I have solar panels and a battery, eventually the battery is full, and the sun is still shining, leaving energy going to waste. I figured that since I also have an electric geyser, I could use excess energy to heat water, which would otherwise need to come from the grid.
I had an electrician move my geyser to the AUX port of my Sunsynk 8kW inverter, but was not happy with the fine-grained controllability of this, and also needed to know what the actual temperature of the water in the geyser was, to know when to turn it on and off.

Wanting to keep a physical failsafe, but still monitor the temperature was a problem. Having pondered all sorts of ways of putting a sensor inside the thermostat, but knowing that I also didn't really want to deal with any leaks if anything went wrong, I decided to go with a commercial product. I found the Geyserwise thermostat for sale by itself at an online store (normally only available as part of a much more comprehensive, and expensive, setup). This contains an NTC thermistor, which is an analog device, meant to form part of a voltage divider. Easy enough to work with, one would think!

The geyser has a 3kW element, which at 220V means a 20A relay should do the trick. First I got a CBI Astute Smart Controller, which is rated for 30A, and reprogrammed it using the LibreTuya-ESPHome project, since it is using a RTL8710BN microcontroller. However, my electrician told me that it could not be installed near to the geyser, as it was not an isolator. I then got the CBI Astute Smart Isolator, and did the same reprogramming. I then realised that the CBI Devices were not mains isolated at their GPIO's, and that connecting the external temperature sensor would potentially be routing 220V into the inside of my geyser! Time for a new approach, using something designed to use external sensors!

boreal gust
#

The best match I could find for this was the Sonoff THR320, which has a 20A relay, and a RJ9 plug for an external sensor. And if you look at the internals, there is an actual transformer stepping down mains voltage, and isolating the ESP32 in the process. Perfect! The downside, which I only figured out later, was that the exposed GPIO on the RJ9 port was connected to GPIO25, which is in the ADC2 group. Which is not usable if WiFi is in use. I considered a few options:

  1. reroute GPIO25 to a GPIO in the ADC1 group. Problem: None of them were exposed on pins or pin headers, and the ESP32 is a VERY fine pitch package in amongst a number of other components, I don't trust my soldering enough to put a wire on the right pin!
  2. Turn off the WiFi periodically, take the reading, and turn it back on again. Problem: I wasn't sure that this would work, and I didn't want to take chances with it failing in the wrong state.
  3. Since the THR320 was designed for use with 1-wire sensors, somehow make the analog NTC thermistor appear to be a 1-wire sensor.
#

Googling for 1-wire slave implementations, I found a few, but the most promising was https://github.com/orgua/OneWireHub. This claimed to support a variety of microcontrollers, including the ATTiny85. I found a supplier with some ATTiny412's in stock, but quickly realised that the ATTiny85 and 412 are very different beasts! Fortunately, digging through my parts bin, I found that I already had some ATTiny85's! I flashed the sample code to the ATTiny, using "Arduino as ISP", and implemented a simple 1-wire sketch for the same Arduino. This resulted in a fairly roundabout test cycle:

  1. Flash ArduinoISP onto the Arduino.
  2. use the Arduino to flash the firmware onto the ATTiny85
  3. Flash the Arduino 1-wire sketch onto the Arduino
  4. goto 1

In retrospect, I should have just used two different Arduino's for the ISP and 1-wire sketch, it would have made my life a LOT easier!

boreal gust
#

Especially considering how many iterations it took me to get things working! Firstly, I had tried it on an ESP32, to "prove" that the idea could work. The Arduino was able to enumerate the various 1-wire sensors that the ESP32 was emulating.

However, when I flashed it to the ATTiny85, I got no results. I put a logic analyser on the 1-wire pin to see what was happening, but the short answer was "nothing". The master would pull the line down, but the slave (ATTiny) simply never responded. Unfortunately, the ATTiny85 is rather resouce limited, so trying to figure out what the problem could be seemed insurmountable.

Eventually, I realised that the sample sketch had a blink function on one of the other pins, so I included that in my logic analyser probe. And after an embarrassingly long time, I realised that the 0.5HZ (1 second on, 1 second off) flashing I was expecting to see was taking 16 seconds! And after some further googling, I found this note in the ATTinyCore documentation: https://github.com/SpenceKonde/ATTinyCore#when-using-an-individual-chip-for-the-first-time-or-after-changing-the-clock-speed-eesave-or-bod-settings-you-must-do-burn-bootloader-to-set-the-fuses-even-if-you-are-not-using-the-chip-with-a-bootloader

#

And so, on to the THR320! This turned into an interesting exercise as well, as it boot-looped after being flashed. The documented workaround of installing Tasmota first didn't work for me at all. What did work for some weird reason was installing it with no wifi creds, but only ap: and captive_portal:. Then, powering it from AC allowed the device to be reconfigured onto my home WiFi, and reprogrammed OTA as usual.

boreal gust
#

Given the stated goals of this installation, my end configuration looks like this.

boreal gust
#

The above are pictures of the ATTiny85 "interposer" board, that sits between the THR320 and the Geyserwise thermostat. There is a pull up resistor from the 1-wire pin to Vcc as required by the spec. (I wasn't sure whether this was included within the THR320 or not, so I added it anyway, and it works, so ...) There is also a 10k resistor between ground and the ADC pin, with the NTC thermistor connected between the ADC and Vcc, making a voltage divider.
The black wire in the 4-core is ground, the red wire (clipped off) is not connected, the greenish wire is 1-wire (GPIO25), and the yellow wire is Vcc. I was not able to find documentation on the RJ9 pinout online, so I thought I would add it here. In the second picture you can see the required orientation of the RJ9 connector for this wiring description.

And the last picture shows the connections required underneath the strip board. Basically, I used a 6x6 piece of veroboard, with the middle 4 rows split in half underneath the ATTiny85. The outer two rows formed power buses, being Vcc and ground. I made ground run adjacent to the ATTiny95's ground pin, and Vcc adjacent to the Vcc pin, so all I needed was a small jumper between the adjacent rows. The resistors ended up being wedged into the same holes as the ATTiny85's pins, so perhaps it would have been smarter to have used an 8x6-row bit of stripboard. This was just a convenient piece I had lying around, so I used it as is. It also fitted nicely into the heatshrink tubing that I had on hand.

#

One "positive" about taking the 1-wire to ADC translator approach as I did is that people with no interest in ESPHome should be able to simply use the Sonoff THR320 as-is, without reprogramming anything. Then they could use the ewelink app to manage it. Not saying I'd recommend it, as my configuration above has many local failsafes built-in, that I would be hesistant to put on the other side of a flaky internet connection. But it would be possible.

abstract rose
#

👏 Lovely write up and great solution

boreal gust
#

Thank you!

barren violet
#

Another consideration would be to use a thyristor to drive the heating element, that way you can effectively "Dim" down the element, so if you are exporting 1.6Kw then you could drive the element at say 1.5kw load. that will ensure you capture maximum energy without exporting excessively and also not importing for the element. You would need a good meter that can measure direction with a CT on your supply tail and then apply some calcs and drive an analog output. Good luck

boreal gust
#

Not sure I’m quite ready to make circuits that switch up to 3kW. But thanks for the idea.

lunar minnow
#

Amazing to have found this because I've just begun this exact project, only in my case rather than a PV system it's a simple solar heater and it's on the roof of the building. A third option for switching power is to use some middleware. Have all your data reported to a central location like home assistant and then have home assistant direct something like colorock's 30a (40a internally!) zigbee switch to do its thing. Or if you're a fan of rube goldberg and his influence on Looney Tunes (or just renting) you could do what I did and have some servo motors or a switchbot literally flicking the switch for you.

boreal gust
#

LOL. a Switchbot could do the job, but I wanted to have it at least monitoring and controlling in a single device, to avoid the geyser running wild if anything went wrong.

#

while the geyserwise thermostat does have a hard cutout at 90 C, I didn't want to take the chance of burning my family with near boiling water (or having the geyser burst from overpressure)

#

A possibly better approach for power switching would be a contactor, which can be rated for much higher currents than a simple relay

lunar minnow
#

Sounds like your hot water tanks are very different than what I'm used to in north america. Our thermostats are set to cut off around our desired temp and we've got pressure valves built in. As for relays/contactors like I said colorocks is rated for 30 and built for 40, which at 220v will get you over 6 kilowatts.

distant orchid
#

I'm still confused about the term "geyser". 🤣 (NA as well)

lunar minnow
#

Right? I feel like that's a term more descriptive of what you don't want it to do.

boreal gust
#

In general (dumb) installations, the water heater has a mechanical thermostat set to the desired temperature, and that is the end of it. But that doesn’t give you the ability to vary the desired temperature as and when needed. The thermostat I installed can be read by a controller, and varied as high as 90C by turning the power off with an external relay when it reaches the desired temperature. BUT if the external controller crashes, the thermostat will still turn it off before it starts boiling.

#

Smart water heater controller

#

And yes, our installations do also have to have over pressure relief valves, as well as drip trays plumbed to the outside to catch burst tanks.

#

Ultimately, I should probably install a heat pump, which will let me leave this element turned off, and heat the water much more efficiently. But that would cost roughly 20 times what this did, so …

lunar minnow
#

Tbh I don't think a heat pump would be worth it. Now heat pipes on the other hand. If you're somewhere sunny and have roof access an evacuated tube collector will abuse the same physics loophole and also have zero moving parts and zero electric consumption, it's an almost perfectly passive system.

boreal gust
#

Johannesburg certainly is sunny, so that would be an option.

lunar minnow
#

Ah "Sath Ifrica". Definitely look into heat pipe solar water. Even the garbage quality flat-panel types we use over here work well enough to get warm to hot water even when it's single digits outside. The vacuum tube+heat pipe systems are significantly more efficient and less dependent on sun angle. You might actually be able to tie that into your thermostat so you can switch between heating your tank and sending water to a radiator system.

boreal gust
#

LOL

#

will check it out as an alternative. That said, I think I may have maxed out my roof space with PV panels, leaving no space for water heating.

lunar minnow
#

Fair point. Do the PV panels have any kind of cooling? They get pretty hot and work better when not overheated iirc, I'm really surprised it's not more common to use their waste heat for this.

boreal gust
#

The ones I have do not have any cooling. That would certainly be a good idea. Perhaps I can heat-exchange with my swimming pool 😉

lunar minnow
#

Hey it worked for Linus

boreal gust
#

how so?

lunar minnow
#

Linus from LTT had a heat-exchange system built into his house that uses all the waste heat from his computers and servers to warm the pool, and vice versa.

boreal gust
#

ah, right

#

I mean, that's basically what a heat pump does, right? Separates heat and cold to the places that you need it

lunar minnow
#

Yes, and it has a much higher capacity and speed of action than simply pumping water around, but the difference is you need to power the compressor and pumps and run airtight refrigerant tubes between your hot and cold sides.

boreal gust
#

fair enough

lunar minnow
#

Simple fluid heat exchanges won't get you 300% efficiency like a heat pump, but they can work 100% passively depending on the setup and at most need a basic water pump. That's incomparably more accessible than needing to run pressurized copper piping around and power a complicated system.