Sunday, 20 April 2014

How to upload data from Growatt inverter to pvoutput.org using a Raspberry Pi.

Uploading data from your solar inverter to a site like pvoutput.org can have have the benefit of letting you monitor your power output from anywhere, comparing data with other systems around the world from various other vendors or just simply to keep track.


I have prepared a walk-through on how to use a Raspberry Pi to upload your Growatt inverter data together with weather data to pvoutput.org. More technical skilled people might find this guide too detailed - they are welcome to grab the goodies at the end or ignore the whole thing :-)

Background


I have 2 Growatt 3000 inverters (this setup probably also work with any other Growatt or Sungold inverter) and 6000kW panels.

I did initially setup an old Windows XP PC with 2 COM ports - running PVBeancounter which ran fine for a couple of months - it nagged me having a full PC running a XP license stuffed with a .Net framework - only to get my inverter data uploaded. So having a Raspberry Pi laying around I did plan to use that instead at a point in time - when I got the time to look into it. I was being stupid enough to promise to help someone else with a similar setup (to keep the pressure on myself) - a very patient guy indeed :-)

I did make a small Object Pascal console program to get the data from the inverter at that time - not using the mod-bus protocol - but then got busy elsewhere.

When I finally came around to look at the setup again - I did a quick search, and found out that once again if you wait long enough - someone else has found a solution to help you scratch your itch. Credit should go to Andrew Elwell for his initial explorations and Kuhlmeier|Sisand - who has a walk-through of his setup and also has some other interesting projects.

Since our setups are not identical and I wanted things a bit different - I have done my own setup guide trying to target people who don't really have that much Raspberry Pi or Linux experience. But they should at least have a PC with Windows and be able to use it.

Ingredients needed

  • 1 Raspberry Pi Model B
  • 1 SD card (4 GB or more) - preferable Class 10
  • 1 microUSB power adapter
  • 1 USB-RS232 adapter with the number of RS232 ports that equals your number of inverters. If you have more than 1 inverter you might additional need an extension RS232 cable. Do not buy these too cheap - cables with PL2303 chips seems ok.
  • 1 USB WiFi adapter or Ethernet cable
  • 1 USB keyboard and mouse
  • 1 USB hub (if you easily need to setup the WiFi adapter up on an encrypted network)
  • 1 SD card reader (you might have one in your laptop)
  • Monitor/TV with hdmi or composite video, along with cable.
The ingredients list might look a bit too "detailed" - but some people only have laptops or tablets. If you do have the possibility of cabled networking at your inverter(s) and do not want/need WiFi - leave out the USB hub and mouse.

Setup steps

Part 1 - In front of the telly.
  1. Download the Operating System image file for your Raspberry Pi here: http://downloads.raspberrypi.org/raspbian_latest
  2. Follow the guide to write the image to the SD card shown here.
  3. Register your solar system at pvoutput.org and get your API key located at the bottom of the settings page, also remember to enabled the API access just above the key. Write down your systems id.
  4. If you want weather and temperature data along with your solar data, register at openweathermap.org and get your API key. Use Google map or something else to find your longitude and latitude, if you want near correct weather data :-)
  5. While the SD card is still in your computer, create a new file named pvoutput.txt using notepad on the SD card with the following content (replace the content between the < > with your values:
    1. # Register at pvoutput.org to get your SYSTEMID and APIKEY
        SYSTEMID=<Your 5-digit pvoutput.org systems id>
          APIKEY=<Your long API key from pvoutput.org>
            # Numbers of inverters
              Inverters=<The number of inverters you have, 1 or 2>
                # Register at openweather.org to get your APIKEY
                  # If OWMKEY and Longitude and Latitude is not supplied
                    # no weather will be read, and tried uploaded to 
                      # pvoutput.org - together with your energy data.
                        OWMKEY=<Your openweather.org API key>
                          Latitude=<Latitude of your panels location>
                            Longitude=<Longitude of your panels location>
                          1. Also copy the Python code to the SD card - you can download it from here.
                          2. Insert the SD card, keyboard/mouse/hub, network cable/adapter, monitor into your Raspberry Pi and add power  to it on.
                          3. At the "login as" prompt, log in as pi and password is raspberry - you might want to change that later.
                          4. Run sudo raspi-config to enable SSH (option 8-A4) - you might also want to setup timezone and keyboard (option 4), and use the whole SD card (option 1) - then finish.
                          5. If you need a WiFi adapter to be setup - a easy way is to use the graphical wifi-manager - so run startx and run the wifi-manager, entering the password for your network. Logout afterwards.
                          6. Write down the IP-address of your Raspberry Pi - run ifconfig and look for the inet addr for eth0 (or wlan0 if WiFi).
                          7. Back at the prompt power off the Raspberry Pi by entering the command: sudo poweroff - you should never just cut the power - it might corrupt the data on your SD card.
                          Part 2 - Finishing the setup remotely.
                          1. Now remove the keyboard/mouse/hub from the Raspberry Pi, and insert the USB-RS232 cable.
                          2. Power on the Raspberry Pi again - and download a terminal program like PuTTY, so that you can access your Raspberry Pi remotely.
                          3. Start PuTTY and enter the IP-address of the Raspberry Pi, select SSH and Open - and accept the SSH host key message. Log in as previously.
                          4. Now check if the USB-RS232 is detected by the Raspberry Pi - run lsusb - and you should something similar to below - the key here is that you have Serial Port(s) listed:
                          5. Now we want to update the OS and install the needed packages - by running the following commands:
                            1. sudo apt-get update
                              sudo apt-get upgrade
                              sudo apt-get install build-essential
                              sudo apt-get install python-dev
                              sudo apt-get install python-setuptools
                              sudo easy_install pip
                              sudo pip install pyowm
                              sudo pip install configobj
                              sudo pip install pymodbus
                            2. Copy the Python code to the home of the pi user - run sudo cp /boot/pvout_upload.py /home/pi/pvout_upload.py.
                            3. Provided that you have the Raspberry Pi connected to the inverter(s) and the sun is shining :-), you can test if everything is setup okay by running the command: python pvout_upload.py - you should then be able to see data on pvoutput.org - if all parameters where set correctly in the pvoutput.txt file.
                            4. Now you only need to setup that the program is run every 10 minutes - run crontab -e and add the following line at the end - and save and close:
                            5. */10 * * * * cd /home/pi/; python pvout_upload.py;
                            6. Done - enjoy the sun :-).

                            Additional info

                            Look through the Python code - you might want to add your own improvements, change the weather info provider or send an email with the total production of the day to yourself.

                            Also I did only used the input register values from the inverter that is needed for pvoutput.org - but for the rest of the Growatt mod-bus registers you can take a look at table 4.2 in this document.

                            I did not use the "high" values in the register pairs - since I will never generate that much power, and it just makes the code harder to read. Also notice that the "work time" are 2 ticks per second.

                            For users with inverters running firmware prior to 1.8, you need to use the serial protocol described here - since I do not think the mod-bus was available.

                            The German zentralpower inverters should be a clone of the Growatt/Sungold inverters - but I do not know if they also run the same firmware.