Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
82 changes: 38 additions & 44 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,63 +1,57 @@
# Powerpal Auth Extractor

Because the powerpal mobile app is not open source, and does not provide a way to extract the API key and serial number from the device, this script was created to extract the API key and serial number from the device directly via Bluetooth Low Energy (BLE).
Extracts the **Device Serial** and **API Key** from a Powerpal energy monitor via Bluetooth, without needing the Powerpal app. Once you have these credentials you can query the Powerpal API directly, or use them with integrations like Home Assistant.

Once extracted, these credentials can be used to query your home's energy usage data straight from the official Powerpal API endpoints. Can be used with integrations like Home Assistant, Grafana, etc.
## Requirements

## What it does
- Python 3.10+
- Bluetooth enabled on your computer
- Your Powerpal's **6-digit pairing code** (on the card that came with your Powerpal, or in the Powerpal app)

This script uses your computer's Bluetooth to connect to your Powerpal. It authenticates using your 6-digit pairing code, reads the specific GATT characteristics holding your Device Serial Number and API Key (UUID), and formats them for use.

## Prerequisites

- **Python 3.7+**
- A computer with **Bluetooth enabled** (Windows, macOS, or Linux)
- Your Powerpal's **MAC Address** (Format: `12:34:56:78:9A:BC`)
- Your Powerpal's **6-digit Pairing Code**

> **Note:** The MAC address and pairing code can typically be found printed on the device itself, on the original packaging card, or mostly within the settings of **You can also find the MAC address within bluetooth settings on your phone or computer.**

## Installation

1. Clone or download this repository.
2. Install the required dependencies:
## Setup

```bash
pip install -r requirements.txt
```

## How to use it

### IMPORTANT: When and How to Connect via Bluetooth

**DO NOT** try to pair or connect to the Powerpal device through your computer's operating system Bluetooth menu.
## Usage

The Powerpal device can only maintain **one active Bluetooth connection at a time**. In order for this script to work, you must ensure the Powerpal is completely disconnected from any other devices.

**Before running the script:**
1. Ensure your computer's Bluetooth hardware is **turned on**.
2. **Disconnect your phone** from the Powerpal device. The easiest way to do this is to fully close/kill the Powerpal mobile app on your smartphone, or temporarily turn off Bluetooth on your phone altogether.
3. The Python script will handle the Bluetooth connection directly. *make sure you are within range of the Powerpal device*

### Running the script

You can run the script and manually enter the information when prompted:
Close the Powerpal app on your phone (or disable phone Bluetooth) so the device is free to connect, then run:

```bash
python retrieve_api_key.py
$ python retrieve_api_key.py
```

Or you can provide your MAC address and Pairing code directly as command-line arguments:
```
Found: Powerpal 000123ab (12:34:56:78:9A:BC)
? Your Powerpal pairing code: 123456
✓ Paired
╭─────────────────────────────────── Powerpal Credentials ───────────────────────────────────╮
│ Serial (Device ID) 000123ab │
│ API key (Authorisation Key) 7e4a9f12-83cb-4d56-ae01-2f9b0c3d7e58 │
│ Readings endpoint https://readings.powerpal.net/api/v1/meter_reading/000123ab │
╰────────────────────────────────────────────────────────────────────────────────────────────╯
? Validate credentials by calling the Powerpal API for device 000123ab? Yes
✓ Credentials verified — your Device ID and Authorisation Key were successfully retrieved!
╭──────────────────────────────────────── API Response ──────────────────────────────────────╮
│ { │
│ "serial_number": "000123ab", │
│ "total_meter_reading_count": 312847, │
│ "total_watt_hours": 2914830, │
│ "total_cost": 1053.42, │
│ ... │
│ } │
╰────────────────────────────────────────────────────────────────────────────────────────────╯
```

You can pass arguments directly to skip the prompts:

```bash
python retrieve_api_key.py 12:34:56:78:9A:BC 123456
$ python retrieve_api_key.py --code 123456
$ python retrieve_api_key.py --code 123456 --device 12:34:56:78:9A:BC
```

### Script Execution

1. The script will pause and ask you to confirm that no other devices (like your phone) are currently connected to the Powerpal. Hit `Enter` to proceed.
2. It attempts to connect to the Powerpal via BLE and authenticates with your pairing code.
3. It grabs your **Device Serial**.
4. It grabs your **API Key (UUID)**.
5. It will finally ask `(y/n)` if you'd like to test the credentials against `https://readings.powerpal.net/api/v1/device/{serial}`.
6. If the request succeeds, your Powerpal's configuration metadata will be printed to the console, and you now have the required keys to build your own integrations (like Home Assistant, Grafana, etc.).
| Option | Description |
| --- | --- |
| `--code` | 6-digit pairing code |
| `--device` | Bluetooth MAC address — skips scanning if you already know it |
4 changes: 4 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
bleak
requests
rich
questionary
typer
dbus-fast; sys_platform == "linux"
Loading