Skip to main content

Get Historical Data

Retrieve complete historical data for a sensor type including current value, statistics, trend analysis, and chart data.

Query Parameters

greenhouseId
long
required
ID of the greenhouse
sensorType
string
required
Type of sensor (TEMPERATURE, HUMIDITY, CO2, LIGHT, etc.)
period
string
default:"24h"
Time period for analysis. Options: 24h (hourly aggregation), 7d (daily), 30d (daily)

Response

greenhouseId
long
ID of the greenhouse
tenantId
long
ID of the tenant
sensorType
string
Type of sensor queried
unit
string
Unit of measurement
currentValue
number
Most recent sensor reading
currentValueTimestamp
string
Timestamp of current value (ISO 8601)
avgValue
number
Average value over the period
minValue
number
Minimum value recorded in the period
maxValue
number
Maximum value recorded in the period
medianValue
number
Median value (if calculated)
trendPercent
number
Percentage change from average (positive or negative)
trendDirection
string
Trend direction: INCREASING, DECREASING, or STABLE
chartData
array
Array of time-series data points for charting
period
string
The period string used for this query
startTime
string
Start of the time range (ISO 8601)
endTime
string
End of the time range (ISO 8601)

Example Request

curl -X GET "https://api.example.com/api/v1/statistics/historical-data?greenhouseId=123456789&sensorType=TEMPERATURE&period=24h" \
  -H "Accept: application/json"

Example Response

{
  "greenhouseId": 123456789,
  "tenantId": 987654321,
  "sensorType": "TEMPERATURE",
  "unit": "°C",
  "currentValue": 22.5,
  "currentValueTimestamp": "2025-03-03T14:30:00Z",
  "avgValue": 21.8,
  "minValue": 19.5,
  "maxValue": 24.1,
  "medianValue": 21.9,
  "trendPercent": 3.2,
  "trendDirection": "INCREASING",
  "chartData": [
    {
      "timestamp": "2025-03-02T14:00:00Z",
      "value": 20.5
    },
    {
      "timestamp": "2025-03-02T15:00:00Z",
      "value": 20.8
    },
    {
      "timestamp": "2025-03-02T16:00:00Z",
      "value": 21.2
    }
  ],
  "period": "24h",
  "startTime": "2025-03-02T14:30:00Z",
  "endTime": "2025-03-03T14:30:00Z"
}

Get Hourly Statistics

Retrieve hourly aggregated statistics for a sensor type.

Query Parameters

greenhouseId
long
required
ID of the greenhouse
sensorType
string
required
Type of sensor
hours
integer
default:"24"
Number of hours to retrieve

Response

bucket
string
Start of the 1-hour bucket (ISO 8601)
greenhouseId
long
ID of the greenhouse
tenantId
long
ID of the tenant
sensorType
string
Type of sensor
unit
string
Unit of measurement
avgValue
number
Average value for the hour
minValue
number
Minimum value in the hour
maxValue
number
Maximum value in the hour
stddevValue
number
Standard deviation
countReadings
long
Number of readings in the hour
nullCount
long
Number of null readings
firstReadingAt
string
Timestamp of first reading in hour
lastReadingAt
string
Timestamp of last reading in hour

Example Request

curl -X GET "https://api.example.com/api/v1/statistics/hourly?greenhouseId=123456789&sensorType=TEMPERATURE&hours=48" \
  -H "Accept: application/json"

Example Response

[
  {
    "bucket": "2025-03-03T13:00:00Z",
    "greenhouseId": 123456789,
    "tenantId": 987654321,
    "sensorType": "TEMPERATURE",
    "unit": "°C",
    "avgValue": 21.5,
    "minValue": 20.8,
    "maxValue": 22.3,
    "stddevValue": 0.45,
    "countReadings": 60,
    "nullCount": 0,
    "firstReadingAt": "2025-03-03T13:00:15Z",
    "lastReadingAt": "2025-03-03T13:59:45Z"
  },
  {
    "bucket": "2025-03-03T14:00:00Z",
    "greenhouseId": 123456789,
    "tenantId": 987654321,
    "sensorType": "TEMPERATURE",
    "unit": "°C",
    "avgValue": 22.1,
    "minValue": 21.5,
    "maxValue": 22.8,
    "stddevValue": 0.38,
    "countReadings": 60,
    "nullCount": 0,
    "firstReadingAt": "2025-03-03T14:00:10Z",
    "lastReadingAt": "2025-03-03T14:59:50Z"
  }
]

Get Daily Statistics

Retrieve daily aggregated statistics for a sensor type.

Query Parameters

greenhouseId
long
required
ID of the greenhouse
sensorType
string
required
Type of sensor
days
integer
default:"7"
Number of days to retrieve

Response

Returns an array of daily statistics with extended metrics:
bucket
string
Start of the 1-day bucket (ISO 8601)
greenhouseId
long
ID of the greenhouse
tenantId
long
ID of the tenant
sensorType
string
Type of sensor
unit
string
Unit of measurement
avgValue
number
Average value for the day
minValue
number
Minimum value in the day
maxValue
number
Maximum value in the day
stddevValue
number
Standard deviation
countReadings
long
Total number of readings in the day
medianValue
number
Median value for the day
p95Value
number
95th percentile value
p5Value
number
5th percentile value
nullCount
long
Number of null readings
hoursWithData
integer
Number of hours (0-24) that had readings
firstReadingAt
string
Timestamp of first reading in day
lastReadingAt
string
Timestamp of last reading in day

Example Request

curl -X GET "https://api.example.com/api/v1/statistics/daily?greenhouseId=123456789&sensorType=HUMIDITY&days=7" \
  -H "Accept: application/json"

Get Statistics Summary

Retrieve a summary of statistics (min/max/avg) without chart data.

Query Parameters

greenhouseId
long
required
ID of the greenhouse
sensorType
string
required
Type of sensor
period
string
default:"24h"
Time period. Options: 24h, 7d, 30d

Response

Returns a simple map of summary statistics:
overall_avg
number
Average value over the period
overall_min
number
Minimum value
overall_max
number
Maximum value
unit
string
Unit of measurement
total_readings
long
Total number of readings in period

Example Request

curl -X GET "https://api.example.com/api/v1/statistics/summary?greenhouseId=123456789&sensorType=TEMPERATURE&period=7d" \
  -H "Accept: application/json"

Example Response

{
  "overall_avg": 21.8,
  "overall_min": 19.5,
  "overall_max": 24.1,
  "unit": "°C",
  "total_readings": 10080
}

Get Sensor Trend

Calculate the trend (percentage change) for a sensor over a period.

Path Parameters

sensorId
string
required
Unique identifier for the sensor

Query Parameters

tenantId
string
ID of the tenant (for multi-tenant filtering)
period
string
default:"24h"
Time period. Examples: 24h, 7d, 30d, 60m

Response

Returns trend analysis for the sensor:
sensorId
string
ID of the sensor
currentValue
number
Most recent value
previousValue
number
Value at the start of the period
percentChange
number
Percentage change (positive or negative)
direction
string
Trend direction: INCREASING, DECREASING, or STABLE
period
string
Period used for calculation

Example Request

curl -X GET "https://api.example.com/api/v1/sensors/stats/TEMP_01/trend?period=24h" \
  -H "Accept: application/json"

Example Response

{
  "sensorId": "TEMP_01",
  "currentValue": 22.5,
  "previousValue": 21.8,
  "percentChange": 3.2,
  "direction": "INCREASING",
  "period": "24h"
}

Build docs developers (and LLMs) love