API Measurements cookbook
Measurements cookbook
Section titled “Measurements cookbook”This guide explains how to use the public measurements API, how to interpret metric metadata, and how to calculate common customer-facing values from returned rows.
Use the measurements API for new integrations
Section titled “Use the measurements API for new integrations”Preferred endpoints:
GET /api/v1.25f/devicesGET /api/v1.25f/metricsGET /api/v1.25f/devices/{device_id}/metricsPOST /api/v1.25f/measurementsGET /api/v1.25f/queries/{query_id}/statusGET /api/v1.25f/queries/{query_id}/result
Legacy endpoints ending in .json are deprecated and should not be used for new work:
GET /api/v1.25f/devices/list.jsonGET /api/v1.25f/devices/consumption.jsonGET /api/v1.25f/objects/list.json
Typical workflow
Section titled “Typical workflow”- Discover devices with
GET /devices - Discover metric definitions with
GET /metrics - Check the metrics that actually exist on one device with
GET /devices/{device_id}/metrics - Submit a query with
POST /measurements - Poll with
GET /queries/{query_id}/status - Read rows with
GET /queries/{query_id}/result - Apply the formula that matches the metric family
Practical limits
Section titled “Practical limits”Current measurements API limits:
- maximum time range: 5 days
- maximum devices per query: 5
- maximum metrics per query: 5
- minimum time range: none
Short windows such as 5, 15, or 30 minutes are supported. That is useful for onboarding, debugging, and formula validation.
Discover the right IDs first
Section titled “Discover the right IDs first”List devices
Section titled “List devices”GET /api/v1.25f/devices
Example response:
{ "devices": [ { "device_id": 210404, "name": "Main Feed - Building 3", "device_type": "gridmate", "is_active": true, "object_id": 31021, "object_name": "Riga Plant - Building 3" }, { "device_id": 210405, "name": "Solar Inverter - Roof A", "device_type": "gridlink", "is_active": true, "object_id": 31021, "object_name": "Riga Plant - Building 3" } ]}List metric definitions
Section titled “List metric definitions”GET /api/v1.25f/metrics
Example response:
{ "metrics": [ { "metric_id": 4007, "name": "gridmate_total_pos_active_energy_wh", "unit": "Wh", "data_type": "COUNTER", "description": "Gridmate per-phase positive active energy counter.", "is_phased": true, "phase_behavior": "phases_1_3_with_legacy_phase_4", "recommended_phase_handling": "group_by_phases_1_3_ignore_4_by_default", "aggregation_guidance": [ { "agg_fn": "SUM", "description": "Sum energy deltas" } ] }, { "metric_id": 7001, "name": "gridlink_voltage_histogram", "unit": "V", "data_type": "SUMMARY", "description": "Gridlink voltage distribution histogram.", "is_phased": true, "phase_behavior": "phases_1_3_only", "recommended_phase_handling": "group_by_phases_1_3", "aggregation_guidance": [ { "agg_fn": "SUM", "description": "Merge histograms by summing bucket counts" } ], "complex_payload_type": "voltage_histogram" } ]}List metrics for one device
Section titled “List metrics for one device”GET /api/v1.25f/devices/{device_id}/metrics
This is the best starting point for a real query because it tells you which metrics are present on that device, which phases can appear, and how the metric should be interpreted.
Example response:
{ "device_id": 210404, "metrics": [ { "metric_id": 4001, "name": "gridmate_rms_voltage_v", "unit": "V", "data_type": "GAUGE", "available_phases": ["1", "2", "3", "4"], "is_phased": true, "phase_behavior": "phases_1_3_with_legacy_phase_4", "recommended_phase_handling": "group_by_phases_1_3_ignore_4_by_default", "aggregation_guidance": [ { "agg_fn": "AVG", "description": "Time-weighted average RMS voltage" } ] }, { "metric_id": 7001, "name": "gridlink_voltage_histogram", "unit": "V", "data_type": "SUMMARY", "available_phases": ["1", "2", "3"], "is_phased": true, "phase_behavior": "phases_1_3_only", "recommended_phase_handling": "group_by_phases_1_3", "aggregation_guidance": [ { "agg_fn": "SUM", "description": "Merge histograms by summing bucket counts" } ], "complex_payload_type": "voltage_histogram" } ]}How to use the metric metadata
Section titled “How to use the metric metadata”Every metric definition now includes interpretation fields that are meant to be used directly by clients.
is_phased
Section titled “is_phased”true: the metric normally has per-phase rowsfalse: the metric should be treated as one non-phased series
phase_behavior
Section titled “phase_behavior”Current values:
non_phasedphases_1_3_onlyphases_1_3_with_legacy_phase_4
recommended_phase_handling
Section titled “recommended_phase_handling”Current values:
do_not_group_by_phasegroup_by_phases_1_3group_by_phases_1_3_ignore_4_by_default
If you are building default customer-facing behavior, use recommended_phase_handling instead of inventing your own rule.
aggregation_guidance
Section titled “aggregation_guidance”This comes from the metric definition source data and tells you which aggregation rule matches the metric family.
Examples:
AVG: time-weighted average voltage, current, temperature, or powerSUM: energy deltas or merged histogramsMAX: peak-style metricsNONE: point-in-time structured payloads such as fuse states
complex_payload_type
Section titled “complex_payload_type”Present only when the metric returns val_complex.
Current values:
fuse_state_arrayvoltage_histogram
Submit a measurements query
Section titled “Submit a measurements query”Example: short counter query using default quality handling
Section titled “Example: short counter query using default quality handling”{ "type": "timeseries", "device_ids": [210404], "metric_ids": [4007], "time_from": "2026-01-15T10:00:00Z", "time_to": "2026-01-15T10:15:00Z"}Because quality_filter is omitted, this request uses the default quality_filter=ok.
Example: explicit per-phase gauge query
Section titled “Example: explicit per-phase gauge query”{ "type": "timeseries", "device_ids": [210404], "metric_ids": [4001], "time_from": "2026-01-15T10:00:00Z", "time_to": "2026-01-15T10:30:00Z", "phase_filter": 1, "quality_filter": "ok"}Query defaults that matter
Section titled “Query defaults that matter”Default quality handling
Section titled “Default quality handling”If you omit quality_filter, the API uses:
"quality_filter": "ok"Use this default for business calculations.
Request not-ok only when you are inspecting bad rows.
Request all only when you intentionally want both good and bad rows.
Default phase handling
Section titled “Default phase handling”If you omit phase_filter, the API returns:
- phase
1 - phase
2 - phase
3 - non-phased rows with empty phase
""
If a metric has legacy phase 4, it is excluded by default.
Phase 4 is returned only when you explicitly request:
"phase_filter": 4Poll for completion
Section titled “Poll for completion”Submission returns:
{ "query_id": "0196291a-0931-7d5d-8b7d-4f0d6c0f1a2b"}Then poll:
GET /api/v1.25f/queries/{query_id}/statusGET /api/v1.25f/queries/{query_id}/result
States:
preparingrunningdoneerrornone
How to interpret a measurement row
Section titled “How to interpret a measurement row”Counter-style row example
Section titled “Counter-style row example”{ "device_id": 210404, "metric_id": 4007, "phase": "1", "measurement_time": "2026-01-15T10:15:00Z", "val_rate": 0.0002777778, "val_counter": 15234.5, "validity_sec": 900, "val_complex": null, "quality_status": "ok", "quality_flags": []}Gauge-style row example
Section titled “Gauge-style row example”{ "device_id": 210404, "metric_id": 4001, "phase": "1", "measurement_time": "2026-01-15T10:15:00Z", "val_rate": 229.8, "val_counter": null, "validity_sec": 900, "val_complex": null, "quality_status": "ok", "quality_flags": []}Field meaning:
device_id: device identifiermetric_id: metric identifierphase:"","1","2","3", or sometimes legacy"4"measurement_time: interval end timestampval_rate:- gauge value for
GAUGE - normalized delta per second for
COUNTER
- gauge value for
val_counter: raw cumulative counter value forCOUNTERvalidity_sec: duration covered by the rowval_complex: structured payload for supportedSUMMARYmetricsquality_status:okornot-okquality_flags: row-level quality details
Two rules matter most:
- Never sum
val_counter - For interval totals, use
val_rate * validity_sec
val_counteris the running total at the end of the interval. If you sum multiple rows, you count the same historical energy again and again.val_rateforCOUNTERrows is already normalized to per-second change. Multiplying byvalidity_secreconstructs the amount that actually belongs to that interval.- The sum covers only the intervals represented by returned rows. Missing or quality-filtered data must not be treated as zero consumption or as complete period coverage.
Example:
- row at
10:15withval_counter=15234.5andval_rate=0.0002777778,validity_sec=900means the interval contributed0.25 Wh - row at
10:30withval_counter=15234.8andval_rate=0.0003333333,validity_sec=900means the interval contributed0.30 Wh
Correct total: 0.25 + 0.30 = 0.55 Wh
Incorrect total: 15234.5 + 15234.8 because those numbers are cumulative readings, not interval consumption
How to think about phases
Section titled “How to think about phases”Normal electrical phases
Section titled “Normal electrical phases”Most customer-facing electrical analysis should use:
- phase
1 - phase
2 - phase
3
Non-phased metrics
Section titled “Non-phased metrics”Non-phased metrics use:
- empty phase
""
Do not group those rows by phase.
Phase 4
Section titled “Phase 4”Some Gridlink and Gridmate metrics can expose phase 4 in legacy raw data.
Treat phase 4 as redundant legacy channel data, not as a physical fourth electrical phase.
Safe default:
- use phases
1,2, and3 - ignore phase
4unless you explicitly need legacy raw-channel analysis - do not sum phase
4together with phases1,2, and3in normal customer calculations
Phase 4 is not an extra customer-facing electrical leg. Including it in default totals can duplicate information and overstate results.
data_type and calculation rules
Section titled “data_type and calculation rules”Examples:
- voltage
- current
- active power
- temperature
Use val_rate as the interval value.
A GAUGE row describes the measured level during that interval. There is no cumulative reading to unwrap, so customer calculations should start from the reported gauge value and then apply the metric-specific aggregation rule such as weighted average, max, or energy integration.
COUNTER
Section titled “COUNTER”Examples:
- positive active energy
- negative active energy
- pulse counters
Use:
val_counteras the raw cumulative readingval_rate * validity_secas the interval delta
val_counter is useful for audit, debugging, and showing the meter reading itself. It is not the interval total. The interval total is the change during the covered time, and the API already exposes that change as normalized val_rate, which must be multiplied back by validity_sec.
SUMMARY
Section titled “SUMMARY”Examples:
- fuse state arrays
- voltage histograms
Use val_complex.
Check complex_payload_type before decoding.
These metrics are structured payloads, not scalar values. They cannot be interpreted with the counter or gauge formulas.
Typed val_complex payloads
Section titled “Typed val_complex payloads”Fuse state payload
Section titled “Fuse state payload”Metrics with complex_payload_type=fuse_state_array return an array:
[1, 1, 1, 0, 1, 1, 0, 0]Interpretation:
- each array entry is one fuse position
1means closed or on0means open or off
These payloads are snapshots. They are not normally aggregated over time.
Why not aggregate them with averages or sums: the payload answers a state question, not an energy or level question. For example, summing two fuse-state arrays does not produce a meaningful electrical measurement.
Voltage histogram payload
Section titled “Voltage histogram payload”Metrics with complex_payload_type=voltage_histogram return an object:
{ "min": 220, "max": 224, "total_count": 50, "buckets": [ { "label": "220-221", "min": 220, "max": 221, "count": 10 }, { "label": "221-222", "min": 221, "max": 222, "count": 20 }, { "label": "222-223", "min": 222, "max": 223, "count": 15 }, { "label": "223-224", "min": 223, "max": 224, "count": 5 } ]}Interpretation:
minandmaxdescribe the covered rangetotal_countis the total sample count- each bucket describes a voltage range and sample count
These payloads are for distribution analysis, not for simple counter or gauge formulas.
Why not use gauge or counter formulas: a histogram row is already an aggregated distribution. You merge compatible histograms by summing bucket counts, not by summing val_rate or reading it like a counter.
Common calculations
Section titled “Common calculations”1. Consumption from an energy counter
Section titled “1. Consumption from an energy counter”Use this for COUNTER metrics whose unit is already energy, such as gridmate_total_pos_active_energy_wh.
For gridmate_total_pos_active_energy_wh, energy counter values are stored in Wh. After summing, the total remains in Wh; optionally divide by 1000 to present kWh. Do not divide by 3_600_000: that factor applies only to integration of power in watts over seconds (Ws to kWh), and an energy counter summed in Wh does not need it.
Formula:
consumption = Σ(val_rate * validity_sec)Worked example for two 15-minute rows:
row_1 = 0.0002777778 * 900 = 0.25 Whrow_2 = 0.0003333333 * 900 = 0.30 Whconsumption = 0.25 + 0.30 = 0.55 WhEach row contributes only the energy that belongs to its own validity window.
Do not use these shortcuts:
- do not sum
val_counterbecause that adds cumulative meter readings together - do not average
val_ratewhen you need total consumption because an average rate is not an energy total - do not assume every row covers the same duration; always use
validity_sec
2. Consumption from an active power metric
Section titled “2. Consumption from an active power metric”Use this for GAUGE metrics in watts, such as gridlink_active_power_w or gridmate_avg_active_power_w.
Formula:
consumption_wh = Σ(val_rate * validity_sec) / 3600consumption_kwh = Σ(val_rate * validity_sec) / 3_600_000Worked example for two 15-minute rows:
row_1 = 1200 W * 900 s = 1_080_000 W·srow_2 = 800 W * 900 s = 720_000 W·stotal_wh = 1_800_000 W·s / 3600 = 500 Whtotal_kwh = 1_800_000 W·s / 3_600_000 = 0.5 kWhPower is an instantaneous level, so energy comes from integrating power over time. 3_600_000 converts watt-seconds to kilowatt-hours.
Do not use these shortcuts:
- do not sum watts directly because watts are a rate, not an energy amount
- do not divide by the number of rows when you need consumption; that gives an average power, not total energy
- match the divisor to the input and output units: W × seconds /
3600gives Wh; W × seconds /3_600_000gives kWh; kW × seconds /3600gives kWh
3. Weighted average for gauge metrics
Section titled “3. Weighted average for gauge metrics”Use this for voltage, current, temperature, power factor, and average power.
Formula:
weighted_average = Σ(val_rate * validity_sec) / Σ(validity_sec)Worked example with unequal interval lengths:
row_1 = 229.8 V for 900 srow_2 = 231.0 V for 300 sweighted_average = (229.8*900 + 231.0*300) / (900 + 300) = 230.1 VLonger intervals should influence the result more than shorter ones. A plain arithmetic mean only works when every row has the same validity_sec.
Do not use these shortcuts:
- do not use
AVG(val_rate)unless all rows cover equal durations - do not sum gauge values because that produces a number with no customer-facing meaning
- do not use
val_counterbecause gauge metrics do not represent cumulative readings
4. Maximum observed value
Section titled “4. Maximum observed value”Use the maximum val_rate from good rows.
A peak metric asks for the highest observed level in the window, not the average level and not the total over time.
Do not use these shortcuts:
- do not average rows when you need the peak
- do not sum rows because totals hide the actual maximum
- do not include
not-okrows unless your analysis explicitly wants suspect values
5. Per-phase totals
Section titled “5. Per-phase totals”Common pattern:
- group rows by phase
- calculate each phase separately
- combine phases only when the metric family says that is valid
For normal customer analysis, default to phases 1, 2, and 3.
Phases are separate electrical channels. Calculating each phase first preserves traceability and avoids mixing missing phases, non-phased rows, or legacy phase 4 into the wrong total.
Do not use these shortcuts:
- do not collapse all rows into one pool before checking phase semantics
- do not mix empty phase
""rows into phased calculations - do not add legacy phase
4into normal three-phase totals by default
6. Pulse consumption
Section titled “6. Pulse consumption”Pulse sensors report readings in metric 8008 (generic_pulse_count), which is a raw COUNTER value: each stored point is a cumulative count. Never sum val_counter, and apply the multiplier only once. The metric is nonphased, so no per-phase summation is involved. Calculate each device and sensor channel separately, using the multiplier for that sensor.
For each interval, derive the pulse count from the rate values, then convert once, where validity_sec is the number of seconds each rate value is valid:
pulse_count = Σ(val_rate * validity_sec)consumption = pulse_count * multiplierThe multiplier means target units per pulse. Always take the actual configured value and its unit from the device profile in the AdvanGrid system; do not invent a common multiplier and do not assume all devices share the same one.
Hypothetical example: an interval has 120 pulses and the device profile multiplier is 0.01 m³/pulse. The line 120 * 0.01 = 1.2 m³ gives 1.2 m³. If the multiplier is in liters/pulse, the result is in liters; divide by 1000 for m³.
Metric family guidance for common use cases
Section titled “Metric family guidance for common use cases”Period import consumption from an energy counter
Section titled “Period import consumption from an energy counter”Use a COUNTER energy metric such as gridmate_total_pos_active_energy_wh.
{ "type": "timeseries", "device_ids": [210404], "metric_ids": [4007], "time_from": "2026-01-01T00:00:00Z", "time_to": "2026-01-05T23:59:59Z"}Then calculate:
Σ(val_rate * validity_sec)The metric already represents energy, so each row’s delta is already in energy units after multiplying by the covered seconds. This gives the period’s imported energy directly.
Do not calculate it by summing val_counter or by subtracting only the first and last visible counters unless you fully control gap handling and row filtering. The API already gives you interval-safe deltas.
Consumption from active power
Section titled “Consumption from active power”Use a GAUGE power metric such as gridlink_active_power_w.
{ "type": "timeseries", "device_ids": [210404], "metric_ids": [2007], "time_from": "2026-01-15T00:00:00Z", "time_to": "2026-01-15T23:59:59Z"}Then calculate:
Σ(val_rate * validity_sec) / 3_600_000Power must be integrated over time to become energy. The division converts watt-seconds to kilowatt-hours.
Do not report Σ(val_rate) as consumption. That is only the sum of sampled power levels and changes when the interval size changes.
Average voltage by phase
Section titled “Average voltage by phase”Use a phased GAUGE metric such as gridmate_rms_voltage_v.
{ "type": "timeseries", "device_ids": [210404], "metric_ids": [4001], "time_from": "2026-01-15T00:00:00Z", "time_to": "2026-01-15T23:59:59Z"}Calculate the weighted average separately for phases 1, 2, and 3.
Voltage is a level, so the right customer-facing summary is the time-weighted mean per phase. Per-phase calculation keeps one unstable phase from being hidden inside an early combined average.
Do not average all rows together first when you still need per-phase visibility, and do not sum voltage readings.
Fuse state inspection
Section titled “Fuse state inspection”Use gridlink_fuse_state and decode val_complex as a fuse-state array.
This metric answers which fuse positions were open or closed at each snapshot. It is an inspection workflow, not an energy or average-value workflow.
Do not apply counter deltas, weighted averages, or max calculations to the raw array itself.
Voltage quality analysis
Section titled “Voltage quality analysis”Use gridlink_voltage_histogram and decode val_complex as a histogram object.
Voltage quality is about the distribution of observed values across ranges. The bucket counts preserve that distribution.
For combining compatible rows, merge buckets by summing matching bucket counts. Do not treat the histogram like a single scalar gauge or counter.
Rules of thumb
Section titled “Rules of thumb”- prefer the measurements API over legacy
.jsonendpoints - discover IDs before building queries
- let
quality_filterdefault tookunless you need bad rows - omit
phase_filterunless you need one explicit phase - treat phase
4as legacy and ignore it by default - never sum
val_counter - use
val_rate * validity_secfor interval totals - use weighted averages for gauge metrics
- use
aggregation_guidanceandrecommended_phase_handlinginstead of guessing - expect
val_complexonly for supported structured metrics