Bellows

0.49.0 · active · verified Thu Apr 16

Bellows is a Python 3 library that implements the EmberZNet Serial Protocol (EZSP) to add Zigbee radio support for Silicon Labs EM35x and EFR32-based Zigbee coordinator devices. While it can function as a standalone library, its primary goal is to integrate these devices with Home Assistant's built-in ZHA (Zigbee Home Automation) component. The library is actively developed, with frequent releases, and the current version is 0.49.0.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to initialize the `bellows` library to connect to a Zigbee coordinator and start a Zigbee network. It requires a serial port where your EZSP-compatible Zigbee adapter is connected. The `asyncio` event loop is essential for `bellows` operations. Remember to replace the placeholder serial port with your actual device path.

import asyncio
from bellows.ezsp import EZSP
from bellows.zigbee.application import ControllerApplication

async def main():
    # Replace '/dev/ttyUSB0' with your serial port, e.g., 'COM3' on Windows
    # and adjust baudrate if necessary (default 115200)
    # For real use, ensure database_file is persistent.
    serial_port = os.environ.get('BELLOWS_SERIAL_PORT', '/dev/ttyUSB0')
    database_file = os.environ.get('BELLOWS_DATABASE_FILE', 'zigbee.db')

    print(f"Connecting to {serial_port} and using database {database_file}")

    try:
        ezsp = await EZSP.probe_and_connect(serial_port, 115200)
        application = ControllerApplication(ezsp, database_file)
        await application.startup(auto_form=True)
        print("Zigbee network started successfully!")
        # Keep the application running, e.g., for event listening or CLI interaction
        while True:
            await asyncio.sleep(3600) # Keep alive indefinitely

    except Exception as e:
        print(f"Error during Zigbee application startup: {e}")
    finally:
        if 'application' in locals() and application.state.running: # Check if application was successfully started and is still running
            await application.shutdown()
            print("Zigbee application shut down.")

if __name__ == '__main__':
    import os
    # Example of setting environment variables for demonstration
    # os.environ['BELLOWS_SERIAL_PORT'] = '/dev/ttyUSB0'
    # os.environ['BELLOWS_DATABASE_FILE'] = '/tmp/my_zigbee_network.db'
    
    asyncio.run(main())

view raw JSON →