Welcome to the Energy Monitoring System API documentation. This document provides details about the available endpoints, their request formats, and exact response structures as returned by the controllers.
http://your-domain/api
Some endpoints require a secret key for access. This key can be provided via a query parameter or a request header.
- Query Parameter:
?secret=YOUR_SYNC_SECRET - Request Header:
X-Sync-Secret: YOUR_SYNC_SECRET
The API follows a standard response structure for all controller-based endpoints:
{
"status": "success",
"data": { ... },
"message": "Action completed successfully"
}{
"status": "error",
"message": "Description of the error",
"code": 404
}Retrieve a list of all registered devices.
Response Example:
{
"status": "success",
"data": [
{
"id": "1",
"device_id": "energy",
"device_name": "Main Meter",
"location": "Main Panel",
"status": "active",
"created_at": "2026-05-12 10:00:00",
"updated_at": "2026-05-12 10:00:00"
}
],
"message": "Devices retrieved successfully"
}Retrieve details for a specific device.
Response Example:
{
"status": "success",
"data": {
"id": "1",
"device_id": "energy",
"device_name": "Main Meter",
"location": "Main Panel",
"status": "active",
"created_at": "2026-05-12 10:00:00",
"updated_at": "2026-05-12 10:00:00"
},
"message": ""
}Retrieve the latest status and sensor reading for a specific device.
Response Example:
{
"status": "success",
"data": {
"device": {
"id": "1",
"device_id": "energy",
"device_name": "Main Meter",
"location": "Main Panel",
"status": "active",
"created_at": "2026-05-12 10:00:00",
"updated_at": "2026-05-12 10:00:00"
},
"latest_reading": {
"id": "500",
"device_id": "energy",
"current": "1.45",
"voltage": "230.1",
"temperature": "35.2",
"power_watt": "333.645",
"energy": "12.5",
"kwh": "0.12",
"power": "0.33",
"recorded_at": "2026-05-12 12:00:00"
}
},
"message": ""
}Retrieve the most recent reading for all devices.
Response Example:
{
"status": "success",
"data": [
{
"id": "500",
"device_id": "energy",
"current": "1.45",
"voltage": "230.1",
"temperature": "35.2",
"power_watt": "333.645",
"energy": "12.5",
"kwh": "0.12",
"power": "0.33",
"recorded_at": "2026-05-12 12:00:00"
}
],
"message": ""
}Retrieve the latest reading for a specific device.
Response Example:
{
"status": "success",
"data": {
"id": "500",
"device_id": "energy",
"current": "1.45",
"voltage": "230.1",
"temperature": "35.2",
"power_watt": "333.645",
"energy": "12.5",
"kwh": "0.12",
"power": "0.33",
"recorded_at": "2026-05-12 12:00:00"
},
"message": ""
}Retrieve historical readings for a specific device.
Query parameters: ?from=YYYY-MM-DD&to=YYYY-MM-DD&limit=100
Response Example:
{
"status": "success",
"data": [
{
"id": "500",
"device_id": "energy",
"current": "1.45",
"voltage": "230.1",
"temperature": "35.2",
"power_watt": "333.645",
"energy": "12.5",
"kwh": "0.12",
"power": "0.33",
"recorded_at": "2026-05-12 12:00:00"
}
],
"message": ""
}Retrieve aggregated statistics.
Query parameters: ?period=daily|weekly|monthly
Response Example:
{
"status": "success",
"data": {
"period": "daily",
"count": 144,
"avg_current": 1.25,
"max_current": 2.1,
"min_current": 0.5,
"avg_voltage": 229.5,
"avg_temperature": 34.0,
"avg_power": 286.875,
"max_power": 483.0
},
"message": ""
}Insert a manual test reading. Requires Authentication.
Request Body:
{
"device_id": "energy",
"current": 1.2,
"voltage": 220.5,
"temperature": 32.0,
"kwh": 0.05,
"power": 0.0,
"energy": 10.5,
"recorded_at": "2026-05-12 15:00:00"
}Response Example:
{
"status": "success",
"data": {
"inserted_id": 501
},
"message": ""
}Retrieve the latest bill prediction for each device.
Response Example:
{
"status": "success",
"data": [
{
"id": "10",
"device_id": "energy",
"month": "2026-05",
"predicted_kwh": "150.5",
"predicted_cost": "45.15",
"currency": "USD",
"generated_at": "2026-05-12 10:00:00"
}
],
"message": ""
}Generate a new bill prediction using Gemini AI.
Response Example:
{
"status": "success",
"data": {
"device_id": "energy",
"month": "2026-05",
"predicted_kwh": 150.5,
"predicted_cost": 45.15,
"currency": "USD",
"generated_at": "2026-05-12 20:30:00",
"id": 11,
"summary": "Based on the last 30 readings, your usage is stable..."
},
"message": ""
}Retrieve historical predictions for a device.
Query parameters: ?limit=12
Response Example:
{
"status": "success",
"data": [
{
"id": "11",
"device_id": "energy",
"month": "2026-05",
"predicted_kwh": "150.5",
"predicted_cost": "45.15",
"currency": "USD",
"generated_at": "2026-05-12 20:30:00"
}
],
"message": ""
}Retrieve the latest AI-generated tip for each device.
Response Example:
{
"status": "success",
"data": [
{
"id": "25",
"device_id": "energy",
"tip_text": "Consider turning off appliances during peak hours.",
"category": "energy saving",
"generated_at": "2026-05-12 10:00:00"
}
],
"message": ""
}Manually trigger new tips generation. Requires Authentication.
Response Example:
{
"status": "success",
"data": [
{
"device_id": "energy",
"tip_text": "Your AC temperature is set too low.",
"category": "maintenance",
"generated_at": "2026-05-12 20:35:00",
"id": 26
}
],
"message": ""
}Retrieve history of tips for a device.
Query parameters: ?limit=20
Response Example:
{
"status": "success",
"data": [
{
"id": "26",
"device_id": "energy",
"tip_text": "Your AC temperature is set too low.",
"category": "maintenance",
"generated_at": "2026-05-12 20:35:00"
}
],
"message": ""
}Endpoints for syncing data from Firebase. Requires Authentication. These return a non-standard success structure (no data wrapper).
Response:
{
"synced": 5,
"status": "ok"
}Response:
{
"synced": 2,
"status": "ok"
}