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)

Tags: , , , , ,

29 responses to “Download SolarEdge solar production data and save to csv”

  1. bogdan says :

    how can this tool be used?

    Like

  2. bogdan says :

    how can this tool be used? thanks!

    Like

  3. Chrissy says :

    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

  4. cpsross says :

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

    Like

  5. Stu says :

    This is really good, is there a way to get export and self consumption data also?

    Like

    • Powershell Administrator says :

      Thank you. As far as I know, this isn’t possible, as SolarEdge doesn’t offer this in their API. But you can check it for yourself in their API documentation over here: https://www.solaredge.com/sites/default/files/se_monitoring_api.pdf

      Like

      • Stuart Evans says :

        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

  6. Powershell Administrator says :

    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

    • ebj says :

      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

  7. EBJ says :

    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

    • EBJ says :

      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

      • Powershell Administrator says :

        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

  8. ebj says :

    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

    • Powershell Administrator says :

      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

  9. EBJ says :

    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

  10. EBJ says :

    SolarEdge provide a new API key. Where can I find the output files, what are the file names.

    Like

  11. EBJ says :

    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

    • Powershell Administrator says :

      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

  12. EBJ says :

    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

  13. EBJ says :

    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

  14. EBJ says :

    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

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: