Blog

The thoughts, opinions, happenings, and just plain ramblings of a seemingly boring person.

Logging Solar Inverter Output with a Raspberry Pi

We've had a 3kW solar array on top of our house ever since we built it about 6 years ago.

Solar panels on our roof. Look at that perfectly competent builder person!

It came to our attention recently that one of our 12 solar panels had shattered glass (seemingly for a while), something you can even see from the latest Google Maps satellite imagery.

dodgy solar panel
Detective work; just like on CSI.

Surprisingly, when we had some guys out to replace it, it is pretty much impossible to source another panel with a similar voltage and current that wouldn't drastically affect the rest of the array. So we ended up just removing the broken panel.

It came to mind that, other than random glances at the inverter's basic LCD display, I had no idea if our solar system is performing as it should. As our inverter (a Samil Solar River SR3K3TLA1) is an old and fairly basic model, it doesn't have fancy wireless/network logging or monitoring, and pretty much only records the total output for the current day (which is reset each day), and the lifetime total output of the inverter.

The only method of external monitoring is through a serial data connection over RS485 or RS232, i.e. the good old serial port that computers have largely ditched for well over a decade.

Sensing the opportunity for a project, I googled around for some monitoring mechanisms. The most popular was having a small computer hooked up to the inverter using a serial cable, and then uploading the data to the online PVOutput service for storage and analysis.

Our inverter (blue box) with the Raspberry Pi attached (the little white box).
Our inverter (the blue box) with the Raspberry Pi attached (the little white box).

I've been waiting to have a decent use case for doing something with a Raspberry Pi, and this seemed a perfect fit: something extremely low-powered that I could stick on the wall (our inverter is inside our garage). I ordered the Raspberry Pi starter kit (which includes the official case, power supply, and SD card in addition to the Raspberry Pi 3 Model B) from Core Electronics, and it was delivered a few days later. The last piece of the pie (ha 😉 ) was a basic serial to USB cable.

For the script itself, I found a lot of references to a perl script from a forum called Solar Freaks, but the website seems to now be defunct. Luckily, some kind person had uploaded the script onto GitHub, so I promptly forked it and went to work.

I have to acknowledge this fantastic post for tips on how to use this script for a Samil inverter, as well as modifying it to run as a cron instead of a looping program. Most of the changes recommended there I have made in my own GitHub repository for the project.

You can find my fork on GitHub.

For a similar Samil inverter, the latest commit from my fork should work fine on a Raspberry Pi, although there are also config files included for some other manufacturers' inverters.

Here are the steps I needed to do to get it working:

  1. On your Raspberry Pi, install the required Perl modules (Perl should already be installed by default on Raspbian).
    1. Open the Perl CPAN module manager:
      sudo cpan
    2. Install the modules:
      install AppConfig Device::SerialPort HTTP::Request::Common LWP::UserAgent
    3. Exit CPAN to return to the bash terminal:
      exit
  2. Download the script from my GitHub repository and extract it to your Raspberry Pi home directory.
    The script assumes that it resides in /home/pi/inverter_monitor/ , but you can put it anywhere and change the paths in config.ini, inverter.pl, and runSolarStats.sh (there should only be a few mentions of the path).
  3. In pvoutput.pl, insert your own PVOuput user account details for your system ID, inverter serial number, and API key:
    my @PVOUTPUT = (
     {
      SERIAL_NUM    => "<REPLACE WITH YOUR INVERTER SERIAL NUMBER>",
      API_KEY       => "<REPLACE WITH YOUR PVOutput API KEY>",
      SYSTEM_ID     => "<REPLACE WITH YOUR PVOutput SYSTEM ID>",
     },
    );
  4. Run the script and see if it works:
    bash runSolarStats.sh
  5. Create a cron so that the script runs according to your desired schedule. I used the following which runs it every 5 minutes between 4am and 8pm:
    */5 4-19 * * * bash /home/pi/inverter_monitor/runSolarStats.sh

That should be it! You can see my system's live output data on PVOutput.org. Below is a graph of yesterday's output.

Let me know if this helps you, and feel free to fork my version of the script for your needs! 🙂

Leave a comment