Get GoodWe data with Powershell

I recently had a few solar panels installed over the roof of my house and right after that I thought, how can I get GoodWe data with Powershell?

Edit 20190613: GoodWe has switched over to the SEMS Portal and ever since the script stopped working. Thankfully, SEMS has an API available, have a look at this post on how to get started, it’s very simple: Get SEMS/GoodWe data with Powershell. Also, you may still be able to use the method shown in this article, if your inverter is still registered with goodwe’s old portal. In my case it started working right after I logged on to http://eu.goodwe-power.com (but I kept https://www.goodwe-power.com/.. in the $url). I also tested by replacing https://goodwe-power.com in the url with http://eu.goodwe-power.com and it worked as well.

GoodWe is the brand of the inverter installed, which connects to my home wifi and sends data automatically to the GoodWe Portal. The model I have is the GW4200D-NS.

I have to say that I wasn’t happy with the app I was provided with, neither was I happy with the portal, which refreshes the Real Time Data every 15 minutes! What kind of real time is that? However, to be fairly honest, why would you want to see actual Read Time readings? Well, because I want to. 🙂

Before looking for a solution on my own, I always search online, I don’t want to re-invent the wheel, so I found a post where I got the main idea: https://brnrd.eu/misc/2016-03-13/goodwe-logging-to-pvoutput.html . This post describes a way of grabbing the data from a non-Windows environment.

Important: I am not (nor is the post above) grabbing the data directly from the inverter, but I am leveraging the GoodWe portal information. An idea I have is to sniff the traffic the inverter sends to goodwe, capture it and re-utilise it, however I’m not too interested in that yet as the solution I have works fine.

Edit 20180605: GoodWe has started using HTTPS, so the previous script got broken because of this. I’ve updated it (just changed the URL from http to https) and the script is working as usual.

Dirty Notes

I’ll try to make it quick as the guy from the post above and myself have done most of the dirty work, I will just say that this required testing and some in-html reading. Thanks to the builtin Chrome Developer functions (F12), I was able to see quiet a few information, including the URL powershell had to grab its data from.

Two ways we can do this

  1. Grabbing the xls file for the current month.
    • GoodWe has an “Historic Data” tab that you can Export as well. I did find a way to get it exported it and then I grabbed the info from there. Unfortunately it required Excel for me to leverage the powershell cmdlets and also the DLL out there to work with XLS files (not xlsx) won’t work after a certain file size, so after the first half of the month (14MB or so), it would have stopped working giving errors. As I was not interested in getting Excel installed just for this, and I wanted a better way (than downloading 14+MB every minute), I went for option 2.
  2. Grab the data from the loaded Graph in the webpage, which contains updated data every 5 minutes.
    • goodwe-graph

URL

The post on brnrd.eu says to use the URL “https://www.goodwe-power.com/PowerStationPlatform/PowerStationReport/QueryTypeChanged” which updates every 10 minutes or so. However, after some digging, I found another URL that would refresh the data every 5: https://www.goodwe-power.com/PowerStationPlatform/PowerStationReport/QueryTypeChangedFor5Minutes

goodwe-url-5minutes

Process

What we need

  • The Inverter SN, something like 913100PQS071Z0112 (I made that up)
  • The Power Station ID, something like 33nn3332-4c19-232b-9h14-gbh0c2w490q1 (I made also this one up)

We also need other info, which don’t need to be provided by you, I’ll go through them later on.

How to get the Inverter SN and the Power Station ID

I suggest you to use Chrome or Firefox.

Inverter SN

The easy way to get this is by going to the Inverter and looking at the label and look for the S/N. Or else, you can do the following:

  • Log on the GoodWe Portal (https://goodwe-power.com)
  • Under Overview, you’ll find the SN there at the bottom.
Power Station ID

For this one, we will just need to view the GoodWe Portal source code.

  • Log on the GoodWe Portal (https://goodwe-power.com)
  • Right click and “View Source Page”
    • goodwe-view-page-source
  • Search the page for <input id=”ID” name=”ID”
    • There it is, you’re interested in what’ within “value” (the part I obfuscated in the screenshot).
    • goodwe-powerstationID-page-source

The Script

Just change the InvertSN and the PowerStationID from the script below and you should be good.

Basically the script will grab the data from the website for you and also format it in a way that gets 4 arrays of data:

  • PGrid(W) >> It’s the current production in Watt/h
  • Temperature (C) >> The temperature in Celsius
  • ETotal (kWh) >> The total amount of energy in KWh produced so far by the system.
  • EDay (kWh) >> The amount of energy in KWh produced today by the system

I’ve added a little check in the script: let’s say the script is running and it’s midnight, so when the inverter is off, the script will notice that PGrid(W) returns only zeros, so it reports everything to 0, except for the Time, which is set to “Yesterday” and except for ETotal (kWh) which the script will grab from the previous day.

The time in the script is taken from the number of minute passed: The amount of data reported by the web interface is every 5 minutes, which means we will have 289 entries in 24 hours (including 00:00 and 24:00). The script uses a counter to see which one is the last value, let’s say it’s the entry number 100, multiplies by 5 minutes and converts it in time we understand. That is done by this bit:

It’s important to notice that the PGrid changes way more often than just once every 5 minutes, here’s an example:

goodwe-powershell-monitoring-output

As you can see, for the past 5 times, the time is stuck at 13:40, however the PGrid(W) changes every 1 minute circa (the script runs every 30 seconds or so).

Now, the script just displays the information on screen and it’s adjusted for anybody who wants to grab the data, however I made another script (very similar) which I won’t show you (at least not today) that basically will drop all of the info in a php file that is integrated in the index.php of an IIS website and that will show me a simple output. Something very primitive for now (that is displayed very well on a mobile):

goodwe-php-monitoring

I hope this was informative and will help you building your own monitoring, in Windows 🙂 I didn’t want to go too deep into the details, if not this post would’ve became an e-book.

19 thoughts on “Get GoodWe data with Powershell

  1. Great work, and the update rate is perfect. Any chance you have since modified the script to push the data to PVoutput? I’ve been searching for some time for a Windows based solution to get my GoodWe data to PVoutput.

    1. Thanks Brad. I think I’ll write a quick article on that, but haven’t done it yet as I don’t use PVOutput. However, I had a very quick look at this and it seems pretty easy. First of all, in your PVOutput settings, enable the API Access and Generate a new key. After that have a look at the API Documentation: https://pvoutput.org/help.html#api-addbatchstatus .
      Basically you’ll need to use Powershell and Invoke-WebRequest to push the data. In the examples in the API page, they use curl.

      I wrote the article, check the link on the comment below.

  2. Hi,

    Thank you for posting this useful script. Just wondering if there has been any update to this. I have tried the script but I get {“result”:”error”} returned by the Invoke-WebRequest. I used the Developer Tools in Chrome and the query looks identical, just doesn’t work from Powershell. I’ve tried invoking get request on some public urls which works fine.

    Thank you

      1. Simone,

        Thank you for the quick response to this. Yes I am using https in the url. I used Fiddler to grab the request when navigating the via the portal and compared it with that produced by Powershell. Mostly header differences.

        This is what I tried and it always returns {“result”:”error”} in the request content. The status code is 200 so the request does complete.

        $url = “https://www.goodwe-power.com/PowerStationPlatform/PowerStationReport/QueryTypeChangedFor5Minutes”
        $InverterSN = “myserialno”
        $PowerStationID = “mypowerid”
        $QueryType=0
        $DateFrom = Get-Date -Format yyy-MM-dd
        # Build the Post parameters
        $postparams = @{InventerSN=$InverterSN; DateFrom=$DateFrom; PowerStationID=$PowerStationID; QueryType=$QueryType}
        $content = (Invoke-WebRequest -Uri $url -Method Post -Body $postparams).content
        $content

        1. So, I copied and pasted the script you posted and changed just the SN and the ID, and worked. It did give me the same error when I changed $PowerStationID to something random. Sorry for the stupid question, but.. are you sure you haven’t mixed up the PowerStationID with the SN? 😀

          1. Thank you! That was it – I had the SN/PoweStationID mixed up. Sometimes it just takes another pair of eyes. Sorry for the waste of time.

  3. Good work, works fine with me with my Goodwe inverter.
    I use jSunnyReports for my other set of panels to produce an overview via a website (http://pv.dierselhuis.eu). For this I use an SMA Inverter that creates csv files per day, which is then read every 5 minutes by jSunnyReport.
    How nice would it be if there is the possibility that the script can be modified to create a csv (or txt) file every day that could be provided with the data that is retrieved with your script.
    The output could then be: dd.MM.yyyy HH: mm: ss; Kwh; kw (power (w)).
    The csv file should then be named: Goodwe_yyyyMMdd. Goodwe should be a variable given.
    I do not have enough knowledge to do this. You may see a challenge in this.
    If that does not work, can you help me on my way?

    1. Hey Jan,

      When you say “How nice would it be if there is the possibility that the script can be modified to create a csv (or txt) file every day..” do you mean “every 5 minutes”? Generating a csv file daily, would be sort of useless, unless you’re only interested in the previous’ day output?
      It should be fairly simple to make this change on the script that generates the PHP file and instead of generating the file, it could just generate the csv file with the format you want.
      Have you got any experience at all with Powershell, at least I can see more or less how much technical I can get.. 🙂

  4. Thanks for the great script! Really awesome!

    I’ve just had a GoodWe GD5048D-ES installed, and I’m trying this out.

    I was initially getting this returned: {“result”:”error”}

    But I’ve realised it’s down to GoodWe changing their portal. They now use:
    https://www.semsportal.com

    I’ve tried a URL along the lines of:
    https://www.semsportal.com/PowerStation/PowerStationReport/QueryTypeChangedFor5Minutes

    but just getting a DOCTYPE response (which doesn’t seem to change, regardless of the URL).

    Do you know whether the new portal still provides this interface?

    Thanks very much!
    I’ve gone through the comments, checked the issues other people were having (Station ID & SN mixed up, etc.) and everything seemed correct.

    I have been that goodwe

  5. Thanks very much for this script – awesome work!

    I’ve just installed a GoodWe GW5048D-ES, and have tried to imeplement the script.

    I hit a few issues, which I think come down to GoodWe shutting down the old portal – they now use https://www.semsportal.com/

    I’ve been trying to see if they have a similar API, but I can’t seem to find anything that works. Do you know whether this is available? Have you got this working on the new portal?

    Thanks!

    1. Hi Daniel,

      Recently I noticed errors, but didn’t have time to look at it. However, I just did, it’s working again for me. Try to login with your account over to http://eu.goodwe-power.com and then try to run the script. Once you login, check if you have any station registered over there.
      Also, try to replace $url with http://eu.goodwe-power.com/
      I’m not sure whether your inverter is actually registered with the old portal as well though.

      Finally, as soon as I have a second, I want to review the new SEMS Portal, because I believe there’s an actual API for it which would make things way easier:
      http://euapi.sems.com.cn:82/swagger/ui/index#/PowerStationMonitorController

      Cheers

      1. Thanks for your reply (apologies for the double-post, wasn’t sure if it had gone through).

        I’ve tried logging into to old portal, but is says my account doesn’t exist. It also won’t let me register, pushing me to the new portal. I suspect that the old portal will now only work with accounts created before the cutover.

        I saw the swagger API, which looks really great – it’s just a little beyond my expertise at this point. No time like the present to learn though, I suppose!

        1. No worries about the double post (just an extra level of security against spam.. :)).
          Anyway, I think I worked it out, I’m gonna wrap a very basic script and post it today. It’s actually awesome because finally all data comes in a decent format and the script will end up being way shorter.

          1. Cool, let me know how that goes. It’s very basic but I think it’s all there to start.

Leave a Reply

Your email address will not be published. Required fields are marked *