Code example¶
Here is a simple example of pyzigbee library usage (see: pyzigbee/examples/088328/scan.py)
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from __future__ import print_function
from contextlib import closing
from pyzigbee.gateways.factory import GatewayFactory
def scan():
"""
Scan the network looking for zigbee devices and print the found IDs
"""
# Note that you may need to pass a configuration file to
# the GatewayFactory since your low level device may be different
# from the default one. Please read the 'Configuration' section
# of the documentation
gateway = GatewayFactory().create_gateway(ref="088328")
with closing(gateway.open()) as gateway:
ids = gateway.scan()
print("Zigbee devices on the network:", ids)
if __name__ == '__main__':
scan()
You may need to pass a configuration file (see: Configuration) to the factory to be override some driver arguments. Change gateway creation as following:
gateway = GatewayFactory(conf_filename="my_conf.json").create_gateway(ref="088328")
The gateway is the abstraction you will deal with to talk to zigbee devices.