Get SEMS/GoodWe data with Powershell

Get SEMS/GoodWe data with Powershell: GoodWe has transferred everything over to the SEMS Portal, which finally comes with an API! In this article we’ll see how to grab data directly from SEMS’ API.

This is basically an update to Get GoodWe data with Powershell which is no longer working for some users (mainly people with a brand new Inverter that was never registered with the old portal).

Let me start by saying that even though there’s finally an API, with some documentation (in Chinese as far as I could find it), it’s still a bit messy, I noticed that this works with different URLs, but I tried to stick to what I normally use to login to the portal (https://www.semsportal.com).

The API works based on tokens, which means it requires two web requests, one to authenticate and grab the token data and another one to grab the actual output we’re after. It’s fairly simple and I’ll go through what I think it’s most important.

At the time of testing (20190613) the Inverter was pushing data to the SEMS Portal every 2.5 minutes circa, which it’s better than the old version of the script that could only see data every 5 minutes. It takes about 30 seconds to see the data: what I mean is, if it’s 9:00:00AM next refresh will occur at around 9:02:30AM, but the portal will have this data processed by around 9:03:00AM (sometimes earlier). An example for the last 4 entries I tried:

  • 06/13/2019 14:08:58
  • 06/13/2019 14:11:28
  • 06/13/2019 14:13:59
  • 06/13/2019 14:16:29

This is a basic script, please implement some error handling!

Authenticate and get the token

So all you need to input are the credentials to the SEMS Portal (email address and password). Just because we’re testing this out, the script will use Get-Credential. You could store a hash or even better use Windows Credential Manager to retrieve user/pwd.

$TokenRequest contains a few info we need:

  • $TokenRequest.data.token
  • $TokenRequest.data.uid
  • $TokenRequest.data.timestamp
  • $TokenRequest.msg

$TokenRequest.msg will contain the string success in case the request is successful, so you can implement an If to check if ($TokenRequest.msg -ne “success”) and throw an error or at least, check it before proceeding with querying data (or else you’ll get an error from the API going forward).

The other 3 variables (..token, uid and timestamp) are needed to.. build the token 🙂 – So basically .data.token isn’t enough.

Next step, request the the most updated data

There’s one thing you must input: that’s the powerstationId which is located in the URL once you access the SEMS Plant Status portal. If you look at the source of the page, you’ll also find it under powerstation_id or pw_id, but in the URL it’s super easy and straight forward.

https://www.semsportal.com/powerstation/powerstatussnmin/12345678-1234-1234-1234-123456789012

At the minute, I’m not sure how long it’ll take before the token expire, I know that it’ll expire for sure if you authenticate again with the first bit of this script.

If everything went fine, $Request.msg equals success, so you could check for that. I only played with this for a few minutes, but I found already that the most interesting data for me is located in $Request.data.inverter.d.

Especially these values:

  • last_refresh_time
    • Useful to make sure the data is up to date.
  • warning
    • Shows the current status of the inverter
  • eDay
    • KWh produced today
  • eTotal
    • KWh produced ever since
  • pac
    • Last’s refresh output from the inverter

You can also use just $Request.data.inverter to see them (and the temperature), in the picture below I highlighted what’s handy.

This should be enough to get you started. I will look at updating this post whenever I have some more time.

Here you can have a look at the API documentation: http://semsportal.com:82/swagger/ui/index#/. On the top of the page, there’s a drop down menu with the 3 available APIs today (v0, v1 and v2).

Leave a Reply

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