High availability Bluetooth

6.0.0 · active · verified Sun Apr 12

habluetooth is a Python library providing high-availability Bluetooth scanning and device management, built on top of Bleak. It aims to offer robust Bluetooth integration, often used in home automation contexts. The current version is 6.0.0. The project maintains an active and frequent release cadence, often with multiple updates per month, incorporating new features and bug fixes.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to initialize the `BluetoothManager`, set up a `HaBleakScannerWrapper`, and asynchronously iterate over discovered Bluetooth devices and their advertisement data. Run this script to see local Bluetooth devices and their basic information.

import asyncio
from habluetooth import BluetoothManager, HaBleakScannerWrapper

async def main():
    manager = BluetoothManager()
    await manager.async_setup()
    scanner = HaBleakScannerWrapper(manager)

    print("Starting Bluetooth scan...")
    async with scanner:
        # Iterate over discovered devices and their advertisement data
        async for device, advertisement_data in scanner.advertisement_data:
            print(f"Device: {device.name or device.address}, RSSI: {advertisement_data.rssi}, Services: {advertisement_data.service_uuids}")
            # Uncomment the line below to stop after the first detected device
            # break
    await manager.async_stop()

if __name__ == "__main__":
    try:
        asyncio.run(main())
    except KeyboardInterrupt:
        print("Scan interrupted by user.")

view raw JSON →