Async Python client for the Leviton My Leviton cloud API
Project description
aioleviton
Async Python client for the Leviton My Leviton cloud API.
Supports LWHEM and DAU/LDATA Smart Load Centers with WebSocket real-time push and REST API fallback.
Features
- Pure
asynciowithaiohttp-- no blocking calls - Accepts an injected
aiohttp.ClientSessionfor connection pooling - WebSocket real-time push notifications with automatic subscription management
- Full REST API coverage: authentication, device discovery, breaker control, energy history
- Typed data models with PEP 561
py.typedmarker - Support for both hub types: LWHEM (
IotWhem) and DAU/LDATA (ResidentialBreakerPanel) - Two-factor authentication (2FA) support
Installation
pip install aioleviton
Quick Start
import aiohttp
from aioleviton import LevitonClient, LevitonWebSocket
async def main():
async with aiohttp.ClientSession() as session:
# Authenticate
client = LevitonClient(session)
auth = await client.login("user@example.com", "password")
# Discover devices
permissions = await client.get_permissions()
for perm in permissions:
if perm.residential_account_id:
residences = await client.get_residences(perm.residential_account_id)
for residence in residences:
whems = await client.get_whems(residence.id)
panels = await client.get_panels(residence.id)
# Get breakers for a LWHEM hub
for whem in whems:
breakers = await client.get_whem_breakers(whem.id)
cts = await client.get_cts(whem.id)
# Connect WebSocket for real-time updates
ws = LevitonWebSocket(
session=session,
token=auth.token,
user_id=auth.user_id,
user=auth.user,
token_created=auth.created,
token_ttl=auth.ttl,
)
await ws.connect()
# Subscribe to a hub (delivers all child breaker/CT updates)
await ws.subscribe("IotWhem", whem.id)
# Handle notifications
ws.on_notification(lambda data: print("Update:", data))
Note: On LWHEM firmware 2.0.0+, hub subscriptions no longer deliver individual breaker updates. You must subscribe to each
ResidentialBreakerseparately. CT updates are still delivered via the hub subscription on all firmware versions.
Debug Logging
from aioleviton import enable_debug_logging
enable_debug_logging() # sets aioleviton logger to DEBUG
Supported Devices
| Device | API Model | Hub Type |
|---|---|---|
| LWHEM (Whole Home Energy Module) | IotWhem |
Wi-Fi hub |
| DAU / LDATA (Data Acquisition Unit) | ResidentialBreakerPanel |
Wi-Fi hub |
| Smart Breaker Gen 1 (trip only) | ResidentialBreaker |
Child of LWHEM or DAU |
| Smart Breaker Gen 2 (on/off) | ResidentialBreaker |
Child of LWHEM or DAU |
| Current Transformer (CT) | IotCt |
Child of LWHEM only |
| LSBMA Add-on CT | ResidentialBreaker |
Virtual composite |
Breaker Control
# Trip a Gen 1 breaker (cannot turn back on remotely)
await client.trip_breaker(breaker_id)
# Turn on/off a Gen 2 breaker
await client.turn_on_breaker(breaker_id)
await client.turn_off_breaker(breaker_id)
# Blink LED on a breaker
await client.blink_led(breaker_id)
# Identify LED on a LWHEM hub
await client.identify_whem(whem_id)
Energy History
Energy history endpoints return consumption data for all devices in a residence. Data is keyed by hub ID, then by breaker position and CT channel.
# Daily energy (hourly data points)
day = await client.get_energy_for_day(
residence_id=123456,
start_day="2026-02-16",
timezone="America/Los_Angeles",
)
# Weekly energy (daily data points for 7 days)
week = await client.get_energy_for_week(
residence_id=123456,
start_day="2026-02-17",
timezone="America/Los_Angeles",
)
# Monthly energy (daily data points for billing month)
month = await client.get_energy_for_month(
residence_id=123456,
billing_day_in_month="2026-02-28",
timezone="America/Los_Angeles",
)
# Yearly energy (monthly data points for 12 months)
year = await client.get_energy_for_year(
residence_id=123456,
billing_day_in_end_month="2026-02-16",
timezone="America/Los_Angeles",
)
# Response structure:
# {
# "<hub_id>": {
# "residentialBreakers": {"<position>": [{x, timestamp, energyConsumption, totalCost, ...}]},
# "iotCts": {"<channel>": [...]},
# "totals": [...]
# },
# "totals": [...] # residence-level totals
# }
Firmware Check
# Check for available firmware updates
firmware = await client.check_firmware(
app_id="LWHEM",
model="AZ",
serial="1000_XXXX_XXXX",
model_type="IotWhem",
)
# Returns list of firmware objects with version, fileUrl, signature, hash, size, notes
for fw in firmware:
print(f"v{fw['version']}: {fw['fileUrl']}")
License
MIT
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file aioleviton-0.2.4.tar.gz.
File metadata
- Download URL: aioleviton-0.2.4.tar.gz
- Upload date:
- Size: 16.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4929be0b2157f5f4ef40b3506f7ab5761a7420e4af8c8c0d81fa22ebdcf3afb1
|
|
| MD5 |
0a8839abd55790607f2a3f2ab7a1cec1
|
|
| BLAKE2b-256 |
bde66545e35767483c8e6536d770157bad49cadf2c78cb6dc89dc9049d7f7d5c
|
Provenance
The following attestation bundles were made for aioleviton-0.2.4.tar.gz:
Publisher:
publish.yml on gtxaspec/aioleviton
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
aioleviton-0.2.4.tar.gz -
Subject digest:
4929be0b2157f5f4ef40b3506f7ab5761a7420e4af8c8c0d81fa22ebdcf3afb1 - Sigstore transparency entry: 962181437
- Sigstore integration time:
-
Permalink:
gtxaspec/aioleviton@7a53c917cfadf127f5e93f1145d4a6ab86a7405b -
Branch / Tag:
refs/tags/v0.2.4 - Owner: https://github.com/gtxaspec
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@7a53c917cfadf127f5e93f1145d4a6ab86a7405b -
Trigger Event:
release
-
Statement type:
File details
Details for the file aioleviton-0.2.4-py3-none-any.whl.
File metadata
- Download URL: aioleviton-0.2.4-py3-none-any.whl
- Upload date:
- Size: 16.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
25e6bb1d93d2dfd8c79436e8cd218a3fc6bd65e40d155f469eef9ac766f5fa40
|
|
| MD5 |
3978c4ba79803d62be883ae582341ec3
|
|
| BLAKE2b-256 |
de802515f8d2adb5b0455d404bcd6863b5b69bf4e28505a4cbd43848cfbb50f5
|
Provenance
The following attestation bundles were made for aioleviton-0.2.4-py3-none-any.whl:
Publisher:
publish.yml on gtxaspec/aioleviton
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
aioleviton-0.2.4-py3-none-any.whl -
Subject digest:
25e6bb1d93d2dfd8c79436e8cd218a3fc6bd65e40d155f469eef9ac766f5fa40 - Sigstore transparency entry: 962181443
- Sigstore integration time:
-
Permalink:
gtxaspec/aioleviton@7a53c917cfadf127f5e93f1145d4a6ab86a7405b -
Branch / Tag:
refs/tags/v0.2.4 - Owner: https://github.com/gtxaspec
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@7a53c917cfadf127f5e93f1145d4a6ab86a7405b -
Trigger Event:
release
-
Statement type: