Maximize your solar to keep your home warm — Part 2

pascal boudalier
6 min readMar 18, 2023

Automatically feed all excess solar energy, and only excess, into existing electric heaters.

See Part 1

Grid status reading

The automation application needs to know the direction and intensity of the current flowing between the grid and the home, whether the current is drawn from the grid, or exported to the grid.

There are many ways to get such information:

  • install a dedicated current clamp (such as this one) around the wire connecting the home to the electricity company.
  • some consumer unit meter (provided by the electricity provider) do provide this information via an API/protocol (The French “Linky” does)
  • I decided to leverage the monitoring device which comes with my solar installation, the Enphase envoy
The Envoy offers central management/monitoring for Enphase micro-inverters
A current clamp is an easy way to measure current (intensity and direction), without any wiring disruption.

The Envoy already has a current clamp for grid monitoring so there is no need for extra hardware. Besides, it provides a local REST API allowing the automation application to interact, over my home wifi, with a server located in the envoy box itself.

This means I get real time information and do not have a dependency on any cloud system.

I am also using a dedicated current/voltage sensor (PZEM 004t) to get an idea of the power being diverted by the eddi. Even if not required for the automation logic, this is a valuable piece of information which can be used to build nice graphics/statistics.

The PZEM 004 (bottom of the picture) has its own current clamp (not shown) fitted on the output of the eddi. It connects to the Raspberry PI (top of the picture) via serial (MODBUS protocol)

Controlling heaters

Existing heaters are equipped with wifi enabled relay. I picked Shelly products, because they have a comprehensive and well documented REST API, which the python automation application can use.

The simplest setting: a Shelly plug S (rated 2500w)

Most of my existing heaters come with what is known as a “pilot wire”. This wire is designed for home automation, and allows to configure the heater in different modes, based on the 230V AC voltage applied to this pilot wire.

  • Comfort mode. Heater ON. Target temperature set on heater’s thermostat
  • Eco mode. Heater ON. Target temperature typically comfort minus 3 C
  • Anti freeze. Heater OFF, except if ambient temperature drops too low (typically below 7C)
  • Stop: heater OFF
Control the heater with 230V AC voltage on the pilot wire

A Shelly 1PM relay and a simple diode allow to set the heater in either Comfort mode or Antifreeze mode.

The diode suppresses the positive part of the AC voltage. The table above shows that this correspond to Antifreeze.

With a pilot wire, the wifi relay does not switch heater’s power (power switching is done in the heater itself). Therefore the relay does not need to have high power rating

A small box is added to existing heaters to control them via WiFi. Easy to hide behind the heaters.

Automation logic

The logic (implemented in Python on a Raspberry PI) is quite simple. It periodically monitors grid current (using the Enphase API), and based on the direction of the current (export or draw), turns heaters on or off using the Shelly API.

Which heaters to turn on first ? By popular vote, it is entirely configurable. Heaters are grouped as “primary” and “secondary” with primary heaters being switched on before secondary ones. Likewise secondary heaters will be switched off before primary devices.

It is also possible to disable automation altogether. Typically, the system would run in full automation when we are absent/happy to let the application manage the primary/secondary heaters.

Some behaviors (such as how often to check for export, how quick to react to change of grid status, ..) are also configurable.

The eddi in operation. Solar production is 3.2Kw. Home (eg oven, fridge ..) is consuming 1.7Kw. Eddi is diverting most the the excess (1.3 Kw). Export is only 100W.

Control with a smartphone

As the solar2heater application is meant to run forever and unattended, much attention is given to application management.

I used the excellent Blynk platform to build a smartphone application to manage the configuration and monitoring of the solar2heater application.

Screenshot of the smartphone application (Android)

With Blynk, no code needs to be written on the smartphone side, applications are built by assembling widgets. The Python application running on the Raspberry PI interacts with those widgets.

In the screenshot above, you can see how the power on the controlled heaters (yellow line) reasonably tracks solar production (green line), and how the grid (red line) hovers around 0.

The delta between the green and yellow lines is what the house consumes outside of the controlled heaters (fridge, etc ..)

The corresponding solar production reported by the Enphase application.

The smartphone application also provides real time access to all power meters, and to log of key events. It is pretty handy to see the automation logic in action ..

The Raspberry PI is monitored using Linux’s Monit. Monit checks the health of various system’s components (network connections, filesystems, memory, CPU, processes, etc…) and take automated actions on error.

For instance, in case the solar2heater application fails , it will automatically be restarted.

The yellow terminal display the health status of various system’s components.

As for event reporting, alarms are provided with both push notifications and emails.

Pushover for smartphone push notification, as well as Gmail integration

All this makes the system “embedded”, i.e. able to run forever, without much attention.

Multiple applications can be managed from the smartphone. solar2heater is just one of them.

Raspberry PI add-on board

I also developed the PCB (printed circuit board) for an add-on board to the Raspberry PI (i.e. it connects to the standard Raspberry Pi’s expansion header)

The PCB design is available on github

In the solar2heater application, the board is used for visual cues (display some statistics, events). It is equipped with led and a color display.

The board is designed to be quite generic, and can also host temperature sensor, current sensor, gesture sensor, light sensor, lithium battery sensor, buzzer, opto-coupler ..etc.

For now, I am only using the display as text, but when I have time, I’ll build nicer graphics ( good idea says the editor )

The PCB connects to the Raspberry PI expansion header.

The system has been working fine for several weeks now and indeed, it makes sure I use all the excess solar to help heating my house.

The orange area corresponds to the power consumed by the house.
The blue area corresponds to the solar power production
The gray area on top corresponds to the power being imported from the grid
The gray area on bottom corresponds to the power being exported to the grid

  • In the early part of the day, power consumed by the house is provided by the grid (gray and orange matches).
  • The narrow peak in the morning is heating of the water tank around 6pm (I do not need much, as the tank is already hot)
  • As solar production ramps (blue), the power is consumed by the house’s heaters (orange). You can see the effect of a cloud on both production and consumption.
  • Very little gray area on the bottom of the curve means no power exported to the grid. The heaters take it all !!!!.



pascal boudalier

Tinkering with Raspberry PI, ESP32, RiscV, Solar, LifePo4, IoT, Zigbee, energy harvesting, Python, MicroPython, Keras, Tensorflow, tflite, TPU. Ex Intel and HP