> ## 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.

# Charge a battery from solar

> Poll solar production and push a battery charge when output is high.

Amps doesn't link devices together or act on its own. To charge a battery when the sun is out, poll the inverter yourself and push a `charge` to the battery when production crosses your threshold.

## 1. Check the battery supports it

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

```json theme={null}
{
  "success": true,
  "data": {
    "id": "device_bat456",
    "state": { "status": "idle", "level": 42, "currentMode": "auto.balance" },
    "commands": {
      "charge": {
        "parameters": {
          "target": { "unit": "percent", "min": 0, "max": 100 },
          "power": { "unit": "kw", "min": 0, "max": 1000 }
        },
        "execution": ["immediate", "scheduled", "windowed"]
      }
    },
    "conflictStrategies": ["cancel_and_replace", "queue_after"]
  }
}
```

## 2. Read production

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

```json theme={null}
{ "success": true, "data": { "state": { "status": "producing", "currentPower": 3.4 } } }
```

`currentPower` is total output, not surplus. Amps doesn't see household consumption, so subtract your own estimate if you have one.

## 3. Send the charge

If output is above your threshold, charge the battery and cap the rate near the output:

```bash theme={null}
curl -X POST https://api.amps.ai/battery/device_bat456 \
  -H "x-api-key: $AMPS_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "action": {
      "command": "charge",
      "parameters": {
        "target": { "value": 90, "unit": "percent" },
        "power": { "value": 3, "unit": "kw" }
      }
    },
    "onConflict": "cancel_and_replace"
  }'
```

```json theme={null}
{ "success": true, "data": { "id": "action_qVEFrQ3kYE", "command": "charge", "state": "acknowledged" } }
```

`cancel_and_replace` replaces whatever the battery was last told to do. See [Conflicts](/guides/push/conflicts). When production drops, push `auto.balance` to hand control back to the battery.

## 4. Confirm

Check `GET /actions/action_qVEFrQ3kYE` for `completed`, then repeat from step 2 on your poll interval. See [Push](/guides/push).

## Next steps

<CardGroup cols={2}>
  <Card title="Monitor production" icon="sun" href="/cookbooks/solar/monitor-production">
    Polling and freshness for inverters.
  </Card>

  <Card title="Battery cookbook" icon="battery-full" href="/cookbooks/battery">
    More ways to control a battery.
  </Card>
</CardGroup>


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