> ## Documentation Index
> Fetch the complete documentation index at: https://docs.amps.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Discharge during a peak window

> Discharge or export from a battery between a start and end time, stopping at a minimum charge level.

Discharge a battery during a peak-rate window by sending `discharge` with a `start` and an `end`. For `discharge`, `target` is the floor: the battery stops discharging when it reaches that level.

## 1. Check the battery supports it

The battery must list `windowed` in `commands.discharge.execution`.

```bash theme={null}
curl https://api.amps.ai/battery/device_abc123 \
  -H "x-api-key: $AMPS_API_KEY"
```

```json theme={null}
{
  "success": true,
  "data": {
    "id": "device_abc123",
    "state": { "level": 92 },
    "commands": {
      "discharge": {
        "parameters": {
          "target": { "unit": "percent", "min": 10, "max": 100 },
          "power": { "unit": "kw", "min": 0, "max": 5 },
          "reserve": { "unit": "percent", "min": 0, "max": 100 }
        },
        "execution": ["immediate", "scheduled", "windowed"]
      }
    }
  }
}
```

## 2. Send the command

Discharge at up to 5 kW from 16:00 to 19:00, stopping at 30%. `reserve` sets a second floor that holds while the command runs.

```bash theme={null}
curl -X POST https://api.amps.ai/battery/device_abc123 \
  -H "x-api-key: $AMPS_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "action": {
      "command": "discharge",
      "start": "2026-11-12T16:00:00",
      "end": "2026-11-12T19:00:00",
      "parameters": {
        "target": { "value": 30, "unit": "percent" },
        "power": { "value": 5, "unit": "kw" },
        "reserve": { "value": 20, "unit": "percent" }
      }
    }
  }'
```

```json theme={null}
{
  "success": true,
  "data": {
    "id": "action_njbw6w8BJM",
    "command": "discharge",
    "state": "scheduled",
    "start": "2026-11-12T16:00:00.000Z",
    "end": "2026-11-12T19:00:00.000Z",
    "links": { "self": "/actions/action_njbw6w8BJM" }
  }
}
```

The API returns `202 Accepted`. A value outside a parameter's `min`/`max` returns `422 PARAMETER_OUT_OF_RANGE`. At `end`, Amps takes the command back; send `auto.balance` afterwards if you want the battery to manage itself again. See [Scheduling](/guides/scheduling) for time format and limits.

## 3. Confirm

Listen for `push.completed` or `push.failed` on your [webhook](/guides/webhooks). During the window, `GET /battery/device_abc123` shows `state.status: "discharging"` and a negative `chargeRate`.

## Next steps

<CardGroup cols={2}>
  <Card title="Charge in a cheap-rate window" icon="moon" href="/cookbooks/battery/charge-in-window">
    Refill the battery overnight.
  </Card>

  <Card title="Conflicts" icon="code-merge" href="/guides/push/conflicts">
    Handle a `409` when the battery is busy.
  </Card>
</CardGroup>


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.