Reading12 min
App Pattern: Cost Optimizer (Forecast + Dispatch + Settle)
🏗️ Module 8: Build Real Apps
App Pattern: Cost Optimizer (Forecast + Dispatch + Settle)
This is the app that prints money. Battery arbitrage: charge when electricity is cheap, discharge when it's expensive, pocket the difference.
You're combining 3 things: Forecast prices, Dispatch battery commands, Settle with proof.
The Price Spread
UAE electricity prices follow a predictable daily pattern:
| Period | Time | Price (AED/kWh) |
|---|---|---|
| Off-peak | 22:00 - 06:00 | 0.20 |
| Shoulder | 06:00 - 12:00 | 0.29 |
| Peak | 12:00 - 18:00 | 0.38 |
| Shoulder | 18:00 - 22:00 | 0.29 |
The spread between off-peak and peak is 0.18 AED/kWh. For a 100 kW / 500 kWh battery:
- Charge cost (off-peak): 500 kWh x 0.20 = 100 AED
- Discharge revenue (peak): 500 kWh x 0.38 = 190 AED (accounting for 95% round-trip efficiency: ~475 kWh x 0.38 = 180.5 AED)
- Gross margin: ~80 AED/cycle
- 2 cycles/day: ~161 AED/day
- Monthly: ~4,830 AED/month
That's real money. And you're the developer who built the system.
Step 1: Get Price Forecast
curl -s https://app.energyatit.com/api/v1/grid-prices?region=UAE \
-H "Authorization: Bearer $TOKEN" | jq '.data'curl.exe -H "Authorization: Bearer $env:TOKEN" "https://app.energyatit.com/api/v1/grid-prices?region=UAE" | ConvertFrom-Json | ConvertTo-Json -Depth 10Step 2: Dispatch Charge (Off-Peak)
curl -s -X POST https://app.energyatit.com/api/v1/assets/1/dispatch \
-H "Authorization: Bearer $TOKEN" \
-H "Content-Type: application/json" \
-d '{
"command": "charge",
"target_kw": 100,
"duration_minutes": 300
}'curl.exe --% -X POST -H "Authorization: Bearer $env:TOKEN" -H "Content-Type: application/json" -d "{"command": "charge", "target_kw": 100, "duration_minutes": 300}" "https://app.energyatit.com/api/v1/assets/1/dispatch"Step 3: Dispatch Discharge (Peak)
curl -s -X POST https://app.energyatit.com/api/v1/assets/1/dispatch \
-H "Authorization: Bearer $TOKEN" \
-H "Content-Type: application/json" \
-d '{
"command": "discharge",
"target_kw": 100,
"duration_minutes": 300
}'curl.exe --% -X POST -H "Authorization: Bearer $env:TOKEN" -H "Content-Type: application/json" -d "{"command": "discharge", "target_kw": 100, "duration_minutes": 300}" "https://app.energyatit.com/api/v1/assets/1/dispatch"Step 4: Settle with Proof
from energyatit import EnergyAtItClient
client = EnergyAtItClient(token="your_token")
settlement = client.generate_settlement(
site_id=1,
period_start="2026-02-27",
period_end="2026-02-28"
)
print(f"Settlement ID: {settlement['id']}")
print(f"Hash chain valid: {settlement['chain_valid']}")The settlement creates a hash-chained record of every charge/discharge cycle, the prices at time of execution, and the net revenue. This is auditable proof that your optimizer is doing what it claims.
Log in to track your progress and earn certifications.