Documentation ¶
Overview ¶
Package solaredge provides a client library for the SolarEdge Cloud-Based Monitoring Platform. The API gives access to data saved in the monitoring servers for your installed SolarEdge equipment and its performance (i.e. generated power & energy).
The implementation is based on SolarEdge's official API documentation.
The current version of this library implements the following sections of the API:
- Site Data API
- Site Equipment API
- API Versions
Access to SolarEdge data is determined by the user's API Key & installation. If your situation gives you access to the Accounts List, Meters or Sensors API, feel free to get in touch to get these implemented in this library.
Index ¶
- type APIRelease
- type Battery
- type BatteryEquipment
- type BatteryTelemetry
- type Client
- func (c *Client) GetComponents(ctx context.Context, id int) (GetComponentsResponse, error)
- func (c *Client) GetCurrentAPIVersion(ctx context.Context) (GetCurrentAPIVersionResponse, error)
- func (c *Client) GetDataPeriod(ctx context.Context, id int) (GetDataPeriodResponse, error)
- func (c *Client) GetEnergyDetails(ctx context.Context, id int, timeUnit TimeUnit, startTime, endTime time.Time) (GetEnergyDetailsResponse, error)
- func (c *Client) GetEnergyForTimeFrame(ctx context.Context, id int, startDate, endDate time.Time) (GetEnergyForTimeframeResponse, error)
- func (c *Client) GetEnergyMeasurements(ctx context.Context, id int, timeUnit TimeUnit, startDate time.Time, ...) (GetEnergyMeasurementsResponse, error)
- func (c *Client) GetEnvBenefits(ctx context.Context, id int) (GetEnvBenefitsResponse, error)
- func (c *Client) GetEquipmentChangeLog(ctx context.Context, id int, serialNr string) (GetEquipmentChangeLogResponse, error)
- func (c *Client) GetInventory(ctx context.Context, id int) (GetInventoryResponse, error)
- func (c *Client) GetInverterTechnicalData(ctx context.Context, id int, serialNr string, startTime, endTime time.Time) (GetInverterTechnicalDataResponse, error)
- func (c *Client) GetPowerDetails(ctx context.Context, id int, start, end time.Time) (GetPowerDetailsResponse, error)
- func (c *Client) GetPowerFlow(ctx context.Context, id int) (GetPowerFlowResponse, error)
- func (c *Client) GetPowerMeasurements(ctx context.Context, id int, startTime, endTime time.Time) (GetPowerMeasurementsResponse, error)
- func (c *Client) GetPowerOverview(ctx context.Context, id int) (GetPowerOverviewResponse, error)
- func (c *Client) GetSiteDetails(ctx context.Context, id int) (GetSiteDetailsResponse, error)
- func (c *Client) GetSites(ctx context.Context) (GetSitesResponse, error)
- func (c *Client) GetStorageData(ctx context.Context, id int, startTime, endTime time.Time) (GetStorageDataResponse, error)
- func (c *Client) GetSupportedAPIVersions(ctx context.Context) (GetSupportedAPIVersionsResponse, error)
- type CurrentPower
- type DataPeriod
- type Date
- type EnergyDetails
- type EnergyMeasurements
- type EnergyOverview
- type EnvBenefits
- type EquipmentChangeLog
- type Error
- type GatewayEquipment
- type GetComponentsResponse
- type GetCurrentAPIVersionResponse
- type GetDataPeriodResponse
- type GetEnergyDetailsResponse
- type GetEnergyForTimeframeResponse
- type GetEnergyMeasurementsResponse
- type GetEnvBenefitsResponse
- type GetEquipmentChangeLogResponse
- type GetInventoryResponse
- type GetInverterTechnicalDataResponse
- type GetPowerDetailsResponse
- type GetPowerFlowResponse
- type GetPowerMeasurementsResponse
- type GetPowerOverviewResponse
- type GetSiteDetailsResponse
- type GetSitesResponse
- type GetStorageDataResponse
- type GetSupportedAPIVersionsResponse
- type Inventory
- type Inverter
- type InverterEquipment
- type InverterTelemetry
- type InverterTelemetryL1Data
- type LifetimeEnergy
- type MeterEquipment
- type MeterReadings
- type PowerDetails
- type PowerFlow
- type PowerFlowReading
- type PowerMeasurements
- type PowerOverview
- type SensorEquipment
- type SiteDetails
- type SiteEnergyForTimeframe
- type Sites
- type StorageData
- type Time
- type TimeUnit
- type Value
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type APIRelease ¶
type APIRelease struct {
Release string `json:"release"`
}
type Battery ¶
type Battery struct { SerialNumber string `json:"serialNumber"` ModelNumber string `json:"modelNumber"` Telemetries []BatteryTelemetry `json:"telemetries"` Nameplate int `json:"nameplate"` TelemetryCount int `json:"telemetryCount"` }
Battery contains detailed storage information from batteries: the state of energy, power and lifetime energy.
type BatteryEquipment ¶
type BatteryEquipment struct { Name string `json:"name"` Manufacturer string `json:"manufacturer"` Model string `json:"model"` FirmwareVersion string `json:"firmwareVersion"` ConnectedInverterSn string `json:"connectedInverterSn"` SN string `json:"SN"` NameplateCapacity float64 `json:"nameplateCapacity"` }
BatteryEquipment contains a battery's name, model, manufacturer, serial number, etc.
type BatteryTelemetry ¶
type BatteryTelemetry struct { TimeStamp Time `json:"timeStamp"` Power float64 `json:"power"` BatteryState int `json:"batteryState"` LifeTimeEnergyCharged float64 `json:"lifeTimeEnergyCharged"` LifeTimeEnergyDischarged float64 `json:"lifeTimeEnergyDischarged"` FullPackEnergyAvailable float64 `json:"fullPackEnergyAvailable"` InternalTemp float64 `json:"internalTemp"` ACGridCharging float64 `json:"ACGridCharging"` }
type Client ¶
type Client struct { SiteKey string HTTPClient *http.Client // contains filtered or unexported fields }
func (*Client) GetComponents ¶
GetComponents returns a list of inverters/SMIs in the specific site.
func (*Client) GetCurrentAPIVersion ¶
func (c *Client) GetCurrentAPIVersion(ctx context.Context) (GetCurrentAPIVersionResponse, error)
GetCurrentAPIVersion returns the current API version used by the SolarEdge API server.
func (*Client) GetDataPeriod ¶
GetDataPeriod returns the energy production start and end dates of the site.
Note: unlike the example in the specs, this only returns the date, not the time of day.
func (*Client) GetEnergyDetails ¶
func (c *Client) GetEnergyDetails(ctx context.Context, id int, timeUnit TimeUnit, startTime, endTime time.Time) (GetEnergyDetailsResponse, error)
GetEnergyDetails returns site energy measurements from meters such as consumption, export (feed-in), import (purchase), etc. for a given time range and a specified time resolution.
timeUnit must be one of the following values: QUARTER_OF_AN_HOUR, HOUR, DAY, WEEK, MONTH, YEAR.
The server limits the time range depending on the chosen timeUnit:
- For QUARTER_OF_AN_HOUR and HOUR, the time range cannot exceed one month
- For DAY, the time range cannot exceed one year.
If these conditions are not met, an APIError is returned.
func (*Client) GetEnergyForTimeFrame ¶
func (c *Client) GetEnergyForTimeFrame(ctx context.Context, id int, startDate, endDate time.Time) (GetEnergyForTimeframeResponse, error)
GetEnergyForTimeFrame returns the site total energy produced for a given period.
Notes:
- This API only returns on-grid energy for the requested period. In sites with storage/backup, this may mean that results can differ from what appears in the Site Dashboard. Use the regular Site EnergyMeasurements API to obtain results that match the Site Dashboard calculation.
- The period between end and start must not exceed one year.
func (*Client) GetEnergyMeasurements ¶
func (c *Client) GetEnergyMeasurements(ctx context.Context, id int, timeUnit TimeUnit, startDate time.Time, endDate time.Time) (GetEnergyMeasurementsResponse, error)
GetEnergyMeasurements return the site energy measurements.
timeUnit must be one of the following values: QUARTER_OF_AN_HOUR, HOUR, DAY, WEEK, MONTH, YEAR.
The server limits the time range depending on the chosen timeUnit:
- For QUARTER_OF_AN_HOUR and HOUR, the time range cannot exceed one month
- For DAY, the time range cannot exceed one year.
If these conditions are not met, the call returns an error.
func (*Client) GetEnvBenefits ¶
GetEnvBenefits returns all environmental benefits based on site energy production: gas emissions saved, equivalent trees planted and light bulbs powered for a day.
func (*Client) GetEquipmentChangeLog ¶
func (c *Client) GetEquipmentChangeLog(ctx context.Context, id int, serialNr string) (GetEquipmentChangeLogResponse, error)
GetEquipmentChangeLog returns a list of equipment component replacements ordered by date. This method is applicable to inverters, optimizers, batteries and gateways.
func (*Client) GetInventory ¶
GetInventory the inventory of SolarEdge equipment in the site, including inverters/SMIs, batteries, meters, gateways and sensors.
func (*Client) GetInverterTechnicalData ¶
func (c *Client) GetInverterTechnicalData(ctx context.Context, id int, serialNr string, startTime, endTime time.Time) (GetInverterTechnicalDataResponse, error)
GetInverterTechnicalData returns specific inverter data for a given timeframe.
Notes:
- This API is limited to a one-week period. If the time range exceeds one week, an error is returned.
- this may not be fully complete, as data returned for my account doesn't match the specifications.
Example ¶
c := solaredge.Client{SiteKey: os.Getenv("SOLAREDGE_APIKEY")} ctx := context.Background() end := time.Now() start := end.Add(-1 * 24 * time.Hour) resp, err := c.GetSites(ctx) if err != nil { panic(err) } for _, site := range resp.Sites.Site { inventory, err := c.GetComponents(ctx, site.Id) if err != nil { panic(err) } for _, inverter := range inventory.Reporters.List { telemetry, err := c.GetInverterTechnicalData(ctx, site.Id, inverter.SerialNumber, start, end) if err != nil { fmt.Println(err.Error()) return } for _, entry := range telemetry.Data.Telemetries { fmt.Printf("%s - %s - %5.1f V - %4.1f ºC - %6.1f\n", inverter.Name, time.Time(entry.Time).String(), entry.DcVoltage, entry.Temperature, entry.TotalActivePower) } } }
Output:
func (*Client) GetPowerDetails ¶
func (c *Client) GetPowerDetails(ctx context.Context, id int, start, end time.Time) (GetPowerDetailsResponse, error)
GetPowerDetails returns site power measurements from meters such as consumption, export (feed-in), import (purchase), etc.
Note: This API is limited to one-month period. If the provided time range exceeds one month, an APIError is returned.
func (*Client) GetPowerFlow ¶
GetPowerFlow returns the current power flow between all elements of the site including PV array, storage (battery), loads (consumption) and grid.
TODO: test this during daytime
func (*Client) GetPowerMeasurements ¶
func (c *Client) GetPowerMeasurements(ctx context.Context, id int, startTime, endTime time.Time) (GetPowerMeasurementsResponse, error)
GetPowerMeasurements returns the site power measurements in 15 minute intervals.
Note: This API is limited to a one-month period. If the provided time range exceeds one month, an APIError is returned.
func (*Client) GetPowerOverview ¶
GetPowerOverview returns the energy produced at the site for its entire lifetime, current year, month and day (in Wh) and current power (in W).
Example ¶
ctx := context.Background() c := solaredge.Client{SiteKey: os.Getenv("SOLAREDGE_APIKEY")} resp, err := c.GetSites(ctx) if err != nil { panic(err) } for _, site := range resp.Sites.Site { resp, err := c.GetPowerOverview(ctx, site.Id) if err != nil { panic(err) } fmt.Printf("Site: %s\nLast update: %s\nCurrent power: %.1fW", site.Name, time.Time(resp.Overview.LastUpdateTime).String(), resp.Overview.CurrentPower.Power) }
Output:
func (*Client) GetSiteDetails ¶
GetSiteDetails returns the site details, such as name, location, status, etc.
func (*Client) GetSites ¶
func (c *Client) GetSites(ctx context.Context) (GetSitesResponse, error)
GetSites returns a list of sites related to the given SiteKey, which is the account api_key.
Note: the API accepts parameters for convenient search, sort and pagination, but this is currently not implemented. This means the result is limited to the first 100 sites registered under the SiteKey.
Example ¶
ctx := context.Background() c := solaredge.Client{SiteKey: os.Getenv("SOLAREDGE_APIKEY")} resp, err := c.GetSites(ctx) if err != nil { panic(err) } for _, site := range resp.Sites.Site { fmt.Printf("Site '%s' (%s), Peak Power: %.1f\n", site.Name, site.Status, site.PeakPower) }
Output:
func (*Client) GetStorageData ¶
func (c *Client) GetStorageData(ctx context.Context, id int, startTime, endTime time.Time) (GetStorageDataResponse, error)
GetStorageData returns detailed information from batteries installed at the active site.
This API is limited to a one-week period.
func (*Client) GetSupportedAPIVersions ¶
func (c *Client) GetSupportedAPIVersions(ctx context.Context) (GetSupportedAPIVersionsResponse, error)
GetSupportedAPIVersions returns all API versions supported by the SolarEdge API server.
type CurrentPower ¶
type CurrentPower struct {
Power float64 `json:"power"`
}
CurrentPower contains the current power output, as contained in PowerOverview
type DataPeriod ¶
type EnergyDetails ¶
type EnergyDetails struct { TimeUnit TimeUnit `json:"timeUnit"` Unit string `json:"unit"` Meters []MeterReadings `json:"meters"` }
EnergyDetails contains site energy measurements from meters such as consumption, export (feed-in), import (purchase), etc.
type EnergyMeasurements ¶
type EnergyOverview ¶
EnergyOverview contains the energy produced in PowerOverview
type EnvBenefits ¶
type EquipmentChangeLog ¶
type GatewayEquipment ¶
type GatewayEquipment struct { Name string `json:"name"` FirmwareVersion string `json:"firmwareVersion"` SN string `json:"SN"` }
GatewayEquipment contains a gateway's name, model, manufacturer, serial number, etc.
type GetComponentsResponse ¶
type GetCurrentAPIVersionResponse ¶
type GetCurrentAPIVersionResponse struct {
Version APIRelease `json:"version"`
}
type GetDataPeriodResponse ¶
type GetDataPeriodResponse struct {
DataPeriod DataPeriod `json:"dataPeriod"`
}
type GetEnergyDetailsResponse ¶
type GetEnergyDetailsResponse struct {
EnergyDetails EnergyDetails `json:"energyDetails"`
}
type GetEnergyForTimeframeResponse ¶
type GetEnergyForTimeframeResponse struct {
TimeFrameEnergy SiteEnergyForTimeframe `json:"timeFrameEnergy"`
}
type GetEnergyMeasurementsResponse ¶
type GetEnergyMeasurementsResponse struct {
Energy EnergyMeasurements `json:"energy"`
}
type GetEnvBenefitsResponse ¶
type GetEnvBenefitsResponse struct {
EnvBenefits EnvBenefits `json:"envBenefits"`
}
type GetEquipmentChangeLogResponse ¶
type GetEquipmentChangeLogResponse struct { ChangeLog struct { List []EquipmentChangeLog `json:"list"` Count int `json:"count"` } `json:"ChangeLog"` }
type GetInventoryResponse ¶
type GetInventoryResponse struct {
Inventory Inventory `json:"inventory"`
}
type GetInverterTechnicalDataResponse ¶
type GetInverterTechnicalDataResponse struct { Data struct { Telemetries []InverterTelemetry `json:"telemetries"` Count int `json:"count"` } `json:"data"` }
type GetPowerDetailsResponse ¶
type GetPowerDetailsResponse struct {
PowerDetails PowerDetails `json:"powerDetails"`
}
type GetPowerFlowResponse ¶
type GetPowerFlowResponse struct {
CurrentPowerFlow PowerFlow `json:"siteCurrentPowerFlow"`
}
type GetPowerMeasurementsResponse ¶
type GetPowerMeasurementsResponse struct {
Power PowerMeasurements `json:"power"`
}
type GetPowerOverviewResponse ¶
type GetPowerOverviewResponse struct {
Overview PowerOverview `json:"overview"`
}
type GetSiteDetailsResponse ¶
type GetSiteDetailsResponse struct {
Details SiteDetails `json:"details"`
}
type GetSitesResponse ¶
type GetStorageDataResponse ¶
type GetStorageDataResponse struct {
StorageData StorageData `json:"storageData"`
}
type GetSupportedAPIVersionsResponse ¶
type GetSupportedAPIVersionsResponse struct {
Supported []APIRelease `json:"supported"`
}
type Inventory ¶
type Inventory struct { Batteries []BatteryEquipment `json:"batteries"` Gateways []GatewayEquipment `json:"gateways"` Inverters []InverterEquipment `json:"inverters"` Meters []MeterEquipment `json:"meters"` Sensors []SensorEquipment `json:"sensors"` }
Inventory contains all batteries, gateways, inverters, meters and sensors at a site.
type Inverter ¶
type Inverter struct { Manufacturer string `json:"manufacturer"` Model string `json:"model"` Name string `json:"name"` SerialNumber string `json:"serialNumber"` }
Inverter contains an inverter's name, model, manufacturer and serial number, as returned by GetInverters.
type InverterEquipment ¶
type InverterEquipment struct { SN string `json:"SN"` CommunicationMethod string `json:"communicationMethod"` CPUVersion string `json:"cpuVersion"` Manufacturer string `json:"manufacturer"` Model string `json:"model"` Name string `json:"name"` ConnectedOptimizers int `json:"connectedOptimizers"` }
InverterEquipment contains an inverter's name, model, manufacturer, serial number, etc. as returned by GetEquipment.
type InverterTelemetry ¶
type InverterTelemetry struct { Time Time `json:"date"` InverterMode string `json:"inverterMode"` L1Data InverterTelemetryL1Data `json:"L1Data"` DcVoltage float64 `json:"dcVoltage"` GroundFaultResistance float64 `json:"groundFaultResistance,omitempty"` OperationMode int `json:"operationMode"` PowerLimit float64 `json:"powerLimit"` Temperature float64 `json:"temperature"` TotalActivePower float64 `json:"totalActivePower"` TotalEnergy float64 `json:"totalEnergy"` }
InverterTelemetry contains technical data for an inverter.
type InverterTelemetryL1Data ¶
type InverterTelemetryL1Data struct { AcCurrent float64 `json:"acCurrent"` AcFrequency float64 `json:"acFrequency"` AcVoltage float64 `json:"acVoltage"` ActivePower float64 `json:"activePower"` ApparentPower float64 `json:"apparentPower"` CosPhi float64 `json:"cosPhi"` ReactivePower float64 `json:"reactivePower"` }
type LifetimeEnergy ¶
type MeterEquipment ¶
type MeterEquipment struct { Name string `json:"name"` Manufacturer string `json:"manufacturer"` Model string `json:"model"` FirmwareVersion string `json:"firmwareVersion"` ConnectedSolarEdgeDeviceSN string `json:"connectedSolaredgeDeviceSN"` Type string `json:"type"` Form string `json:"form"` }
MeterEquipment contains an meter's name, model, manufacturer, serial number, etc.
type MeterReadings ¶
MeterReadings contains power measurements for a type of meter.
type PowerDetails ¶
type PowerDetails struct { TimeUnit TimeUnit `json:"timeUnit"` Unit string `json:"unit"` Meters []MeterReadings `json:"meters"` }
type PowerFlow ¶
type PowerFlow struct { Unit string `json:"unit"` Connections []struct { From string `json:"from"` To string `json:"to"` } `json:"connections"` Grid PowerFlowReading `json:"GRID"` Load PowerFlowReading `json:"LOAD"` PV PowerFlowReading `json:"PV"` Storage struct { Status string `json:"status"` CurrentPower float64 `json:"currentPower"` ChargeLevel float64 `json:"chargeLevel"` Critical bool `json:"critical"` } `json:"STORAGE"` }
PowerFlow contains current power flow between all elements of the site including PV array, storage (battery), loads (consumption) and grid.
type PowerFlowReading ¶
type PowerFlowReading struct { Status string `json:"status"` CurrentPower float64 `json:"currentPower"` }
PowerFlowReading contains the current power flow for one element of the site.
type PowerMeasurements ¶
type PowerOverview ¶
type PowerOverview struct { LastUpdateTime Time `json:"lastUpdateTime"` LifeTimeData EnergyOverview `json:"lifeTimeData"` LastYearData EnergyOverview `json:"lastYearData"` LastMonthData EnergyOverview `json:"lastMonthData"` LastDayData EnergyOverview `json:"lastDayData"` CurrentPower CurrentPower `json:"currentPower"` }
type SensorEquipment ¶
type SensorEquipment struct { ConnectedSolarEdgeDeviceSN string `json:"connectedSolaredgeDeviceSN"` ID string `json:"id"` ConnectedTo string `json:"connectedTo"` Category string `json:"category"` Type string `json:"type"` }
SensorEquipment contains an sensor's name, model, manufacturer, serial number, etc.
type SiteDetails ¶
type SiteDetails struct { LastUpdateTime Date `json:"lastUpdateTime"` InstallationDate Date `json:"installationDate"` PtoDate *Date `json:"ptoDate"` Location struct { Country string `json:"country"` City string `json:"city"` Address string `json:"address"` Address2 string `json:"address2"` Zip string `json:"zip"` TimeZone string `json:"timeZone"` CountryCode string `json:"countryCode"` } `json:"location"` Uris struct { SITEIMAGE string `json:"SITE_IMAGE"` DATAPERIOD string `json:"DATA_PERIOD"` DETAILS string `json:"DETAILS"` OVERVIEW string `json:"OVERVIEW"` } `json:"uris"` Name string `json:"name"` Status string `json:"status"` Notes string `json:"notes"` Type string `json:"type"` PrimaryModule struct { ManufacturerName string `json:"manufacturerName"` ModelName string `json:"modelName"` MaximumPower float64 `json:"maximumPower"` } `json:"primaryModule"` Id int `json:"id"` AccountId int `json:"accountId"` PeakPower float64 `json:"peakPower"` PublicSettings struct { IsPublic bool `json:"isPublic"` } `json:"publicSettings"` }
type SiteEnergyForTimeframe ¶
type SiteEnergyForTimeframe struct { StartLifetimeEnergy LifetimeEnergy `json:"startLifetimeEnergy"` EndLifetimeEnergy LifetimeEnergy `json:"endLifetimeEnergy"` Unit string `json:"unit"` MeasuredBy string `json:"measuredBy"` Energy float64 `json:"energy"` }
type Sites ¶
type Sites []SiteDetails
func (Sites) FindByID ¶
func (s Sites) FindByID(id int) (SiteDetails, bool)
FindByID returns the SiteDetails with the specified ID. Returns false if the SiteDetails could not be found.
func (Sites) FindByName ¶
func (s Sites) FindByName(name string) (SiteDetails, bool)
FindByName returns the SiteDetails with the specified name. Returns false if the SiteDetails could not be found.