Analytics: get_analytics
One request per Analytics screen state (period tab, date, device selector).
The reply carries everything that screen draws: the energy summary with its
Production / Consumption breakdown, the chart series (with a revenue figure
per bar), whether any inverter is missing, the money estimate, where stored
data starts, and — for period: "total" — Operation Statistics. Design background, storage and scaling: Analytics design.
// → client
{"type": "get_analytics", "requestId": "c1",
"userId": "17833b2e-a851-4a17-a764-62524d667959",
"plantId": "01M3C8579CXH495CV2MPJ083PT",
"period": "day", "date": "2025-08-12",
"timezone": "Asia/Karachi",
"rates": {"currency": "PKR", "buy": 65.0, "export": 40.0}}
| Field | Meaning |
|---|---|
plantId | The plant. "all" is refused. Omit it (with a deviceKey) for the device-only scope: one inverter you own, whether or not it has a plant. The per-inverter Historical Data screen uses this. Its reply has scope.plantId: "". plantId or deviceKey is required. |
deviceKey | Omit (or "") for the whole plant, aggregated server-side. A device id narrows to that inverter; it must be one of your devices in this plant, otherwise the reply is device_not_in_plant (the same answer whether it exists or not). In the device-only scope (no plantId), a device that isn't yours is device_not_found. |
scope | Optional. "combined" (the whole plant's parallel group — needs plantId, no deviceKey) or "individual" (one inverter — needs deviceKey). Omitted, the scope is inferred from plantId/deviceKey exactly as described above. The reply's scope.kind says which it was; a combined reply also lists scope.members, and scope.parallelSets when paralleled IP20 units were counted once per set (with a PARALLEL_SET_COMBINED notice, and each set counting as one inverter in completeness). See Parallel inverters. |
view | "inverter" (default) or "battery". The battery is not a separate device: "battery" needs the deviceKey of the inverter it hangs off, and returns only battery charge/discharge energy, battery power and SOC. Smart meters are not supported. |
period | "day" + date (YYYY-MM-DD) · "month" + month (YYYY-MM) · "year" + year ("YYYY"; a JSON number such as 2025 is accepted too) · "total" (no date field: one bar per calendar year, grain: "year", point date "YYYY", from the first year with stored energy to today) · "custom" + from/to (YYYY-MM-DD, inclusive, from the calendar). A period may not start in the future; the current month or year is clipped to today ("1–12 Aug so far"). A custom range may not end after today and is at most 5 years. |
timezone | The user's saved IANA zone name ("Asia/Karachi"), never an offset like "+05:00". It decides where every local day starts. The server also remembers it per plant for the nightly rollup (not retroactive: already-finalised days keep the zone they were computed in). |
rates | The plant's saved rates. buy and export are numbers ≥ 0 (per kWh) or null when not set; currency is echoed back. Omit rates entirely for no money estimate. Rates apply to the whole period (today's rate, not a historical one). |
requestId | Echoed on the reply. Useful because a user can tap through periods faster than replies arrive — drop replies whose requestId is not the latest. |
// ← server
{"type": "analytics", "ok": true, "requestId": "c1",
"scope": {"plantId": "01M3C8579CXH495CV2MPJ083PT", "deviceKey": null, "view": "inverter"},
"period": {"kind": "day", "from": "2025-08-12", "to": "2025-08-12", "timezone": "Asia/Karachi",
"grain": "15m", "isCurrent": true, "complete": false},
"capabilities": {"generation": true, "load": true, "gridImport": true, "gridExport": true,
"battery": true, "batteryPower": true, "gridPower": true, "batterySoc": true},
"summary": {"generatedKwh": 51.4, "consumedKwh": 33.8, "gridImportKwh": 4.2, "gridExportKwh": 12.4,
"batteryChargeKwh": 15.2, "batteryDischargeKwh": 9.8, "selfUsedKwh": 39.0,
"peakPvW": 11060, "peakPvAt": "2025-08-12T07:45:00Z", "best": null,
"production": {"toLoadKwh": 19.6, "toBatteryKwh": 15.2, "toGridKwh": 12.4},
"consumption": {"fromSolarKwh": 19.6, "fromBatteryKwh": 9.8, "fromGridKwh": 4.2}},
"series": {"grain": "15m", "unit": "W", "points": [
{"t": "2025-08-11T19:00:00Z", "pv": 0, "load": 812, "batteryCharge": 0, "batteryDischarge": 640,
"gridImport": 172, "gridExport": 0, "soc": 81.5}]},
"completeness": {"partial": true, "devicesExpected": 2, "devicesReporting": 1,
"missing": [{"deviceKey": "16fd2706-8baf-433b-82eb-8c7fada847da", "lastSampleAt": "2025-08-12T06:42:00Z"}]},
"financial": {"currency": "PKR", "selfUsedKwh": 39.0, "savings": 2535.0, "exportCredit": 496.0, "total": 3031.0},
"dataAsOf": "2025-08-12T09:39:00Z",
"dataStartsAt": "2025-03-14T04:10:00Z",
"unavailable": [],
"notices": []}
A day / month / year point (month, year, total and custom grains) carries a
revenue beside its energy:
{"date": "2025-08-01", "generated": 44.1, "consumed": 30.2, "gridImport": 3.9,
"gridExport": 10.8, "batteryCharge": 14.0, "batteryDischarge": 9.1, "revenue": 2569.5}
period: "total" adds Operation Statistics:
"lifetime": {"since": "2026-06-15", "runningDays": 116,
"generatedKwh": 2406.77, "gridExportKwh": 773.85,
"co2KgPerKwh": 0.5, "co2AvoidedKg": 1203.4,
"co2KgPerTree": 21.77, "treesEquivalent": 55,
"financial": {"currency": "PKR", "selfUsedKwh": 1632.92, "savings": 106139.8,
"exportCredit": 30954.0, "total": 137093.8}}
Rules the app can rely on:
nullmeans "not reported" or "not supported";0is a real zero. A metric no in-scope inverter can report at all isnulleverywhere and itscapabilitiesflag isfalse— hide it (screen 39d: no export tile, no Export chip, no export credit). A capability that istruebut a value that isnullmeans no data for that slot or day: draw a gap, never 0.- Capabilities describe the inverter, not the period: they are identical
on every period tab for the same scope. A flag is
falsewhen the model cannot report the metric, or when the inverter's last ~day of readings (288) never carried it — e.g. a standalone IP20, which refuses the parallel-system register bank its energy counters live in, or an Aotai whose energy meter is offline. An inverter with no recent readings falls back to its model. Stored data never turns a flag on, so a flow the inverter has since stopped reporting (a meter removed) is hidden on past periods too. - Units are base units: W for the 15-minute series, kWh everywhere else,
% for SOC. Energy is rounded to 0.01 kWh and power to 1 W. Every
timestamp is UTC with a
Zsuffix (t,peakPvAt,dataAsOf,dataStartsAt,missing[].lastSampleAt,notices[].from); format them inperiod.timezone. - No series value is negative.
pvandloadare one-way flows; a reading just below 0 W (sensor noise at no load) is sent as 0. Battery and grid are already split into separate non-negative series. series.grain:"15m"(unit W) for a day, or a custom range of one day — one point per 15-minute slot that has data,t= slot start, grid import and export as separate non-negative series (draw import solid, export dashed)."day"(unit kWh) for a month or a custom range up to 92 days — one point per local date,date= YYYY-MM-DD, including days with no data (nulls)."month"for a year or a longer custom range —date= YYYY-MM.summary.best: the best day ("day"grain) or best month ("month"grain) by generation,{date, generatedKwh};nullfor a day.summary.peakPvWis set for a day ("Peak solar");peakPvAtisnullwhen the peak is 0 W (nothing generated, so no moment of peak).socis filled in the 15-minute points of both views whenevercapabilities.batterySocistrue.summary.production/summary.consumption(inverter view, every period; absent in the battery view) split the period's energy:production= where the generation went (toLoadKwh,toBatteryKwh,toGridKwh),consumption= where the load's energy came from (fromSolarKwh,fromBatteryKwh,fromGridKwh). The three parts add up togeneratedKwh(and toconsumedKwh) exactly, at 0.01 kWh whenever every in-scope inverter measures battery and grid. To battery / to grid and from battery / from grid are measured: computed per 15-minute slot (solar serves the load first, then charges the battery, then exports; the load draws on solar, then the battery, then the grid), scaled to the inverter's own energy counters and never more than the battery or grid actually measured. To load and from solar are the remainder (generatedKwh − toBattery − toGrid,consumedKwh − fromBattery − fromGrid), so they absorb conversion losses and are not always equal to each other. Anulltotal makes every partnull: a part is never sent beside a missing total. A part isnullwhen an in-scope model cannot measure it — an IP20 has no battery power, so only to load / from solar is known, as the measured allocation, and then the parts do not add up — or when the period includes a day that moved energy but was stored before this breakdown existed (the last 4 months can be recomputed). On a mixed plant where only some inverters measure a part,coveragekeysproduction.toBatteryKwhetc. say so, and to load / from solar stay the measured allocation rather than a remainder.revenueon each day / month / year point is that bar's money estimate, priced exactly likefinancial(self-used × buy + export × export rate).nullwhereverfinancialwould be: device scope, battery view,ratesomitted or both ratesnull, or no energy on that bar.lifetime(period: "total", inverter view only) is Operation Statistics, built from the same stored history as the Total reply'ssummary— not from the inverters' own lifetime counters — so the screen never shows two different total-production figures:generatedKwh=summary.generatedKwh,gridExportKwh=summary.gridExportKwh. Its numbers are nevernull: no data is0.co2AvoidedKg = generatedKwh × co2KgPerKwhandtreesEquivalent = ⌊co2AvoidedKg ÷ co2KgPerTree⌋; both factors are set on the server so every client shows the same figure, and are echoed.sinceis the local date of the first stored sample (nullbefore any) andrunningDayscounts from it, today included (0before any) — neither model exposes a running-time register.lifetime.financialis the profit estimate, the same as the Total reply'sfinancial(plant scope withratesonly).dataStartsAtis the earliest stored sample of any in-scope inverter (nullif none).- A period that starts before it but ends after carries a notice,
notices: [{"code": "NO_DATA_BEFORE", "from": "<dataStartsAt>"}]: its chart is there, and the bars beforefromare "nothing stored", not "produced nothing". - A period that ends before it — or anything when nothing is stored
at all — carries
unavailable: [{"block": "all", "reason": "NO_DATA"}]and is not an outage:completeness.partialisfalseandmissingis empty.
- A period that starts before it but ends after carries a notice,
noticesis always an array (usually empty). A notice qualifies data that is present;unavailablesays a block is missing.completenesscounts inverters. While the period includes today, an inverter is reporting if it was seen in the last 15 minutes; for a past period, if it recorded anything in it.partial: truedrives the "Data May Be Incomplete" banner;missing[].lastSampleAtis "stopped reporting at 11:42 AM": for the current period the last time the inverter was seen, for a finished period its last reading at or before the period's end (nullif it had none). Totals then cover the inverters that did report.coverage(present only when needed) says a plant figure covers only some of its inverters because the others' model cannot report it, e.g.{"gridExportKwh": {"devices": 1, "of": 2}}. The figure is the sum of those that can.financialis plant scope only (nullfor a single device or the battery view, and whenratesis omitted).savings = selfUsedKwh × buy,exportCredit = gridExportKwh × export,total= the sum of the non-null parts. Anullrate makes its figurenull: show "Set electricity rate ›" / "Set export rate ›" and draw nothing for it — never PKR 0 (screen 39e).selfUsedKwhis generated − exported (all generation when export is not reported). These are estimates, not a bill.unavailablelists blocks the server could not fill, with a reason:{"block": "series", "reason": "PERIOD_OUTSIDE_RETENTION"}for a day older than 4 months (its totals still come back; only the 15-minute chart is gone),{"block": "all", "reason": "MODEL_NOT_SUPPORTED"}when none of the in-scope inverters' models reports energy (no current model: the IP20 3K6/5K reports energy since 2026-11-23),{"block": "series", "reason": "NO_READINGS"}for a day inside the 4 months that has no stored 15-minute readings (its totals may still be there — draw "No detailed data for this day"), and theNO_DATAblock above. One reply carries at most oneseriesblock.last7Daysis no longer sent (the app stopped using it).
Errors come back as {"type": "analytics", "ok": false, "requestId": ..., "code": ..., "error": ...}:
code | Meaning |
|---|---|
invalid_request | Missing userId/plantId, a userId that is not a UUID, plantId: "all", a malformed id, an unknown view, view: "battery" without deviceKey, a plant with more inverters than GROUP_MAX_INVERTERS (default 50), a scope that contradicts plantId/deviceKey, or a frame that is not valid for get_analytics at all (for example rates.buy sent as a string) — that last case still echoes your requestId |
invalid_period | Unknown period, a malformed date, a future period, a reversed or over-long custom range |
invalid_timezone | Missing, "Local", an offset, not a known IANA zone, or a zone the analytics database's own tzdata does not have |
invalid_rates | A negative, non-finite or absurd (> 10,000/kWh) rate, or a currency that is not 3 capital letters |
device_not_in_plant | deviceKey is not one of this user's devices in this plant |
device_not_found | Device-only scope: deviceKey is not one of this user's devices |
busy | Another get_analytics is still running on this connection (answered immediately), or the gateway stayed at its concurrent-analytics limit for the whole 5 s budget (a request waits for a free slot first) — retry shortly |
timeout | The query did not finish in 5 s |
unavailable | No device database, or the analytics schema is not migrated yet — including the short window during a deploy when the gateway is newer than the database. Retry shortly |
internal | Anything else. The message is a fixed "analytics query failed"; the details are logged server-side only |
A plant you own no device in is not an error: it returns an ok: true
reply with devicesExpected: 0 and every figure null.
Freshness. Stored telemetry is every 5 minutes, so today's figures
trail real time by up to one interval (dataAsOf says how far). Past days
are finalised 30 minutes after local midnight and re-checked at +6 h and
+24 h, so a figure for yesterday can still rise slightly early the next
morning if an inverter was catching up.