Developer API and Automation

Introduction

Netzero allows you to schedule Powerwall configuration changes using the app (backup reserve, operational mode, energy exports, and grid charging).

For more advanced use, the app also offers an API that allows you to manage these configuration changes.

API Token

Begin by logging into your Tesla account using the Netzero app. Access your API token and energy site ID by navigating to the Account menu (last menu) and selecting Settings > Developer API. It’s important to keep your API token secure, as while it provides access only to the data displayed here, it does grant the ability to manage Powerwall configuration.

Automation with API requests

If you’re familiar with running web requests using curl or similar tools, you can manage the configuration with scripts.

To retrieve the current configuration and live status of the system, insert $API_TOKEN and $SITE_ID values obtained above and run:

export API_TOKEN="..."
export SITE_ID="..."

curl -H "Authorization: Bearer $API_TOKEN" https://api.netzero.energy/api/v1/$SITE_ID/config

{
  "backup_reserve_percent": 80,
  "operational_mode": "autonomous",
  "energy_exports": "pv_only",
  "grid_charging": true,
  "percentage_charged": 70,
  "grid_status": "Active (on_grid)",

  "live_status": {
    "solar_power": 4140,
    "battery_power": -2520,
    "load_power": 1620,
    "grid_power": 0,
    [...],
    "wall_connectors": [
      {
        "din": "1457768-02-G--B7S12345J12345",
        "wall_connector_state": 2,
        "wall_connector_fault_state": 2,
        "wall_connector_power": 0
      }
    ]
  }
}

This response includes both configuration values and the current power draw. If you have a Wall Connector connected to your account, you’ll also see car charging status.

To modify the configuration, send a POST request with new values. You can adjust one or more of the following parameters in the same request:

You can modify one or more of these values in the same request.

curl -H "Authorization: Bearer $API_TOKEN" \
    --json '{"backup_reserve_percent": 50, "operational_mode": "self_consumption"}' \
    https://api.netzero.energy/api/v1/$SITE_ID/config

{
  "backup_reserve_percent": 50,
  "operational_mode": "self_consumption",
  "energy_exports": "pv_only",
  "grid_charging": true,
  "percentage_charged": 98,
  "grid_status": "Active (on_grid)",
  "live_status": {...}
}

The response mirrors that of the GET request, providing the updated configuration (inclusive of any changes made) along with the live status.

Here’s an example with Python code instead of curl:

import os
import requests

site_id = os.environ['SITE_ID']
api_token = os.environ['API_TOKEN']
config = {'backup_reserve_percent': 30, 'operational_mode': 'autonomous'}

response = requests.post(
    url=f'https://api.netzero.energy/api/v1/{site_id}/config',
    headers={'Authorization': f'Bearer {api_token}'},
    json=config,
)
print(response.json())

Off-Grid Status

The off_grid_status parameter allows you to programmatically disconnect from and reconnect to the grid. This is useful for avoiding negative export pricing or demand charges during specific periods.

Requirements:

Example: disconnect from the grid:

curl -H "Authorization: Bearer $API_TOKEN" \
    --json '{"off_grid_status": "go_off_grid"}' \
    https://api.netzero.energy/api/v1/$SITE_ID/config

You can check the current grid status in the response under grid_status.