Home Assistant Bluetooth

2.0.0 · active · verified Wed Apr 15

Home Assistant Bluetooth provides Python models and helpers for integrating Bluetooth devices with Home Assistant. It acts as a wrapper around the `habluetooth` library to offer a consistent API. The current version is 2.0.0, and it follows a release cadence tied to Home Assistant development and dependency updates.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to initialize the `BluetoothManager` and register a callback to receive Bluetooth advertisement data. It will continuously listen for advertisements until interrupted.

import asyncio
from home_assistant_bluetooth import BluetoothManager, BluetoothServiceInfoBleak

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

    def advertisement_callback(service_info: BluetoothServiceInfoBleak):
        print(f"Advertisement: {service_info.name} ({service_info.address}) - RSSI: {service_info.rssi}")
        if service_info.service_data:
            print(f"  Service Data: {service_info.service_data}")
        if service_info.service_uuids:
            print(f"  Service UUIDs: {service_info.service_uuids}")

    manager.async_register_service_info_callback(advertisement_callback)

    print("Listening for Bluetooth advertisements... Press Ctrl+C to stop.")
    try:
        while True:
            await asyncio.sleep(1) # Keep the manager running
    except asyncio.CancelledError:
        pass
    finally:
        await manager.async_stop()

if __name__ == "__main__":
    try:
        asyncio.run(main())
    except KeyboardInterrupt:
        print("\nStopped listening.")

view raw JSON →