logo elektroda
logo elektroda
X
logo elektroda

Low-cost water heating project from photovoltaic overproduction on ESP8266 and Tasmota

Daro1003  26 5877 Cool? (+14)
📢 Listen (AI):

TL;DR

  • A low-cost ESP8266 and Tasmota project switches a water heater on when photovoltaic overproduction reaches a chosen threshold.
  • A PZEM-004T power meter sits on the inverter’s direct phase wire, and a relay on a free GPIO controls the heater.
  • The whole build should cost no more than 100 zł, even if the parts are bought on Allegro.
  • The prototype works in Tasmota, but it still lacks a finished enclosure and advanced functions.
Generated by the language model.
Over-production water heating for PV users under new billing rules.

I would like to present a low-cost project that can be done by anyone who likes electronics and happens to hold a soldering iron in their hand.
The project is designed to switch on the heater when our photovoltaic installation generates a certain power. A control problem often encountered by users of photovoltaic installations - i.e. how to heat water when it is lit.

The system I have presented is very simple to build and cheap, it does not have advanced functions like the systems you can buy for over a thousand zlotys, but I think it will certainly help.

Everything is based on a circuit:
1. ESP8266
PZEM 004-t module, which sees the flow of power with current regardless of the direction, so the final assembly is important to be on a direct wire from the inverter.
3. Free software TASMOTA which we win to the ESP8266 using e.g. NodeMCU Flasher .

The elements I used in the project are:

1. PZEM 004-t measuring module
2. ESP 8266 + board with 5V stabilizer because I just had it, but we can use wemos D1 mini or NodeMCU then we won't need USB TTL programmer but just USB cable from phone to program wemos. For those new to the subject, I would recommend buying a Wems D1 mini, it has everything you need on board for programming and operation once the tasmot is loaded.
3. a button - which will be used to put the ESP into a configuration state.
4. wires to connect the ESP8226 to the input of the PZEM 004-t Module, you can also buy the original cable with plug that fits the PZEM 004-t.
5. the female-to-female wires will also be useful if you purchase the Wemos D1mini.
6. 5V relay module
7. 5V power supply - a phone charger can be used.
8. Tasmota software and NodeMCU Flasher links above.

Components for a heater control project in a photovoltaic system. .

How to connect the module
PZEM to ESP there is a lot of this on the internet, as well as how to upload the Tasmota and its first start-up. I do not want to duplicate these instructions here, they can be found on google.
Borrowed diagram from google:
Wiring diagram of PZEM module to ESP8266 .

We connect the PZEM module to GPIO 4 and GPIO 5 GPIO 4 TX PZEM to GPIO 5 RX PZEM.
We connect the relay module to the free GPIO.
To GPIO 0 and to GND we connect the button giving GND to GPIO0 6 times puts the module into hot-spot mode while giving GND to GPIO while turning on ESP puts it into flash mode.

After loading the tasmota and the first start-up, having the ESP with the tasmota already in our local network, we move on to the module settings:

Screenshot of Tasmota configuration showing GPIO port settings. .

Such settings we save the module restarts and we have the screen:

User interface for the Tasmota system displaying voltage and power data. .

We can check if our relay is working and if we have voltage on the PZEM
Of course we connect 230V to the PEM according to the diagram above.

I for testing did it like this:

ESP8266 module with relay module and wiring. ESP8266 and PZEM 004-t modules connected to a 4-channel relay .

The picture shows a 4 channel relay module connected under two GPIOs because I was testing two rules which are designed to switch on individual relays at different powers. That is, for example, the power going through the PZEM, e.g. above 2000W turns on relay 1, the power going above 3000W turns on relay 2.

How much power we set is an individual matter.

Another key setting is the rule by which the whole system works. A rule borrowed from another forum from my colleague isom to whom I thank for his kindness.

Go to the console tab:

We specify the key rule to run.

Rule1 on Energy#Power>2000 do Power1 1 ENDON on Energy#Power<2000 do Power1 0 ENDON
.

And enabling the rule to make it work:

Rule1 on
.

In the first part of the rule:
Energy#Power> 2000 - we specify from above what power the relay should turn on.

In the second part of the rule:
Energy#Power< 2000 - we specify from below what power the transmitter should switch off.

Now checking that everything is working is enough to mount it in the switchgear.
We mount the measuring clamp on the phase conductor going directly from the inverter and take 230V from the same phase to the PZEM.
The PZEM module sees the power and current flow no matter which way it flows, so we have to mount it directly on the wire from the inverter.

The cost of the whole project should not exceed 100zł even if you buy the components on allegro.

I encourage colleagues to discuss and comment on my idea, maybe thanks to colleagues from Smart Home IoT the project will get more functions and will be extended.

I have also made a project on 3 PZEM modules which monitors the energy consumption for the house was mounted directly on the power supply of the distribution blocks for the protection on the house. The inverter has been plugged in front of the blocks that supply the house thanks to this in tasmotoa I can see the energy consumption of the house and the current power flowing from the inverter.

Relay modules and ESP8266 on a prototype board in an electrical distribution box. .

The above project has not yet gained a casing is currently a prototype but I think that the casing and implementation will already be an individual matter of each, I wanted to throw in a general idea of making such a control for water heating counting on the ideas of other more experienced users in the software Tasmota and ESP8266.

About Author
Daro1003
Daro1003 wrote 2709 posts with rating 603 , helped 295 times. Live in city Szerzyny. Been with us since 2008 year.

Comments

__Maciek__ 03 Aug 2024 12:34

Not a bad idea, but ... - It would be useful to have some kind of hysteresis ... or a timer, so that the relay doesn't click like crazy at the limit (for this, a properly located current measurement). -... [Read more]

michal.zd 04 Aug 2024 09:25

. Do I understand this correctly? There is no information about the direction of energy flow, so you used it to measure the actual power generated by the pv inverter? If so, it is simpler to read this... [Read more]

Daro1003 04 Aug 2024 10:12

This is exactly why the installation of a measuring clamp is important. A project for people like me who only use off-the-shelf software. Tell me more about how to construct your project and I will... [Read more]

michal.zd 04 Aug 2024 12:03

The program can be compiled on any Linux. The test version was run by me on a normal Debian laptop. I can upload the binaries to git as well. There are two in total, a broker and a library. For the rpi... [Read more]

Daro1003 04 Aug 2024 12:11

Yes I have one connected to the app. I also have pin 1 and 3 out for communication and pin 5 and 6 used for communication with the meter it works with. https://obrazki.elektroda.pl/8401447500_1722766619_thumb.jpg... [Read more]

michal.zd 04 Aug 2024 12:16

Which rpi do you have? Version. The current version communicates with the logger via wifi. [Read more]

Daro1003 04 Aug 2024 12:18

All on 3B+ with SSD to somehow make domoticz work stably. I also have a broker on it for integration with Tasmota, AFE or others. [Read more]

michal.zd 04 Aug 2024 12:21

Ok, and do you have mosquitto there? The mqtt server is needed to send data to domoticz. Broker - is that what you mean by mqtt? I use nodered, it's more transparent for me compared to domoticz. I think... [Read more]

Daro1003 04 Aug 2024 13:00

. I do. . Unfortunately NodeRed I have nothing about it I don't know what and how. . Apparently so, and not much can be achieved in domoticz without it, but I have no knowledge of it at all, so... [Read more]

michal.zd 04 Aug 2024 14:06

it's great, there's basically nothing you can't do on it. domoticz it doesn't even compare with nodered along with dashboard. see example view with nodered, i took a screenshot a while ago. https://obrazki.elektroda.pl/9718079000_1722769589_thumb.jpg... [Read more]

Daro1003 04 Aug 2024 14:48

Thanks for the course, I need to start first with the installation of NodeRed. How better on the same RBPi as domoticz or on another ? [Read more]

michal.zd 04 Aug 2024 17:12

If you have an ssd, two side by side will do fine. Besides, you probably have GB of ram, Do you know a bit about Linux from the terminal side? There is a program called htop that shows you the current... [Read more]

Daro1003 04 Aug 2024 19:49

@michalzd I very much appreciate your work and commitment but you approach the subject in a very advanced way. Personally, I don't really know what to do and how with your information. I approach the subject... [Read more]

michal.zd 04 Aug 2024 20:33

. rather for someone who is already familiar with Linux and not afraid of compilation. That's why I asked earlier how you feel about the Linux terminal. But the following list of steps is not complicated... [Read more]

speedy9 05 Aug 2024 10:01

Tuya makes ready-made modules that additionally detect the direction of current flow. So if someone is using the Tuya system anyway, there is no simpler or cheaper way to realise the above functionality.... [Read more]

Daro1003 05 Aug 2024 10:14

. You can insert a link I will be happy to test. [Read more]

speedy9 05 Aug 2024 10:20

Even cheaper than I wrote before: https://www.aliexpress.com/item/1005005885768083.html I am thinking of buying a similar module, but a three-phase one: https://www.aliexpress.com/item/1005006456832377.html... [Read more]

Daro1003 05 Aug 2024 10:31

I have a 3 phase build on a PZEM 004-t on each phase the power is identical rather there is no point in measuring from the inverter the power on each phase unless you want to use it to measure the power... [Read more]

speedy9 05 Aug 2024 10:46

That's why you put the measurement on the output to the grid. The direction of the current flow tells you whether you have an overproduction and send it to the grid or a shortage and take it. You can make... [Read more]

FAQ

TL;DR: For PV owners, this ~100 zł controller uses ESP8266, PZEM-004T, and a 5 V relay; as one poster put it, "anyone who likes electronics" can build it. It switches a heater from measured export power in Tasmota, but adding hysteresis or reading the inverter directly over Modbus makes control steadier and smarter. [#21178107]

Why it matters: Under net billing, self-consuming surplus PV can be more valuable than exporting it cheaply and buying energy back later.

Approach Hardware Typical cost from thread Main strength Main limit
DIY Tasmota + PZEM ESP8266, PZEM-004T, 5 V relay ≤100 zł Simple, low-cost, solder-and-configure build Needs careful clamp placement and better anti-chatter logic
Inverter data via Wi‑Fi/Modbus Raspberry Pi, logger, MQTT broker Reuses existing Pi/logger Reads richer Sofar data, including status and voltages Harder for non-Linux users
Tuya direction-sensing module Tuya meter module ~57–85 zł Cheap, ready-made, supports hysteresis/dependencies Less open and less DIY-flexible

Key insight: The most important design choice is where you measure power. If you measure on the inverter feed or grid connection correctly, you can detect actual export; if you measure in the wrong place, you control the heater from the wrong power signal.

Quick Facts

  • The starter build uses 8 parts: PZEM-004T, ESP8266 board, button, wiring, female-to-female jumpers, 5 V relay module, 5 V supply, and Tasmota flashed with NodeMCU Flasher. [#21178107]
  • The published relay rule uses a 2000 W threshold: Energy#Power>2000 turns the relay on, and Energy#Power<2000 turns it off. [#21178107]
  • The author states the full DIY controller should cost no more than 100 zł, even when buying parts on Allegro. [#21178107]
  • Reported reliability problems exist: one user saw false spikes up to 150 kW, and 4 of about 8 PZEM units failed after roughly half a year. [#21182849]
  • Thread price points for alternatives were lower than expected: a Tuya single-point module was quoted at about 57–70 zł, and a two-point version at about 66–85 zł. [#21180439]

How do I build a low-cost PV overproduction water heater controller with ESP8266, PZEM-004T, a 5V relay, and Tasmota?

Build it from an ESP8266 board, one PZEM-004T, a 5 V relay, a button, and a 5 V phone charger. 1. Flash Tasmota to a Wemos D1 mini, NodeMCU, or ESP8266 board. 2. Wire the PZEM to the ESP and the relay to a free GPIO. 3. Add a Tasmota rule that switches the relay when measured power exceeds your export threshold, such as 2000 W. The author says the complete project should stay under 100 zł and is meant for people using ready-made software, not custom firmware. [#21178107]

What GPIO connections and Tasmota module settings are needed to get a PZEM-004T and relay working on a Wemos D1 mini or NodeMCU?

Use GPIO4 and GPIO5 for the PZEM serial link, and use any free GPIO for the relay. The post states GPIO4 goes to PZEM TX, GPIO5 goes to PZEM RX, and the button goes between GPIO0 and GND. Pressing GPIO0 to GND six times enters hotspot mode, while holding GPIO0 low during power-up enters flash mode. In Tasmota, save the module settings so the PZEM and relay are assigned correctly, then verify relay switching and voltage reading before connecting the final 230 V wiring. [#21178107]

How do I write a Tasmota Rule1 command that turns a heater relay on above 2000 W and off below the threshold?

Use this Rule1 command: Rule1 on Energy#Power>2000 do Power1 1 ENDON on Energy#Power<2000 do Power1 0 ENDON. Then enable it with Rule1 on. This switches relay 1 on when measured power rises above 2000 W and turns it off when power drops below 2000 W. The thread also notes that the exact wattage is an individual setting, so you can replace 2000 with your own export threshold. [#21178107]

What is hysteresis in a PV surplus heater controller, and how can I add it in Tasmota so the relay does not chatter near the switching point?

Hysteresis is a gap between the ON and OFF thresholds that prevents rapid relay switching near one limit. Add it by using different values, not the same 2000 W point both ways. For example, turn the relay on above 2000 W and off below a lower value, or add a timer. One forum reply explicitly warned that without hysteresis or timing, the relay can "click like crazy at the limit." That makes hysteresis the first upgrade to the original rule. [#21178285]

Why does the mounting position of the PZEM measuring clamp matter when I want to detect PV export instead of total household power?

The clamp position matters because the controller reacts to whatever conductor you measure. The author says the PZEM sees power and current regardless of flow direction, so the final assembly must be on the direct wire from the inverter if you want PV-related power, not mixed household demand. Another reply adds that if you want true export, put measurement on the output to the grid, because current direction then shows whether energy is being sent out or taken in. Wrong placement gives the heater the wrong trigger signal. [#21180461]

What is net billing in the context of photovoltaic installations, and why does it change whether heating water from overproduction makes sense?

"Net billing" is a settlement model that credits exported PV energy financially rather than returning the same energy later, so the grid acts like a short-term store with pricing and timing limits. In the thread, one user says the grid works like a battery with a short holding time, giving an example of accumulating for 50 minutes and using it in the last 10. That changes the economics: if export terms are weak, using surplus for hot water can make more sense than selling low and buying back later. [#21178285]

Tasmota with PZEM-004T vs reading data directly from a Sofar inverter over Modbus or HTML — which approach is better for controlling a water heater?

Reading the inverter directly is better when you want richer and more accurate control, but Tasmota with PZEM is easier to build. The PZEM route needs only cheap hardware and a simple Tasmota rule. The Sofar route can read HTML or, better, Modbus data and expose more signals, including phase voltages and storage status. One contributor said, "The best way is to use Modbus data," because he also reacts to voltage rising above the norm. Choose PZEM for simplicity and inverter data for smarter automation. [#21179148]

How can I read Sofar HYD15KTL-3PH inverter data over Wi-Fi from the logger and send it to MQTT using a Raspberry Pi?

Use the inverter’s Wi‑Fi logger, a Raspberry Pi, and an MQTT broker such as Mosquitto. The thread describes a broker program that talks to the Sofar logger over Wi‑Fi, then publishes inverter status to MQTT every 30 seconds. The same contributor says the current version communicates with the logger over Wi‑Fi and was already used on Raspberry Pi hardware. The author of the main project confirms his HYD15KTL-3PH has a Wi‑Fi logger connected to the app, which makes this path possible without reading power through a PZEM first. [#21180001]

What files, directories, and config settings are needed to run michal.zd's pvInverterBroker and MQTT_LinuxLib on a Raspberry Pi 3B+ with Mosquitto?

You need one library, one broker binary, and one config file. Put the MQTT_LinuxLib binary in /usr/lib. Put the pvInverterBroker binary in /usr/inverter. Create a config directory in /etc/ime and place the broker config there. Then edit logger_sn, logger_addr, logger_port 8899, refresh_time 30, service_port 8898, mqtt_server, mqtt_topic ime/inverter/, and mqtt_binary_topic ime/inverterbin. The post says to monitor ime/inverter/# with mosquitto_sub and expect messages every half minute. [#21180001]

Node-RED vs Domoticz for PV automation and heater control — which is easier and more flexible on Raspberry Pi?

Node-RED is presented as more flexible and ultimately easier for complex PV logic. One contributor says it replaced Domoticz on his Raspberry Pi because Node-RED handled MQTT data, dashboard views, voltage graphs, and JavaScript control logic in one flow-based environment. He reports Node-RED used about 100 MB of RAM and under 5% CPU on his setup. Domoticz still works for simpler use, but the thread’s strongest opinion is that Node-RED is the better fit when you want transparent automation and custom heater rules. [#21179552]

What is a SmartMeter in a PV inverter setup, and what extra measurements does it provide compared with app-only inverter monitoring?

"SmartMeter" is a meter used with a PV inverter that measures grid-side energy exchange and adds import/export visibility that the basic inverter app may not show on its own. In the thread, one Huawei user says his inverter app does not show the same data as another screenshot and that such functions appear only after adding a SmartMeter. That means app-only monitoring may show inverter output, while SmartMeter data can reveal what is actually going to or from the grid. [#21180461]

How should I place measurement points in a single-phase or three-phase installation to detect true overproduction sent to the grid and switch a heater correctly?

Place the main measurement where grid exchange is visible, not only where inverter output is visible. In a single-phase system, put the measurement on the line to the grid so current direction shows export versus import. In a three-phase system, think through all phases carefully, because surplus can appear on one phase while household loads sit on another. One reply also suggests a second measurement point on the heater itself. That arrangement lets the controller see real export and the heater load, instead of reacting to incomplete phase data. [#21180461]

Why do some PZEM modules show spikes like 150 kW or fail after power outages, and what can I do to make measurements more reliable?

Some PZEM units in the thread showed unstable readings and hardware failures, especially around outages. One user reports sudden false values of 150 kW, erratic behavior during power cuts, and 4 failed units out of about 8 after half a year. To improve reliability, verify readings before using them for control, avoid trusting a single noisy sample, and add logic that filters spikes or delays switching. If you need better data quality, the thread points toward inverter-native readings over Modbus instead of relying only on low-cost external measurement. [#21182849]

What Tuya modules can detect current direction for cheaper PV surplus water-heating control, and how do they compare with a DIY ESP8266 plus PZEM setup?

The thread mentions Tuya modules that detect current direction and cost about 70 zł for a single-point version and about 85 zł for a two-point version, with later links showing about 57 zł and 66 zł. Their advantage is simplicity: they already support dependencies and hysteresis. Compared with ESP8266 plus PZEM, Tuya can be cheaper and easier if you already use the Tuya ecosystem. The DIY ESP8266 route stays more open, more hackable, and was estimated at under 100 zł for the full controller. [#21180417]

What exactly counts as 'overproduction' in this kind of PV water-heating project, and from when did contract terms become unfavorable enough that using surplus for hot water became worthwhile?

Overproduction here means PV power that is not consumed locally and is instead sent into the grid. The thread makes that explicit by saying the key value is "the power that goes into the grid" and giving 1500 W as an example threshold for switching a heater on. The discussion does not name a contract start date when terms became unfavorable; it only links the idea to the "new billing rules" and later asks that date as an open question without answering it. So the usable definition is clear, but the timeline is not provided. [#21180446]
Generated by the language model.
%}