zigpy-zigate

0.13.4 · active · verified Thu Apr 16

zigpy-zigate is a Python 3 library that provides an implementation for the `zigpy` project, enabling communication with ZiGate based Zigbee radio devices. It acts as a hardware abstraction layer for ZiGate USB, USB-DIN, PiZiGate, and ZiGate Ethernet modules. The library is actively maintained and is primarily used as a backend for Zigbee Home Automation (ZHA) integrations in Home Assistant. Its current version is 0.13.4, with releases generally following the development pace of `zigpy` and Home Assistant's ZHA component.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to initialize a `zigpy` controller with a ZiGate radio. The `zigpy-zigate` library automatically registers the 'zigate' radio type when imported. You need to provide the correct serial port path for your ZiGate device. For Ethernet ZiGate, use a `socket://IP:PORT` format. This example initializes the controller and keeps the event loop running; a real application would then build and manage the Zigbee network.

import asyncio
import os
from zigpy.application import Controller
from zigpy.config import CONF_DEVICE, CONF_DEVICE_PATH, CONF_RADIO_TYPE

# Ensure zigpy-zigate is imported so its radio type is registered
import zigpy_zigate # noqa: F401

async def main():
    # Replace '/dev/ttyUSB0' with your ZiGate's serial port
    # For PiZiGate, it might be '/dev/serial0' or '/dev/ttyAMA0'
    # For ZiGate Ethernet, it would be 'socket://IP_ADDRESS:PORT'
    zigate_port = os.environ.get('ZIGATE_PORT', '/dev/ttyUSB0')

    config = {
        CONF_DEVICE: {
            CONF_DEVICE_PATH: zigate_port,
            CONF_RADIO_TYPE: 'zigate'
        }
    }

    controller = None
    try:
        print(f"Initializing zigpy Controller with ZiGate on {zigate_port}...")
        controller = await Controller.new(config)
        print("Zigbee network initialized. Controller is running.")
        # In a real application, you would now interact with the controller
        # e.g., controller.add_endpoint(), controller.start_network(), etc.
        print("Controller object created. You can now use it to manage your Zigbee network.")
        print("Press Ctrl+C to stop.")
        await asyncio.Event().wait() # Keep the event loop running indefinitely
    except Exception as e:
        print(f"Error during zigpy initialization: {e}")
    finally:
        if controller:
            await controller.shutdown()
            print("Controller shut down.")

if __name__ == "__main__":
    asyncio.run(main())

view raw JSON →