# Consumption, Production & Grid import/export This guide explains how to use the Wia API to retrieve electricity data, focusing on differentiating between energy consumed and produced, isolating energy drawn from the grid (billable) or generated energy exported to the grid. You will need a Wia API key (`Bearer YOUR_API_KEY`) to authenticate all requests. **Note:** The exact behavior and availability of data for different flows (like grid import/export vs. solar) can depend on your specific device setup and configuration within the Wia platform. ## Step 1: Setting the Flow parameter The API allows you to specify the primary direction of energy flow you want to query using the `flow` parameter with the `/energy/electricity` endpoint: * `flow=consumption`: Retrieves data for energy being used or consumed within the scope (e.g., by appliances). * `flow=production`: Retrieves data for energy being generated (e.g., by solar panels). * `flow=import`: Retrieves data for energy consumed from the grid. * `flow=export`: Retrieves data generated and exported to the grid. ### Example: Get Total Electricity Consumption/Production ```bash curl -X GET "[https://api.wia.io/v1/energy/electricity?space.id=spc_abc123&since=1704067200000&until=1704153600000&flow=consumption](https://api.wia.io/v1/energy/electricity?space.id=spc_abc123&since=1704067200000&until=1704153600000&flow=consumption)" \ -H "Authorization: Bearer YOUR_API_KEY" flow=consumption: Retrieves data for all energy consumed within the specified space and time range, regardless of the source (could include grid and self-consumed solar).Example: Get Total Electricity Productioncurl -X GET "[https://api.wia.io/v1/energy/electricity?space.id=spc_abc123&since=1704067200000&until=1704153600000&flow=production](https://api.wia.io/v1/energy/electricity?space.id=spc_abc123&since=1704067200000&until=1704153600000&flow=production)" \ "result": [ { "energy": "1500", // Energy in kWh "timestamp": 1704070800000 // Timestamp in milliseconds UTC }, { "energy": "1650", "timestamp": 1704074400000 } ], "continuationToken": null } curl -X GET "[https://api.wia.io/v1/energy/electricity?space.id=spc_abc123&since=1704067200000&until=1704153600000&flow=production](https://api.wia.io/v1/energy/electricity?space.id=spc_abc123&since=1704067200000&until=1704153600000&flow=production)" \ -H "Authorization: Bearer YOUR_API_KEY" flow=production: Retrieves data for all energy generated (e.g., by solar panels) within the specified space and time range.Response Example (for either flow){ "result": [ { "energy": "1000", // Energy in kWh "timestamp": 1704070800000 // Timestamp in milliseconds UTC }, { "energy": "1050", "timestamp": 1704074400000 } ], "continuationToken": null ```