By Bartłomiej Szabłowski
Table of contents

Introduction

I recently hired a company to install 5.4kWp solar panels on my roof, and with my family's average annual energy usage being about 4MWh, it seemed like a good fit. Once the inverter was hooked up to the grid and powered on, I dove into the Modbus documentation. After some tinkering, I built a Prometheus exporter and hooked it up to the Grafana dashboard on my home server.

What happens with unused PV energy in Poland

In Poland, the "net-billing" system works like this: every day, a new set of hourly prices is released, and any unused solar power is sold at that rate at the end of each hour. The money you earn can then be used to offset your evening energy consumption. Unfortunately, these prices have been steadily dropping over the past few years and months.

This is hourly energy balance, visualised in Grafana.

Cost of gas vs selling energy to the grid

I crunched the numbers and found that heating water with my Junkers gas heater costs about 0.455 PLN per 1kWh of energy. Meanwhile, the hourly prices for selling solar power rarely come close to that amount. On really sunny days, the prices can even drop to zero or go negative. So why should I give away my valuable energy for almost nothing when I can use it to heat water for my family in the evening instead?

Hydraulic automation and schematic

That's when I started planning and came up with this hydraulic schematic:

The switching zone valve is managed by a common W1209 thermostat, with the sensor attached to the hot water output pipe of the electric boiler. I’ve set the minimum temperature to 41.5°C, so when it drops below that, it automatically switches to the gas heater. It’d be a waste to lose all that leftover heat from the boiler, which is where the thermostatic mixing valve comes in. The lukewarm water gets routed into the gas heater’s "cold water" input, letting it use up the remaining energy and burn less gas.

Installing the Shelly 3EM energy meter

To make the most of the energy in each hourly cycle, I need to track how much power the other appliances in my home are using. That's where the Shelly 3EM, a three-phase energy meter, comes in handy. Here are a few pics from my installation, it took me around 20 minutes to install it.

After WiFi configuration was finished I get this beautiful JSON:

Boiler control algorithm

Now that I can see the hourly energy balance and know the power consumption of the boiler (1.5kW @ 230V), along with the rest of my home's usage, I came up with an idea. At the start of each hour, I monitor the energy balance for about 2 minutes and calculate the average rate of change per second. With that data, I can predict the balance for the rest of the hour, both with and without the boiler running. If the projected balance is less than -150Wh (including a margin), then the boiler can kick in. The margin decreases as the hour progresses since the risk of drawing from the grid drops. What's cool about this is I can run the 1.5kW boiler even if my solar panels aren't generating enough power, as long as the hourly balance has enough stored energy to cover it for some time.

💡
Boiler's power usage will depend on the current grid voltage, since: 230V^2/ 1.5kW = 35.27Ω

How that looks in action:

The controller is written in Golang, runs on my home server and it constantly monitors my home's power usage and PV production. Thanks to this I'm able to save around 120 PLN (30 EUR) monthly (when PV production is good) - not to mention that I'm not burning any gas in the summer, saving precious CO2 emissions!

Photo of the installation in real life

Thanks for reading!