Skip to main content

sma-net2

An asynchronous Python client for the legacy SMA-Net2 Bluetooth Classic protocol. It discovers and authenticates SMA inverters and reads measurements and the inverter's five-minute archive. It has no Home Assistant dependency.

This is the communication library extracted from SMA-Net2 Bluetooth for Home Assistant.

Requirements

  • Python 3.11 or newer, on Linux with Bluetooth Classic RFCOMM support.
  • A local Bluetooth adapter and SMA-Net2-capable inverter within radio range.
  • The SMA user password, not an installer password or Bluetooth pairing PIN.
  • For optional discovery: access to BlueZ on the system D-Bus.

ESPHome BLE proxies do not support this protocol. The known tested hardware is SMA Sunny Boy SB 3000HF-30; other legacy Bluetooth models may provide different measurement sets. This project is not affiliated with or endorsed by SMA.

Installation

Install a published release from PyPI:

python -m pip install sma-net2==0.1.0

Development installation

For development, install from the package source directory:

python -m pip install -e '.[test]'

Read measurements

import asyncio
import os

from sma_net2 import SMAClassicClient


async def main():
    async with SMAClassicClient(
        os.environ["SMA_BT_ADDRESS"],
        os.environ["SMA_USER_PASSWORD"],
        connection_mode="auto",
    ) as client:
        inverters = await client.async_query()
        for serial, inverter in inverters.items():
            print(serial, inverter.model, inverter.values)


asyncio.run(main())

auto uses direct mode for NetID 1 and network mode for NetID 2–F. single reads only the selected inverter. network requires NetID 2–F. The result maps serial-number strings to SMAInverter objects. Missing measurements remain unknown; energy counters and source timestamps are not altered to hide resets or backwards readings.

Use one client per session and serialize clients sharing a Bluetooth adapter. The library does not apply Home Assistant's daylight scheduling, retry policy, adapter recovery, entity ownership or Recorder import policy; the caller owns those decisions. Inverters are normally unreachable at night.

async_query(), async_read_archive(periods) and async_sync_clock(...) each start and stop an authenticated session inside the open RFCOMM context. For multiple operations in one session, call async_start_session(), use the corresponding *_active() methods, and call async_stop_session() in finally. Clock synchronization writes to the plant clock and is explicitly invoked, with bounds and a minimum interval checked by the client.

async_read_archive() accepts Unix start/end timestamp pairs (end exclusive), and returns a mapping from each serial to a list of SMAArchivePoint objects. No Home Assistant statistics are written. Original source ordering is preserved. Discovery is available as from sma_net2.discovery import async_discover_sma_devices and returns a mapping of Bluetooth addresses to display names.

Catch SMAAuthenticationError for incorrect credentials, SMAConfigurationError/SMANetworkModeError for incompatible topology, and SMATransportError for connection failures. These derive from SMAProtocolError. The async context manager closes the socket on exit.

Offline tests and distribution build

python -m coverage run -m unittest discover -s tests -v
python -m coverage report
python -m build
python -m twine check dist/*

The tests use mock sockets and D-Bus objects; they never contact an inverter or change its clock. The CI workflow tests Python 3.11 and 3.14, builds a wheel and source distribution, checks metadata, and installs both artifacts in isolated environments without Home Assistant. Release tags use sma-net2-v<VERSION> and must match the version in pyproject.toml.

License and attribution

GPL-3.0-or-later. The protocol adapts the GPLv3-or-later work of Wim Hofman and Stephen Collier (2010–2011) in sma-bluetooth/sma-bluetooth. All original notices and the complete GPL license are retained. This extraction does not relicense the protocol. The optional BlueZ discovery uses the OSI-licensed dbus-fast package.

Metadata

Release files for sma-net2 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for sma-net2 0.1.0
File Size Uploaded
sma_net2-0.1.0.tar.gz 37.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for sma-net2 0.1.0
File Interpreter ABI Platform
sma_net2-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 64.8 kB

Release files / sma_net2-0.1.0.tar.gz

Download URL sma_net2-0.1.0.tar.gz
Size 37.5 kB
Tags Source
SHA-256 checksum
How to use checksums
476b628a57e7ba018f362048f0d0b567592b9c6c4f5e4dfd4e352bd15c1caba3
BLAKE2b-256 checksum
How to use checksums
01565b4a88a4a174a8ae9de1373d147cb16955754257da78a5360192cb43378d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 8, 2026.

Transparency log

Release files / sma_net2-0.1.0-py3-none-any.whl

Download URL sma_net2-0.1.0-py3-none-any.whl
Size 27.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
e485a68d013a641da8bb834fa34523cf73404371850cf65e1aa7716ce73bc3bd
BLAKE2b-256 checksum
How to use checksums
c8352160eb2f8a441f4216cae591d628408bda7e861f36bf65d5c0e7276dce3d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 8, 2026.

Transparency log

Release history Release notifications | RSS feed

0.1.2

2 release files

0.1.1

2 release files

This release

0.1.0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page