Download SolarEdge solar production data and save to csv

I’ve got a nice solar panel setup on my roof, which uploads its data to the SolarEdge monitoring portal (this is the brand of inverter that I got). It appeared that this monitoring portal also has an API to automate getting the energy data. With me working in a company that works on energy savings, monitoring, consultancy etc, it’s a logical step for me to automate downloading the production of my panels, so my collueges at work can import this data in my energy monitoring portal at work and then they can do their magic calculations on them; which results in me getting nice graphs of my solar enrgy production.

The purpose of the tool:

I wrote this tool to be somewhat smart in what to download and what not. I only want to download the information if it’s up-to-date. Next to that, I’d want daily values, but also values with a 15 minute interval. In the end I’d want all the info to be exported to CSV files containing 1 month of data and/or 1 year of data. All files that have already been generated don’t need their data to be downloaded again and overwritten, thus it skips this data once it’s downloaded. In the end I can either mail these files or put them on a file share, so they can be imported by our energy monitoring system. This last step I’ve removed from the script that I share with you.

Several nice ‘techniques’ used in this script to get to the goal:

Since I’m talking with an API, the main important command is the Invoke-WebRequest with a pipe to ConvertFrom-Json

To get the last day of the month, the following line is used: $LastDayOfTheMonth = ((Get-Date -Date “01-$Month-$Year” -Hour 0 -Minute 0 -Second 0).AddMonths(1).AddSeconds(-1)).Day

(which will add a month to the date/time 01-<month>-<year> : 0:00 and then remove 1 second to get to the last second of the previous month, thus resulting in returning the last day of that month (<last day>-<month>-<year> 23:59:59))

In the end, the downloaded data is converted to CSV with this command: | ConvertTo-Csv -Delimiter “;” -NoTypeInformation (in Excel with localization the Netherlands, the semicolon is a better seperator than a comma, since Excel expects a semicolon. This saves me time on opening the csv files and converting the information to an excel readable file. Depending on your localization settings, you’d want to change this accordingly) I also add the switch -NoTypeInformation, since I’m not interested in getting information about the type of variable PS used, I only need the data.

Script parameters and bounds:

The script will check the solaredge portal for the date/time on which the installation received its latest data. If this date is not the same as today, something might be wrong. It’ll warn you about it, but will still download. If it’s out of date for more than 1 day, it’ll give an error about this, but the script will still continue. When no data has been downloaded, the tool will download all data (starting on the installation date of the inverter) per month and save these to csv files. It will also generate files with yearly data. The data that’s downloaded is from the previous month (unless this is a later date than the date the last data was received on the solaredge monitoring portal, then the last data date will be used). In case of the daily values (monthly and yearly csv’s), the tool will only store the value’s if they’re not $null (which is: no data received on portal or the solar panels with its optimizers as a whole aren’t yet initialized by the inverter). In case of the 15 minute interval values, all $null values will be replaced by 0,0 (in that case the inverter is turned off because of its night mode); thus giving a nice list of 96 readings each day, and resulting in about 2688 – 2976 values in each file, depending on the amount of days in the month (which can be checked for, if needed; in my case I don’t, since my work already has many comprehensive tools to check for gaps or strange behaviour in data).

The script can be found and downloaded here: DownloadEnergyData.ps1

 

Edit: I got myself an undocumented API call parameter from a SolarEdge developer, which gives me 15 minute values in WH 🙂 The script has been updated. (&TimeUnit=QUARTER_OF_AN_HOUR)

42 thoughts on “Download SolarEdge solar production data and save to csv

      1. Hi, I’d really like to use this but it seems to throw up a series of errors when I try to run it – does the code still work?

        Like

      2. Hi James,
        yes, the code does still work.
        Did you enter your SiteID and your APIKey?
        If so, you probably use Powershell 2 or lower, but you need Powershell 3.0 or higher to be able to run this. To check which version you are using, you can check “$psversiontable” (without the quotes) when running powershell. This will tell you the current Powershell version (PSVersion)
        You can find upgrades for your powershell here: https://docs.microsoft.com/en-us/powershell/scripting/install/installing-windows-powershell?view=powershell-6 (near the end of the page, there’s a table with different PS versions for each different supported OS)

        Like

      3. That could be as well yes. But since you talked about multiple errors, I assumed you weren’t using the correct PowerShell version. Glad that it got solved and you’re able to run the tool now.

        Like

  1. rather than the overall 15 minute energy value for the site, because there is more than one inverter I need to get individual inverter data. I presume that this will need to use a different url – production? consumption?

    Like

  2. This was super-duper useful – thanks so much. Ran with no issues, and has saved me days of work. THANKS!

    Like

      1. Hi. looks like the energyDetails api can now give me Production, Consumption, SelfConsumption, Import and Export. Ive played around with the script but I cant not get it to convert to csv – I get error “Cannot bind to argument parameter ‘InputObject’

        Im stuck on how I reference the energyDetails.meters.production.values

        the JSON looks like this.

        “energyDetails”: {
        “timeUnit”: “WEEK”,
        “unit”: “Wh”,
        “meters”: [
        {
        “type”: “Production”,
        “values”: [
        {
        “date”: “2015-10-19 00:00:00”
        },
        {
        “date”: “2015-10-26 00:00:00”

        Im at the very beginning of PowerShell learning curve so forgive my ignorance. As a side note what I am trying to do is create a total model of usage (PV, Tesla, heating etc) that I then integrate with time of use tariff data to calculate what my cost would be on each tariff.

        Like

  3. Sorry for my late reply. I’m pretty busy at the moment as multiple areas in my life need(ed) my attention.
    What you can do with the json return, is convert it, by putting ” | ConvertFrom-Json” at the end of the line, where you put the return in a variable.
    Once you’ve done that, you can export the variable to csv, by using “$yourvariable | Export-Csv -path C:\yourpath\yourfilename.csv”
    That way you should be able to make the information readable and exportable.

    Like

    1. Prior to running I invoked

      Set-executionpolicy unrestricted

      I am having problems running the powershell script. I entered the Site ID and API key, which I verified with SolarEdge. Now I am getting these errors

      PS D:\Solar Edge> D:\Solar Edge\DownloadEnergyData.ps1
      Invoke-WebRequest : HTTP Status 403 –
      type Status report
      message
      description Access to the specified resource () has been forbidden.
      Welcome to Apache Tomcat
      At D:\Solar Edge\DownloadEnergyData.ps1:14 char:17
      + $SiteDetails = (Invoke-WebRequest $DetailsUrl).Content | ConvertFrom- …
      + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      + CategoryInfo : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-WebRequest], WebExceptio
      n
      + FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeWebRequestCommand
      Invoke-WebRequest : HTTP Status 403 –
      type Status report
      message
      description Access to the specified resource () has been forbidden.
      Welcome to Apache Tomcat
      At D:\Solar Edge\DownloadEnergyData.ps1:15 char:18
      + $SiteOverview = (Invoke-WebRequest $OverviewUrl).Content | ConvertFro …
      + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      + CategoryInfo : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-WebRequest], WebExceptio
      n
      + FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeWebRequestCommand
      You cannot call a method on a null-valued expression.
      At D:\Solar Edge\DownloadEnergyData.ps1:17 char:1
      + $LastUpdateTime = ($SiteOverview.overview.lastUpdateTime.Split(” “))[ …
      + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      + CategoryInfo : InvalidOperation: (:) [], RuntimeException
      + FullyQualifiedErrorId : InvokeMethodOnNull

      Get-Date : Cannot bind parameter ‘Date’ to the target. Exception setting “Date”: “Cannot convert null to type
      “System.DateTime”.”
      At D:\Solar Edge\DownloadEnergyData.ps1:18 char:38
      + $LastUpdateDateTime = Get-Date -Date $LastUpdateTime
      + ~~~~~~~~~~~~~~~
      + CategoryInfo : WriteError: (:) [Get-Date], ParameterBindingException
      + FullyQualifiedErrorId : ParameterBindingFailed,Microsoft.PowerShell.Commands.GetDateCommand

      Cannot find an overload for “op_Subtraction” and the argument count: “2”.
      At D:\Solar Edge\DownloadEnergyData.ps1:21 char:5
      + $DaysAgo = ($Date – $LastUpdateDateTime).Days
      + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      + CategoryInfo : NotSpecified: (:) [], MethodException
      + FullyQualifiedErrorId : MethodCountCouldNotFindBest

      D:\Solar Edge\DownloadEnergyData.ps1 : The installation has not been updated since . This
      is days ago. Script will continue, but it is advised to fix the error. This script will only download the data until the
      date of the last available data
      + CategoryInfo : NotSpecified: (:) [Write-Error], WriteErrorException
      + FullyQualifiedErrorId : Microsoft.PowerShell.Commands.WriteErrorException,DownloadEnergyData.ps1

      Invoke-WebRequest : HTTP Status 403 –
      type Status report
      message
      description Access to the specified resource () has been forbidden.
      Welcome to Apache Tomcat
      At D:\Solar Edge\DownloadEnergyData.ps1:30 char:16
      + $DataPeriod = (Invoke-WebRequest $DataPeriodUrl).Content | ConvertFro …
      + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      + CategoryInfo : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-WebRequest], WebExceptio
      n
      + FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeWebRequestCommand
      Get-Date : Cannot bind parameter ‘Date’ to the target. Exception setting “Date”: “Cannot convert null to type
      “System.DateTime”.”
      At D:\Solar Edge\DownloadEnergyData.ps1:33 char:30
      + $StartYear = (Get-Date -Date $StartDate).Year
      + ~~~~~~~~~~
      + CategoryInfo : WriteError: (:) [Get-Date], ParameterBindingException
      + FullyQualifiedErrorId : ParameterBindingFailed,Microsoft.PowerShell.Commands.GetDateCommand

      Get-Date : Cannot bind parameter ‘Date’ to the target. Exception setting “Date”: “Cannot convert null to type
      “System.DateTime”.”
      At D:\Solar Edge\DownloadEnergyData.ps1:66 char:61
      + … f($Year -eq $StartYear) { $Month = (Get-Date -Date $StartDate).Month …
      + ~~~~~~~~~~
      + CategoryInfo : WriteError: (:) [Get-Date], ParameterBindingException
      + FullyQualifiedErrorId : ParameterBindingFailed,Microsoft.PowerShell.Commands.GetDateCommand

      Get-Date : Cannot bind parameter ‘Date’. Cannot convert value “01-2-” to type “System.DateTime”. Error: “String was not
      recognized as a valid DateTime.”
      At D:\Solar Edge\DownloadEnergyData.ps1:72 char:47
      + … $LastDayOfTheMonth = ((Get-Date -Date “01-$Month-$Year” -Hour 0 …
      + ~~~~~~~~~~~~~~~~~
      + CategoryInfo : InvalidArgument: (:) [Get-Date], ParameterBindingException
      + FullyQualifiedErrorId : CannotConvertArgumentNoMessage,Microsoft.PowerShell.Commands.GetDateCommand

      Invoke-WebRequest : HTTP Status 403 –
      type Status report
      message
      description Access to the specified resource () has been forbidden.
      Welcome to Apache Tomcat
      At D:\Solar Edge\DownloadEnergyData.ps1:39 char:20
      + $EnergyData = (Invoke-WebRequest “$Url”).Content | ConvertFrom-Js …
      + ~~~~~~~~~~~~~~~~~~~~~~~~
      + CategoryInfo : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-WebRequest], WebExceptio
      n
      + FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeWebRequestCommand
      Exception calling “WriteAllLines” with “2” argument(s): “Value cannot be null.
      Parameter name: contents”
      At D:\Solar Edge\DownloadEnergyData.ps1:42 char:5
      + [io.file]::WriteAllLines(“$PSScriptRoot\$FileName”,$Data)
      + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      + CategoryInfo : NotSpecified: (:) [], MethodInvocationException
      + FullyQualifiedErrorId : ArgumentNullException

      Invoke-WebRequest : HTTP Status 403 –
      type Status report
      message
      description Access to the specified resource () has been forbidden.
      Welcome to Apache Tomcat
      At D:\Solar Edge\DownloadEnergyData.ps1:48 char:20
      + $EnergyData = (Invoke-WebRequest “$Url”).Content | ConvertFrom-Js …
      + ~~~~~~~~~~~~~~~~~~~~~~~~
      + CategoryInfo : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-WebRequest], WebExceptio
      n
      + FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeWebRequestCommand
      The property ‘value’ cannot be found on this object. Verify that the property exists and can be set.
      At D:\Solar Edge\DownloadEnergyData.ps1:49 char:75
      + … alues | ForEach-Object { If($_.value -eq $null) { $_.value = “0,0” }}
      + ~~~~~~~~~~~~~~~~
      + CategoryInfo : InvalidOperation: (:) [], RuntimeException
      + FullyQualifiedErrorId : PropertyNotFound

      ConvertTo-Csv : Cannot bind argument to parameter ‘InputObject’ because it is null.
      At D:\Solar Edge\DownloadEnergyData.ps1:50 char:41
      + … yData.energy.values | ConvertTo-Csv -Delimiter “;” -NoTypeInformation
      + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      + CategoryInfo : InvalidData: (:) [ConvertTo-Csv], ParameterBindingValidationException
      + FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,Microsoft.PowerShell.Commands.ConvertToCsvComm
      and

      Get-Date : Cannot bind parameter ‘Date’. Cannot convert value “01-3-” to type “System.DateTime”. Error: “String was not
      recognized as a valid DateTime.”
      At D:\Solar Edge\DownloadEnergyData.ps1:72 char:47
      + … $LastDayOfTheMonth = ((Get-Date -Date “01-$Month-$Year” -Hour 0 …
      + ~~~~~~~~~~~~~~~~~
      + CategoryInfo : InvalidArgument: (:) [Get-Date], ParameterBindingException
      + FullyQualifiedErrorId : CannotConvertArgumentNoMessage,Microsoft.PowerShell.Commands.GetDateCommand

      Invoke-WebRequest : HTTP Status 403 –
      type Status report
      message
      description Access to the specified resource () has been forbidden.
      Welcome to Apache Tomcat
      At D:\Solar Edge\DownloadEnergyData.ps1:39 char:20
      + $EnergyData = (Invoke-WebRequest “$Url”).Content | ConvertFrom-Js …
      + ~~~~~~~~~~~~~~~~~~~~~~~~
      + CategoryInfo : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-WebRequest], WebExceptio
      n
      + FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeWebRequestCommand
      Exception calling “WriteAllLines” with “2” argument(s): “Value cannot be null.
      Parameter name: contents”
      At D:\Solar Edge\DownloadEnergyData.ps1:42 char:5
      + [io.file]::WriteAllLines(“$PSScriptRoot\$FileName”,$Data)
      + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      + CategoryInfo : NotSpecified: (:) [], MethodInvocationException
      + FullyQualifiedErrorId : ArgumentNullException

      Like

  4. In the SolarEdge app, my ID is seven digits. The PowerShell script is looking for six. “Enter your Site ID here (6 digits):” What am I missing?

    Like

    1. I just spoke to SolarEdge the site ID can be 4-8 digits in length. Is the comment of six digits just a comment?

      Like

      1. Yes, this is only a comment. At the time of writing the script, the technician from SolarEdge told me that they were always 6 digits (maybe he was wrong, but since mine is 6 digits, I didn’t know better), so probably the 6 digit range wasn’t sufficient enough and they’ve expanded on that.

        Like

  5. Firstly I ran this command Set-executionpolicy unrestricted. I replaced the holders with my actual ID and API key. I get the following errors:

    PS D:\Solar Edge> D:\Solar Edge\DownloadEnergyData.ps1
    Invoke-WebRequest : HTTP Status 403 –
    type Status report
    message
    description Access to the specified resource () has been forbidden.
    Welcome to Apache Tomcat
    At D:\Solar Edge\DownloadEnergyData.ps1:14 char:17
    + $SiteDetails = (Invoke-WebRequest $DetailsUrl).Content | ConvertFrom- …
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-WebRequest], WebExceptio
    n
    + FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeWebRequestCommand
    Invoke-WebRequest : HTTP Status 403 –
    type Status report
    message
    description Access to the specified resource () has been forbidden.
    Welcome to Apache Tomcat
    At D:\Solar Edge\DownloadEnergyData.ps1:15 char:18
    + $SiteOverview = (Invoke-WebRequest $OverviewUrl).Content | ConvertFro …
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-WebRequest], WebExceptio
    n
    + FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeWebRequestCommand
    You cannot call a method on a null-valued expression.
    At D:\Solar Edge\DownloadEnergyData.ps1:17 char:1
    + $LastUpdateTime = ($SiteOverview.overview.lastUpdateTime.Split(” “))[ …
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : InvokeMethodOnNull

    Get-Date : Cannot bind parameter ‘Date’ to the target. Exception setting “Date”: “Cannot convert null to type
    “System.DateTime”.”
    At D:\Solar Edge\DownloadEnergyData.ps1:18 char:38
    + $LastUpdateDateTime = Get-Date -Date $LastUpdateTime
    + ~~~~~~~~~~~~~~~
    + CategoryInfo : WriteError: (:) [Get-Date], ParameterBindingException
    + FullyQualifiedErrorId : ParameterBindingFailed,Microsoft.PowerShell.Commands.GetDateCommand

    Cannot find an overload for “op_Subtraction” and the argument count: “2”.
    At D:\Solar Edge\DownloadEnergyData.ps1:21 char:5
    + $DaysAgo = ($Date – $LastUpdateDateTime).Days
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo : NotSpecified: (:) [], MethodException
    + FullyQualifiedErrorId : MethodCountCouldNotFindBest

    D:\Solar Edge\DownloadEnergyData.ps1 : The installation has not been updated since . This
    is days ago. Script will continue, but it is advised to fix the error. This script will only download the data until the
    date of the last available data
    + CategoryInfo : NotSpecified: (:) [Write-Error], WriteErrorException
    + FullyQualifiedErrorId : Microsoft.PowerShell.Commands.WriteErrorException,DownloadEnergyData.ps1

    Invoke-WebRequest : HTTP Status 403 –
    type Status report
    message
    description Access to the specified resource () has been forbidden.
    Welcome to Apache Tomcat
    At D:\Solar Edge\DownloadEnergyData.ps1:30 char:16
    + $DataPeriod = (Invoke-WebRequest $DataPeriodUrl).Content | ConvertFro …
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-WebRequest], WebExceptio
    n
    + FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeWebRequestCommand
    Get-Date : Cannot bind parameter ‘Date’ to the target. Exception setting “Date”: “Cannot convert null to type
    “System.DateTime”.”
    At D:\Solar Edge\DownloadEnergyData.ps1:33 char:30
    + $StartYear = (Get-Date -Date $StartDate).Year
    + ~~~~~~~~~~
    + CategoryInfo : WriteError: (:) [Get-Date], ParameterBindingException
    + FullyQualifiedErrorId : ParameterBindingFailed,Microsoft.PowerShell.Commands.GetDateCommand

    Get-Date : Cannot bind parameter ‘Date’ to the target. Exception setting “Date”: “Cannot convert null to type
    “System.DateTime”.”
    At D:\Solar Edge\DownloadEnergyData.ps1:66 char:61
    + … f($Year -eq $StartYear) { $Month = (Get-Date -Date $StartDate).Month …
    + ~~~~~~~~~~
    + CategoryInfo : WriteError: (:) [Get-Date], ParameterBindingException
    + FullyQualifiedErrorId : ParameterBindingFailed,Microsoft.PowerShell.Commands.GetDateCommand

    Get-Date : Cannot bind parameter ‘Date’. Cannot convert value “01-2-” to type “System.DateTime”. Error: “String was not
    recognized as a valid DateTime.”
    At D:\Solar Edge\DownloadEnergyData.ps1:72 char:47
    + … $LastDayOfTheMonth = ((Get-Date -Date “01-$Month-$Year” -Hour 0 …
    + ~~~~~~~~~~~~~~~~~
    + CategoryInfo : InvalidArgument: (:) [Get-Date], ParameterBindingException
    + FullyQualifiedErrorId : CannotConvertArgumentNoMessage,Microsoft.PowerShell.Commands.GetDateCommand

    Invoke-WebRequest : HTTP Status 403 –
    type Status report
    message
    description Access to the specified resource () has been forbidden.
    Welcome to Apache Tomcat
    At D:\Solar Edge\DownloadEnergyData.ps1:39 char:20
    + $EnergyData = (Invoke-WebRequest “$Url”).Content | ConvertFrom-Js …
    + ~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-WebRequest], WebExceptio
    n
    + FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeWebRequestCommand
    Exception calling “WriteAllLines” with “2” argument(s): “Value cannot be null.
    Parameter name: contents”
    At D:\Solar Edge\DownloadEnergyData.ps1:42 char:5
    + [io.file]::WriteAllLines(“$PSScriptRoot\$FileName”,$Data)
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : ArgumentNullException

    Invoke-WebRequest : HTTP Status 403 –
    type Status report
    message
    description Access to the specified resource () has been forbidden.
    Welcome to Apache Tomcat
    At D:\Solar Edge\DownloadEnergyData.ps1:48 char:20
    + $EnergyData = (Invoke-WebRequest “$Url”).Content | ConvertFrom-Js …
    + ~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-WebRequest], WebExceptio
    n
    + FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeWebRequestCommand
    The property ‘value’ cannot be found on this object. Verify that the property exists and can be set.
    At D:\Solar Edge\DownloadEnergyData.ps1:49 char:75
    + … alues | ForEach-Object { If($_.value -eq $null) { $_.value = “0,0” }}
    + ~~~~~~~~~~~~~~~~
    + CategoryInfo : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : PropertyNotFound

    ConvertTo-Csv : Cannot bind argument to parameter ‘InputObject’ because it is null.
    At D:\Solar Edge\DownloadEnergyData.ps1:50 char:41
    + … yData.energy.values | ConvertTo-Csv -Delimiter “;” -NoTypeInformation
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo : InvalidData: (:) [ConvertTo-Csv], ParameterBindingValidationException
    + FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,Microsoft.PowerShell.Commands.ConvertToCsvComm
    and

    Get-Date : Cannot bind parameter ‘Date’. Cannot convert value “01-3-” to type “System.DateTime”. Error: “String was not
    recognized as a valid DateTime.”
    At D:\Solar Edge\DownloadEnergyData.ps1:72 char:47
    + … $LastDayOfTheMonth = ((Get-Date -Date “01-$Month-$Year” -Hour 0 …
    + ~~~~~~~~~~~~~~~~~
    + CategoryInfo : InvalidArgument: (:) [Get-Date], ParameterBindingException
    + FullyQualifiedErrorId : CannotConvertArgumentNoMessage,Microsoft.PowerShell.Commands.GetDateCommand

    Invoke-WebRequest : HTTP Status 403 –
    type Status report
    message
    description Access to the specified resource () has been forbidden.
    Welcome to Apache Tomcat
    At D:\Solar Edge\DownloadEnergyData.ps1:39 char:20
    + $EnergyData = (Invoke-WebRequest “$Url”).Content | ConvertFrom-Js …
    + ~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-WebRequest], WebExceptio
    n
    + FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeWebRequestCommand
    Exception calling “WriteAllLines” with “2” argument(s): “Value cannot be null.
    Parameter name: contents”
    At D:\Solar Edge\DownloadEnergyData.ps1:42 char:5
    + [io.file]::WriteAllLines(“$PSScriptRoot\$FileName”,$Data)
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : ArgumentNullException

    Like

    1. It sounds like at the side of SolarEdge they don’t allow the web request (api call). I do know that if you do too many requests, they will disable calls for your API key and SiteID for 24 hours.
      But if it is the first time you do a call, you could try to open the URL in your browser manually. In that case, enter this URL (for example): https://monitoringapi.solaredge.com/site/$SiteID/details?api_key=$ApiKey (and replace “$SiteID” by your actual site id, also you need to replay “$ApiKey” by your actual api key. Check if this gives you a result in your browser, of if it gives you an error.

      Like

  6. I tried the examples in the API manual and received the same error. I contacted SolarEdge and they needed to contact Level 3 support in Israel. I must have found an interesting bug. THANK YOU for your time. I will keep you apprised.

    Liked by 1 person

  7. I ran the PowerShell script there were no errors or other messages. Should there have been a completed message. I couldn’t find the resulting output file. What is the output file name and where is the output stored?

    Sorry to bother you again

    Like

    1. The files should have been created in the folder the script is running from. They are csv files, which start with the year and/or the year and month . ie. 201909 (some text based upon site name and type of downloaded files).csv

      Like

  8. Sorry to bother you again. The script does not generate any csv files. So I added some debugging Write-Output statements. If you have time, what are your thoughts. Here is the script:

    #Enter your Site ID here (6 digits):
    $SiteID = “1330580”
    #Enter your API key here (32 characters):
    $ApiKey = “4Q9VK9T154S5LNKZ56AN3TVOH91RJPFA”
    $Day = “DAY”
    $15Min = “QUARTER_OF_AN_HOUR”
    $CurrentDate = Get-Date -Format yyyy-MM-dd
    $Date = Get-Date
    $DataPeriodUrl = “https://monitoringapi.solaredge.com/site/$SiteID/dataPeriod?api_key=$ApiKey”
    $OverviewUrl = “https://monitoringapi.solaredge.com/site/$SiteID/overview?api_key=$ApiKey”
    $DetailsUrl = “https://monitoringapi.solaredge.com/site/$SiteID/details?api_key=$ApiKey”
    $EnergyUrl = “https://monitoringapi.solaredge.com/site/$SiteID/energy?api_key=$ApiKey”

    $SiteDetails = (Invoke-WebRequest $DetailsUrl).Content | ConvertFrom-Json
    $SiteOverview = (Invoke-WebRequest $OverviewUrl).Content | ConvertFrom-Json

    $LastUpdateTime = ($SiteOverview.overview.lastUpdateTime.Split(” “))[0]
    Write-Output $LastUpdateTime
    $LastUpdateDateTime = Get-Date -Date $LastUpdateTime
    Write-Output $LastUpdateTime
    If($LastUpdateTime -ne $CurrentDate)
    {
    $DaysAgo = ($Date – $LastUpdateDateTime).Days
    Write-Output $DaysAgo
    SWitch($DaysAgo)
    {
    0 { Write-Output “The energy data on the monitoring portal is up to date, will start downloading data if necessary” }
    1 { Write-Warning “The energy data on the monitoring portal has not been updated for a day. This might have various reasons: `r`n – The update script is ran within the first 15 minutes of a new day, in that case it’s usual behaviour.`r`n – There has been an interruption in the connection between the inverter and the monitoring portal.`r`n – No data has been received on the monitoring portal.`r`n Script will continue as usual.” -WarningAction Continue }
    default { Write-Error “The installation has not been updated since $LastUpdateTime. This is $DaysAgo days ago. Script will continue, but it is advised to fix the error. This script will only download the data until the date of the last available data” -ErrorAction Continue }
    }
    }

    $DataPeriod = (Invoke-WebRequest $DataPeriodUrl).Content | ConvertFrom-Json
    $StartDate = $DataPeriod.dataPeriod.startDate
    $CurrentYear = $Date.Year
    $StartYear = (Get-Date -Date $StartDate).Year
    $LastMonth = $LastUpdateDateTime.Month

    Write-Output $DataPeriod
    Write-Output $StartDate
    Write-Output $CurrentYear
    Write-Output $LastMonth

    Function Get-EnergyDataRemoveNulls
    {
    Param([Parameter(Mandatory=$true)][string]$Url,[Parameter(Mandatory=$true)][string]$FileName)
    $EnergyData = (Invoke-WebRequest “$Url”).Content | ConvertFrom-Json
    Write-Output $EnergyData
    #Get the daily values per month from the monitoring portal, we do not want empty cells (empty data happens when: the link between the inverter and the monitoring portal was down (ie: no internet connection))
    $Data = $EnergyData.energy.values | Where-Object value -ne $null | ConvertTo-Csv -Delimiter “;” -NoTypeInformation
    Write-Output $Data
    [io.file]::WriteAllLines(“$PSScriptRoot\$FileName”,$Data)
    }

    Function Get-EnergyDataReplaceNulls
    {
    Param([Parameter(Mandatory=$true)][string]$Url,[Parameter(Mandatory=$true)][string]$FileName)
    $EnergyData = (Invoke-WebRequest “$Url”).Content | ConvertFrom-Json
    Write-Output $EnergyData
    $EnergyData.energy.values | ForEach-Object { If($_.value -eq $null) { $_.value = “0,0” }}
    Write-Output $EnergyData.energy.values
    $Data = $EnergyData.energy.values | ConvertTo-Csv -Delimiter “;” -NoTypeInformation
    Write-Output $Data
    If($Data -ne $null) { [io.file]::WriteAllLines(“$PSScriptRoot\$FileName”,$Data) }
    }

    For($Year = $StartYear; $Year -le $CurrentYear; $Year++)
    {
    If($Year -eq $CurrentYear)
    {
    If($StartYear -eq $CurrentYear) { $Month = (Get-Date -Date $StartDate).Month }
    Else { $Month = 1 }

    If($LastMonth -le $LastUpdateDateTime.Month) { $LastMonth = $Date.Month }
    Else { $LastMonth = $LastUpdateDateTime.Month + 1 }
    }
    Else
    {
    If($Year -eq $StartYear) { $Month = (Get-Date -Date $StartDate).Month }
    Else { $Month = 1 }
    $LastMonth = 13
    }
    For($Month; $Month -lt $LastMonth; $Month++)
    {
    $LastDayOfTheMonth = ((Get-Date -Date “01-$Month-$Year” -Hour 0 -Minute 0 -Second 0).AddMonths(1).AddSeconds(-1)).Day
    $strMonth = “{0:0#}” -f $Month
    $FileName = “$Year” + $strMonth + ” – ” + $SiteDetails.details.name + $SiteID + “.csv”
    $FileName15min = “$Year” + $strMonth + ” – ” + $SiteDetails.details.name + $SiteID + “-15min.csv”
    If(!(Test-Path “$PSScriptRoot\$FileName”))
    {
    $Url = “$EnergyUrl&timeUnit=$Day&startDate=$Year-$strMonth-01&endDate=$Year-$strMonth-$LastDayOfTheMonth”
    Get-EnergyDataRemoveNulls -Url “$Url” -FileName $FileName
    }
    Write-Output $FileName
    Write-Output $FileName15min

    Else { Write-Output “File $FileName already exists. Script will not download this data again” }
    If(!(Test-Path “$PSScriptRoot\$FileName15min”))
    {
    $Url = “$EnergyUrl&timeUnit=$15Min&startDate=$Year-$strMonth-01&endDate=$Year-$strMonth-$LastDayOfTheMonth”
    Get-EnergyDataReplaceNulls -Url “$Url” -FileName $FileName15min
    }
    Else { Write-Output “File $FileName15min already exists. Script will not download this data again” }
    }
    If(($Year -lt $CurrentYear) -and ($Year -le $LastUpdateDateTime.Year))
    {
    $Url = “$EnergyUrl&timeUnit=$Day&startDate=$Year-01-01&endDate=$Year-12-31”
    $FileName = “$Year – ” + $SiteDetails.details.name + $SiteID + “.csv”
    If(!(Test-Path “$PSScriptRoot\$FileName”))
    {
    Get-EnergyDataRemoveNulls -Url “$Url” -FileName $FileName
    }
    Else { Write-Output “File $FileName already exists. Script will not download this data again” }
    }
    }
    Here is the output:

    S C:\WINDOWS\system32> D:\SolarEdge\DownloadEnergyData.ps1
    2019-10-31
    2019-10-31

    dataPeriod
    ———-
    @{startDate=2019-10-18; endDate=2019-10-31}
    2019-10-18
    2019
    10

    PS C:\WINDOWS\system32>

    Like

  9. I am making some progress. The script now generates a csv file but seems to be acing inconsistently. My system was first operational on Oct 18. Only 1 report was run this morning (Nov.1) and only had data (all 0’s) from 10-1 00:00:00 to 10-9. 23:45:00. There appeared to be only 1 report. I am still trying to figure it out. The last time I ran it, I received this message ”
    At D:\5 streename St\Solar\Solar Edge\DownloadEnergyDatay.ps1:42 char:5
    + [io.file]::WriteAllLines(“$PSScriptRoot\$FileName”,$Data)
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : ArgumentNullException

    Thanks

    Like

  10. I am still having issues. Today’s issue is I get the following after running it

    S C:\WINDOWS\system32> C:\DownloadEnergyData.ps1
    Exception calling “WriteAllLines” with “2” argument(s): “Value cannot be null.
    Parameter name: contents”
    At C:\DownloadEnergyData.ps1:42 char:5
    + [io.file]::WriteAllLines(“$PSScriptRoot\$FileName”,$Data)
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : ArgumentNullException

    Like

    1. Hi, it looks like you right-click the tool and use the “run with powershell” option. This way the script runs in C:\Windows\system32, which is a protected folder, so you won’t be able to save the files.
      You shoult probably open the tool in powershell, in the folder you’ve saved the tool in and then run it from powershell. Or you should create a CMD file where you run powershell with the script as start-up parameter, so it’ll run in the folder where the tool is saved, instead of the c:\widnows\system32 folder.
      The first option is the easiest, so right-click the file and choose edit, then, when powershell opens, choose run. And it should save all files in the folder.

      Like

  11. Thanks for creating and sharing this PowerShell script. It worked perfectly for me running Windows 7 with PowerShell version 5.1.

    Liked by 1 person

  12. I am getting partial results. month 1 have 31 values, month 2 have values up until day 1, month 3 have values up until day 2. month 4 have values up until day 3. etc.
    Is it a date format setting issue?
    My computer is set to region Sweden and swedish format
    Short date = YYYY-MM-DD
    I have checked the API data manually using an url and that data is complete.
    I have tried to run the script from powershell and by rigth clicking the file and select run with powershell but the result is the same.
    PSVersion 5.1.18362.752
    PSEdition Desktop
    PSCompatibleVersions {1.0, 2.0, 3.0, 4.0…}
    BuildVersion 10.0.18362.752
    CLRVersion 4.0.30319.42000
    WSManStackVersion 3.0
    PSRemotingProtocolVersion 2.3
    SerializationVersion 1.1.0.1

    Like

    1. The date logic on line 72 assumes the date is DD-MM-YYYY. My computer sees MM-DD-YYYY. So for July it computed January 7th, then went on to return 6 as the last day of the month. My solution was to change line 72 from “01-$Month-$Year” to “$Month-01-$Year”. I don’t know enough PowerShell scripting to do that in universal fashion, I’m sure there is a way. Other than that, my hats off to the original poster, this script is exactly what I needed.

      Like

  13. Hey Guys, this is some really cool stuff. I was looking around for python libraries and found some but for now I just want to get *all*¨my data in detail to slice and dice. This already works great, but I only get a limited period in my csv’s e.g. first 10 days of the month. Any ideas ? Sorry, I just moved, don’t have so much time right now to figure it out and if somebody has already the answer … Thanks. Points to the maker!

    Like

    1. Above is someone that had the same. Seems that if your localization settings are “month-day-year” instead of “day-month-year” the script only collects the first few days. They’ve given a solution for this as well.

      Like

      1. Wow, swift reply. Yes, I saw the discussion about the dates but I assumed (wrongly) that my regional settings where set to dd/mm/yyyy since I live in Belgium. I checked and it is set to mm/dd/yyyy indeed. And now I remember I had to change it to make sql server import/export wizard to import some other stuff correctly. (related to a bug but well) Thanks man, this will be the solution I’ll check it out and post.

        Like

  14. I think i found another way to change line 72 so it is independent of your local date format.
    Original code: $LastDayOfTheMonth = ((Get-Date -Date “01-$Month-$Year” -Hour 0 -Minute 0 -Second 0).AddMonths(1).AddSeconds(-1)).Day

    Change to: $LastDayOfTheMonth = ((Get-Date -Date “01-01-$Year” -Hour 0 -Minute 0 -Second 0).AddMonths($Month).AddSeconds(-1)).Day

    01-01 will be seen as the first day of the year as January 01 or 01 January depending on where you are, so no logic error. AddMonths($Month) will get you the first of the next month.

    Like

  15. I ran into Powershell’s default TLS 1 issue
    “Invoke-WebRequest : The request was aborted: Could not create SSL/TLS secure channel.”
    the solution is to add this to the script
    [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
    a
    ll credit to Cody Hosterman

    Like

  16. Hi,

    I have tried to change the script to collect the Power instead as I understand is on the AC side and Energy is och the DC side. But I don´t succeed and I have not many skills in programming.

    Like

  17. I’m a total powershell novice. Downloaded this some time back. Kept getting errors. Today I tried changing the output directory and in short order I got over 2 years of data; annual data, monthly data, daily data and data per month at 15min intervals. I still have little idea what I’m doing but will modify the script to suit my needs.
    Brilliant, thanks

    Like

  18. Hello, I have troubles using this script
    can connect fine to the solaredge api via excel’s power query but whenever I run this script nothing happens, policy is set to unrestricted and I’m running it outside any protected folder. All I can see is something flashing for a split second then back to the powershell prompt and of course no files have been downloaded

    Like

Leave a comment