Package: zigate
zigatePython library forZiGate.
This library manage communication between python and zigate key, both USB and WiFi key are supported.ZiGate is an universal gateway compatible with a lot of ZigBee device (like Xiaomi, Philipps Hue, Ikea, etc).Getting StartedInstallationTo install simply do:pip3installzigateOr if you've planned to use mqttpip3installzigate[mqtt]Usage# if you want loggingimportlogginglogging.basicConfig()logging.root.setLevel(logging.DEBUG)importzigatez=zigate.connect(port=None)# Leave None to auto-discover the portprint(z.get_version())OrderedDict([('major',1),('installer','30c'),('rssi',0),('version','3.0c')])print(z.get_version_text())3.0c# refresh devices listz.get_devices_list()# start inclusion mode>>>z.permit_join()>>>z.is_permitting_join()True# list devices>>>z.devices[Device677c,Deviceb8ce,Device92a7,Device59ef]>>>z.devices[0].addr'677c'# get all discovered endpoints>>>z.devices[0].endpoints{1:{'clusters':{0:Cluster0General:Basic,1026:Cluster1026Measurement:Temperature,1027:Cluster1027Measurement:AtmosphericPressure,1029:Cluster1029Measurement:Humidity},}}# get well known attributes>>>forattributeinz.devices[0].properties:print(attribute){'data':'lumi.weather','name':'type','attribute':5,'value':'lumi.weather'}{'data':'0121c70b0421a8010521090006240100000000642932096521851c662bd87c01000a210000','name':'battery','value':3.015,'unit':'V','attribute':65281}{'data':-1983,'name':'temperature','value':-19.83,'unit':'°C','attribute':0}{'data':9779,'name':'pressure2','value':977.9,'unit':'mb','attribute':16}{'data':977,'name':'pressure','value':977,'unit':'mb','attribute':0}{'data':4484,'name':'humidity','value':44.84,'unit':'%','attribute':0}# get specific property>>>z.devices[0].get_property('temperature'){'data':-1983,'name':'temperature','value':-19.83,'unit':'°C','attribute':0}# call action on devicesz.action_onoff('b8ce',1,zigate.ON)# or from devicesz.devices[1].action_onoff(zigate.ON)# OTA process# Load image and send headers to ZiGatez.ota_load_image('path/to/ota/image_file.ota')# Tell client that image is availablez.ota_image_notify('addr')# It will take client usually couple seconds to query headers# from server. Upgrade process start automatically if correct# headers are loaded to ZiGate. If you have logging level debug# enabled you will get automatically progress updates.# Manually check ota status - logging level INFOz.get_ota_status()# Whole upgrade process time depends on device and ota image size# Upgrading ikea bulb took ~15 minutes# Upgrading ikea remote took ~45 minutesOTA UpdateSome devices (like Ikea Tradfri) could be updated.
For Ikea, you could download available OTA files using the following command :python3 zigate.ikea_ota_download# OTA process# Load image and send headers to ZiGatez.ota_load_image('path/to/ota/image_file.ota')# Tell client that image is availablez.ota_image_notify('addr')# It will take client usually couple seconds to query headers# from server. Upgrade process start automatically if correct# headers are loaded to ZiGate. If you have logging level debug# enabled you will get automatically progress updates.# Manually check ota status - logging level INFOz.get_ota_status()# Whole upgrade process time depends on device and ota image size# Upgrading ikea bulb took ~15 minutes# Upgrading ikea remote took ~45 minutesCallbackWe use pydispatcher for callbackfromzigateimportdispatcherdefmy_callback(sender,signal,**kwargs):print(sender)# zigate instanceprint(signal)# one of EVENTprint(kwargs)# contains device and/or attribute changes, etcdispatcher.connect(my_callback,zigate.ZIGATE_ATTRIBUTE_UPDATED)z=zigate.connect()# orz=zigate.connect(port='/dev/ttyUSB0')# to catch any eventsdispatcher.connect(my_callback,dispatcher.Any)event can be :zigate.ZIGATE_DEVICE_ADDEDzigate.ZIGATE_DEVICE_UPDATEDzigate.ZIGATE_DEVICE_REMOVEDzigate.ZIGATE_DEVICE_ADDRESS_CHANGEDzigate.ZIGATE_ATTRIBUTE_ADDEDzigate.ZIGATE_ATTRIBUTE_UPDATEDzigate.ZIGATE_DEVICE_NEED_DISCOVERYkwargs depends of the event type:forzigate.ZIGATE_DEVICE_ADDEDkwargs contains device.forzigate.ZIGATE_DEVICE_UPDATEDkwargs contains device.forzigate.ZIGATE_DEVICE_REMOVEDkwargs contains addr (the device short address).forzigate.ZIGATE_DEVICE_ADDRESS_CHANGEDkwargs contains old_addr and new_addr (used when re-pairing an already known device).forzigate.ZIGATE_ATTRIBUTE_ADDEDkwargs contains device and discovered attribute.forzigate.ZIGATE_ATTRIBUTE_UPDATEDkwargs contains device and updated attribute.forzigate.ZIGATE_DEVICE_NEED_DISCOVERYkwargs contains device.Wifi ZiGateWiFi ZiGate is also supported:importzigatez=zigate.connect(host='192.168.0.10')# or if you want to set the portz=zigate.connect(host='192.168.0.10:1234')PiZiGatePiZiGate (ZiGate module for raspberry pi) is also supported:importzigatez=zigate.connect(gpio=True)# or if you want to set the portz=zigate.connect(port='/dev/serial0',gpio=True)To be able to use the PiZiGate on Rpi3 you need to disable the bluetooth module.
To disable bluetooth:Adddtoverlay=pi3-disable-btin/boot/config.txtRemoveconsole=serial0,115200from/boot/cmdline.txtDisable hciuartsudo systemctl disable hciuartAdd user to gpio group, example with pi usersudo usermod -aG gpio piandrebootAlternatively you could set mini uart for bluetooth or for zigate but be aware that there's performance issue.MQTT BrokerThis requires paho-mqtt. It could be install as a dependency withpip3 install zigate[mqtt]python3-mzigate.mqtt_broker--deviceauto--mqtt_hostlocalhost:1883Add--mqtt_usernameand--mqtt_passwordas arguments and allow them to be used to establish connection to the MQTT broker.The broker publish the following topics: zigate/device_changed/[addr]Payload example :'zigate/device_changed/522a'{"addr":"522a","endpoints":[{"device":0,"clusters":[{"cluster":1026,"attributes":[{"value":22.27,"data":2227,"unit":"\u00b0C","name":"temperature","attribute":0}]},{"cluster":1027,"attributes":[{"value":977,"data":977,"unit":"mb","name":"pressure","attribute":0},{"value":977.7,"data":9777,"unit":"mb","name":"pressure2","attribute":16},{"data":-1,"attribute":20}]},{"cluster":1029,"attributes":[{"value":35.03,"data":3503,"unit":"%","name":"humidity","attribute":0}]}],"profile":0,"out_clusters":[],"in_clusters":[],"endpoint":1}],"info":{"power_source":0,"ieee":"158d0002271c25","addr":"522a","id":2,"rssi":255,"last_seen":"2018-02-21 09:41:27"}}zigate/device_removed.
Payload example :{"addr":"522a"}zigate/attribute_changed/[addr]/[endpoint]/[cluster]/[attribute] payload is changed attribute.
Payload example :'zigate/attribute_changed/522a/01/0403/0010'{"cluster":1027,"value":978.5,"data":9785,"attribute":16,"unit":"mb","endpoint":1,"addr":"522a","name":"pressure2"}You can send command to zigate using the topic zigate/command payload should be:{"function":"function_name","args":["optional","args","list"]}# example to start permit joinpayload='{"function": "permit_join"}'client.publish('zigate/command',payload)The broker will publish the result using the topic "zigate/command/result".
Payload example :{"function":"permit_join","result":0}All the zigate functions can be call:# turn on endpoint 1payload='{"function": "action_onoff", "args": ["522a", 1, 1]}'client.publish('zigate/command',payload)# turn off endpoint 1payload='{"function": "action_onoff", "args": ["522a", 1, 0]}'client.publish('zigate/command',payload)FlasherPython tool to flash your Zigate (Jennic JN5168)Thanks to Sander Hoentjen (tjikkun) we now have a flasher !Original repoFlasher Usageusage:python3-mzigate.flasher[-h]-p{/dev/ttyUSB0}[-wWRITE][-sSAVE][-u][-d][--gpio][--din]optionalarguments:-h,--helpshowthishelpmessageandexit-p{/dev/ttyUSB0},--serialport{/dev/ttyUSB0}Serialport,e.g./dev/ttyUSB0-wWRITE,--writeWRITEFirmwarebintoflashontothechip-sSAVE,--saveSAVEFiletosavethecurrentlyloadedfirmwareto-u,--upgradeDownloadandflashthelastestavailablefirmware-d,--debugSetlogleveltoDEBUG--gpioConfigureGPIOforPiZiGateflash--dinConfigureUSBforZiGateDINflashCommand Line Interfaceusage:python3-mzigate[-h][--portPORT][--hostHOST][--pathPATH][--gpio][--channelCHANNEL][--admin_panel]optionalarguments:-h,--helpshowthishelpmessageandexit--portPORTZiGateusbport--hostHOSTWifiZiGatehost:port--pathPATHZiGatestatefilepath--gpioEnablePiZigate--channelCHANNELZigbeechannel--admin_panelEnableAdminpanelHow to contributeIf you are looking to make a contribution to this project we suggest that you follow the steps in these guides:https://github.com/firstcontributions/first-contributions/blob/master/README.mdhttps://github.com/firstcontributions/first-contributions/blob/master/github-desktop-tutorial.mdSome developers might also be interested in receiving donations in the form of hardware such as Zigbee modules or devices, and even if such donations are most often donated with no strings attached it could in many cases help the developers motivation and indirect improve the development of this project.Comment contribuerSi vous souhaitez apporter une contribution à ce projet, nous vous suggérons de suivre les étapes décrites dans ces guides:https://github.com/firstcontributions/first-contributions/blob/master/README.mdhttps://github.com/firstcontributions/first-contributions/blob/master/github-desktop-tutorial.mdCertains développeurs pourraient également être intéressés par des dons sous forme de matériel, tels que des modules ou des dispositifs Zigbee, et même si ces dons sont le plus souvent donnés sans aucune condition, cela pourrait dans de nombreux cas motiver les développeurs et indirectement améliorer le développement de ce projet.