Skip to main content

Simple API to access BTicino/Legrand Classe 100X/300X devices

Project description

pybticino

PyPI CI Python License

Async Python library for the BTicino/Netatmo API. Controls BTicino Classe 100X/300X video intercom systems via the Netatmo cloud.

Used by the bticino_intercom Home Assistant integration.

Installation

pip install pybticino

Requires Python 3.13 or later.

Features

  • Authentication: OAuth2 password grant with automatic token refresh and persistence support
  • Home topology: fetch homes, modules, and their configuration
  • Device control: lock/unlock doors, turn lights on/off
  • Events: fetch call history with snapshots and vignettes
  • WebSocket: real-time push notifications (call events, connection status, state changes)
  • Re-subscribe: refresh OAuth token on existing connection without reconnecting
  • WebRTC signaling: offer/answer/ICE exchange for live video calls (experimental)

Quick start

import asyncio
from pybticino import AuthHandler, AsyncAccount

async def on_token_change(tokens):
    """Called when tokens are refreshed — persist them to avoid re-auth."""
    print(f"New token expires at {tokens['expires_at']}")

async def main():
    auth = AuthHandler(
        "your_email@example.com",
        "your_password",
        token_callback=on_token_change,  # optional: persist tokens
    )
    account = AsyncAccount(auth)

    await account.async_update_topology()
    for home_id, home in account.homes.items():
        print(f"Home: {home.name} ({len(home.modules)} modules)")

        status = await account.async_get_home_status(home_id)
        events = await account.async_get_events(home_id, size=5)

    await auth.close_session()

asyncio.run(main())

To restore tokens from a previous session (skip initial auth):

auth = AuthHandler("email", "password", token_callback=on_token_change)
auth.set_tokens(
    access_token=saved["access_token"],
    refresh_token=saved["refresh_token"],
    expires_at=saved["expires_at"],
)

WebSocket (real-time events)

import asyncio
from pybticino import AuthHandler, WebsocketClient

async def on_message(message):
    print(f"Event: {message.get('push_type')} - {message}")

async def main():
    auth = AuthHandler("your_email@example.com", "your_password")
    ws = WebsocketClient(auth, on_message)

    # Option 1: run forever with auto-reconnect (recommended)
    await ws.run_forever(reconnect_delay=30)

    # Option 2: manual connect + listen
    await ws.connect()
    task = ws.get_listener_task()
    if task:
        await task
    await ws.disconnect()

    await auth.close_session()

asyncio.run(main())

Re-subscribe (keep connection alive)

# Refresh token on existing connection without disconnecting.
# Call this periodically (e.g., every hour) to prevent token expiry.
await ws.resubscribe()

API endpoints

Method Endpoint Description
async_update_topology() /api/homesdata Fetch homes and modules
async_get_home_status(home_id) /syncapi/v1/homestatus Get module status
async_set_module_state(home_id, module_id, state) /syncapi/v1/setstate Control devices
async_get_events(home_id, size) /api/getevents Get event history
async_get_turn_servers() /turn Fetch TURN/STUN ICE server credentials for WebRTC

WebSocket event types

Events are delivered with push_type in format {DEVICE_TYPE}-{EVENT_TYPE}:

push_type Description
BNC1-rtc Incoming WebRTC call (with SDP offer)
BNC1-incoming_call Doorbell ring (with snapshot URL)
BNC1-missed_call Unanswered call
BNC1-accepted_call Call answered
BNC1-connection Bridge connected
BNC1-disconnection Bridge disconnected

Documentation

Full documentation at k-the-hidden-hero.github.io/pybticino

Key guides from reverse engineering:

Examples

Working example scripts in examples/:

Script Description
webrtc_offer_mode.py On-demand video: send offer → receive answer → ICE → connected
webrtc_answer_mode.py Answer incoming call: wait for doorbell → answer via signaling
webrtc_audio_test.html Browser-based audio test with silence oscillator
websocket_test.py Real-time push notification listener

Related projects

Contributing

pip install -e ".[test,dev]"
pytest tests/ -v
ruff check src/ tests/

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pybticino-1.8.2.tar.gz (81.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pybticino-1.8.2-py3-none-any.whl (28.9 kB view details)

Uploaded Python 3

File details

Details for the file pybticino-1.8.2.tar.gz.

File metadata

  • Download URL: pybticino-1.8.2.tar.gz
  • Upload date:
  • Size: 81.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for pybticino-1.8.2.tar.gz
Algorithm Hash digest
SHA256 b8da5a5fc3fa4a0aa6941bd397ed24de86e12f96b6bb4c0ba9227322f7a5e369
MD5 1469a95876d1da63dd88cb5503e12ee7
BLAKE2b-256 056d3194b615fba7d2f5feef1d4230e9e860fe8bc7d1607a1afb71c5cd9a5b3a

See more details on using hashes here.

Provenance

The following attestation bundles were made for pybticino-1.8.2.tar.gz:

Publisher: release.yml on k-the-hidden-hero/pybticino

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pybticino-1.8.2-py3-none-any.whl.

File metadata

  • Download URL: pybticino-1.8.2-py3-none-any.whl
  • Upload date:
  • Size: 28.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for pybticino-1.8.2-py3-none-any.whl
Algorithm Hash digest
SHA256 1342523b9a9d5ba050bdd8589f89ab57b149900c8fd1306a55e7d90a09346355
MD5 04336b160ce68963c12b9deadd159202
BLAKE2b-256 7b80b840597eb481ee39d5b3c1b02c72e0545c64f1e95aa2e4b670f26cb5e3f1

See more details on using hashes here.

Provenance

The following attestation bundles were made for pybticino-1.8.2-py3-none-any.whl:

Publisher: release.yml on k-the-hidden-hero/pybticino

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page