zigate


Namezigate JSON
Version 0.15.0 PyPI version JSON
download
home_pagehttps://github.com/doudz/zigate
Summarypython library for the zigate gateway (zigbee) http://zigate.fr
upload_time2018-04-16 14:40:45
maintainer
docs_urlNone
authorSébastien RAMAGE
requires_python>=3
license
keywords zigate zigbee python3
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            ======
zigate
======

python library for zigate http://zigate.fr/
This library manage communication between python and zigate key, both USB and WiFi key are supported (wifi is almost untested)
ZiGate is an universal gateway compatible with a lot of ZigBee device (like Xiaomi, Philipps Hue, Ikea, etc)


Getting Started
===============

Installation
------------
To install simply do::

    pip3 install zigate


Usage
-----

.. code-block:: python

   # if you want logging
   import logging
   logging.basicConfig()
   logging.root.setLevel(logging.DEBUG)

   import zigate
   z = zigate.ZiGate(port=None) # Leave None to auto-discover the port

   print(z.get_version())
   OrderedDict([('major', 1), ('installer', '30c'), ('rssi', 0), ('version', '3.0c')])

   print(z.get_version_text())
   3.0c

   # refresh devices list
   z.get_devices_list()

   # start inclusion mode
   >>> z.permit_join()
   >>> z.is_permitting_join()
   True

   # list devices
   >>> z.devices
   [Device 677c , Device b8ce , Device 92a7 , Device 59ef ]
   >>> z.devices[0].addr
   '677c'

   # get all discovered endpoints
   >>> z.devices[0].endpoints
   {1: {
     'clusters': {0: Cluster 0 General: Basic,
      1026: Cluster 1026 Measurement: Temperature,
      1027: Cluster 1027 Measurement: Atmospheric Pressure,
      1029: Cluster 1029 Measurement: Humidity},
     }}


   # get well known attributes
   >>> for attribute in z.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 devices
    z.action_onoff('b8ce', 1, zigate.ON)

    or from devices
    z.devices[1].action_onoff(zigate.ON)


Callback
--------
We use pydispatcher for callback

.. code-block:: python

   from pydispatch import dispatcher

   def my_callback(sender, signal, **kwargs):
      print(sender)  # zigate instance
      print(signal)  # one of EVENT
	   print(kwargs)  # contains device and/or attribute changes, etc

   dispatcher.connect(my_callback, zigate.ZIGATE_ATTRIBUTE_UPDATED)

   z = zigate.ZiGate()

   # to catch any events
   dispatcher.connect(my_callback, dispatcher.Any)


event can be :

.. code-block:: python

   zigate.ZIGATE_DEVICE_ADDED
   zigate.ZIGATE_DEVICE_UPDATED
   zigate.ZIGATE_DEVICE_REMOVED
   zigate.ZIGATE_ATTRIBUTE_ADDED
   zigate.ZIGATE_ATTRIBUTE_UPDATED

kwargs depends of the event type
for zigate.ZIGATE_DEVICE_ADDED:
kwargs contains device

for zigate.ZIGATE_DEVICE_UPDATED
kwargs contains device

for zigate.ZIGATE_DEVICE_REMOVED
kwargs contains addr (the device short address)

for zigate.ZIGATE_ATTRIBUTE_ADDED:
kwargs contains device and discovered attribute 

for zigate.ZIGATE_ATTRIBUTE_UPDATED
kwargs contains device and updated attribute



Wifi ZiGate
-----------

WiFi ZiGate is also supported :

.. code-block:: python

   import zigate
   z = zigate.ZiGateWiFi(host='192.168.0.10', port=9999)



MQTT Broker
-----------


python3 -m zigate.mqtt_broker --device auto --mqtt_host localhost:1883

the broker publish the following topics:
zigate/device_changed/[addr]
Payload example :

.. code-block:: python

   '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 :

.. code-block:: python

   {"addr": "522a"}

zigate/attribute_changed/[addr]/[endpoint]/[cluster]/[attribute]
payload is changed attribute
Payload example :

.. code-block:: python

   '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 :

.. code-block:: python

   {"function": "function_name", "args": ["optional","args","list"]}

   # example to start permit join
   payload = '{"function": "permit_join"}'
   client.publish('zigate/command', payload)

The broker will publish the result using the topic "zigate/command/result"
Payload example :

.. code-block:: python

   {"function": "permit_join", "result": 0}

All the zigate functions can be call

.. code-block:: python

   # turn on endpoint 1
   payload = '{"function": "action_onoff", "args": ["522a", 1, 1]}'
   client.publish('zigate/command', payload)

   # turn off endpoint 1
   payload = '{"function": "action_onoff", "args": ["522a", 1, 0]}'
   client.publish('zigate/command', payload)





            

Raw data

            {
    "maintainer": "", 
    "docs_url": null, 
    "requires_python": ">=3", 
    "maintainer_email": "", 
    "cheesecake_code_kwalitee_id": null, 
    "keywords": "zigate zigbee python3", 
    "upload_time": "2018-04-16 14:40:45", 
    "author": "S\u00e9bastien RAMAGE", 
    "home_page": "https://github.com/doudz/zigate", 
    "github_user": "doudz", 
    "download_url": "https://pypi.python.org/packages/89/a7/f6786fd1f2b33d552486e47f6b5d7d32d07b65d5a32d4957ea3d866e202e/zigate-0.15.0.tar.gz", 
    "platform": "", 
    "version": "0.15.0", 
    "cheesecake_documentation_id": null, 
    "description": "======\nzigate\n======\n\npython library for zigate http://zigate.fr/\nThis library manage communication between python and zigate key, both USB and WiFi key are supported (wifi is almost untested)\nZiGate is an universal gateway compatible with a lot of ZigBee device (like Xiaomi, Philipps Hue, Ikea, etc)\n\n\nGetting Started\n===============\n\nInstallation\n------------\nTo install simply do::\n\n    pip3 install zigate\n\n\nUsage\n-----\n\n.. code-block:: python\n\n   # if you want logging\n   import logging\n   logging.basicConfig()\n   logging.root.setLevel(logging.DEBUG)\n\n   import zigate\n   z = zigate.ZiGate(port=None) # Leave None to auto-discover the port\n\n   print(z.get_version())\n   OrderedDict([('major', 1), ('installer', '30c'), ('rssi', 0), ('version', '3.0c')])\n\n   print(z.get_version_text())\n   3.0c\n\n   # refresh devices list\n   z.get_devices_list()\n\n   # start inclusion mode\n   >>> z.permit_join()\n   >>> z.is_permitting_join()\n   True\n\n   # list devices\n   >>> z.devices\n   [Device 677c , Device b8ce , Device 92a7 , Device 59ef ]\n   >>> z.devices[0].addr\n   '677c'\n\n   # get all discovered endpoints\n   >>> z.devices[0].endpoints\n   {1: {\n     'clusters': {0: Cluster 0 General: Basic,\n      1026: Cluster 1026 Measurement: Temperature,\n      1027: Cluster 1027 Measurement: Atmospheric Pressure,\n      1029: Cluster 1029 Measurement: Humidity},\n     }}\n\n\n   # get well known attributes\n   >>> for attribute in z.devices[0].properties:\n       \tprint(attribute)\n   {'data': 'lumi.weather', 'name': 'type', 'attribute': 5, 'value': 'lumi.weather'}\n   {'data': '0121c70b0421a8010521090006240100000000642932096521851c662bd87c01000a210000', 'name': 'battery', 'value': 3.015, 'unit': 'V', 'attribute': 65281}\n   {'data': -1983, 'name': 'temperature', 'value': -19.83, 'unit': '\u00b0C', 'attribute': 0}\n   {'data': 9779, 'name': 'pressure2', 'value': 977.9, 'unit': 'mb', 'attribute': 16}\n   {'data': 977, 'name': 'pressure', 'value': 977, 'unit': 'mb', 'attribute': 0}\n   {'data': 4484, 'name': 'humidity', 'value': 44.84, 'unit': '%', 'attribute': 0}\n\n   # get specific property\n   >>> z.devices[0].get_property('temperature')\n   {'data': -1983,\n    'name': 'temperature',\n    'value': -19.83,\n    'unit': '\u00b0C',\n    'attribute': 0}\n\n    # call action on devices\n    z.action_onoff('b8ce', 1, zigate.ON)\n\n    or from devices\n    z.devices[1].action_onoff(zigate.ON)\n\n\nCallback\n--------\nWe use pydispatcher for callback\n\n.. code-block:: python\n\n   from pydispatch import dispatcher\n\n   def my_callback(sender, signal, **kwargs):\n      print(sender)  # zigate instance\n      print(signal)  # one of EVENT\n\t   print(kwargs)  # contains device and/or attribute changes, etc\n\n   dispatcher.connect(my_callback, zigate.ZIGATE_ATTRIBUTE_UPDATED)\n\n   z = zigate.ZiGate()\n\n   # to catch any events\n   dispatcher.connect(my_callback, dispatcher.Any)\n\n\nevent can be :\n\n.. code-block:: python\n\n   zigate.ZIGATE_DEVICE_ADDED\n   zigate.ZIGATE_DEVICE_UPDATED\n   zigate.ZIGATE_DEVICE_REMOVED\n   zigate.ZIGATE_ATTRIBUTE_ADDED\n   zigate.ZIGATE_ATTRIBUTE_UPDATED\n\nkwargs depends of the event type\nfor zigate.ZIGATE_DEVICE_ADDED:\nkwargs contains device\n\nfor zigate.ZIGATE_DEVICE_UPDATED\nkwargs contains device\n\nfor zigate.ZIGATE_DEVICE_REMOVED\nkwargs contains addr (the device short address)\n\nfor zigate.ZIGATE_ATTRIBUTE_ADDED:\nkwargs contains device and discovered attribute \n\nfor zigate.ZIGATE_ATTRIBUTE_UPDATED\nkwargs contains device and updated attribute\n\n\n\nWifi ZiGate\n-----------\n\nWiFi ZiGate is also supported :\n\n.. code-block:: python\n\n   import zigate\n   z = zigate.ZiGateWiFi(host='192.168.0.10', port=9999)\n\n\n\nMQTT Broker\n-----------\n\n\npython3 -m zigate.mqtt_broker --device auto --mqtt_host localhost:1883\n\nthe broker publish the following topics:\nzigate/device_changed/[addr]\nPayload example :\n\n.. code-block:: python\n\n   'zigate/device_changed/522a'\n   {\"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\"}}\n\nzigate/device_removed \nPayload example :\n\n.. code-block:: python\n\n   {\"addr\": \"522a\"}\n\nzigate/attribute_changed/[addr]/[endpoint]/[cluster]/[attribute]\npayload is changed attribute\nPayload example :\n\n.. code-block:: python\n\n   'zigate/attribute_changed/522a/01/0403/0010'\n   {\"cluster\": 1027, \"value\": 978.5, \"data\": 9785, \"attribute\": 16, \"unit\": \"mb\", \"endpoint\": 1, \"addr\": \"522a\", \"name\": \"pressure2\"}\n\nyou can send command to zigate using the topic zigate/command\npayload should be :\n\n.. code-block:: python\n\n   {\"function\": \"function_name\", \"args\": [\"optional\",\"args\",\"list\"]}\n\n   # example to start permit join\n   payload = '{\"function\": \"permit_join\"}'\n   client.publish('zigate/command', payload)\n\nThe broker will publish the result using the topic \"zigate/command/result\"\nPayload example :\n\n.. code-block:: python\n\n   {\"function\": \"permit_join\", \"result\": 0}\n\nAll the zigate functions can be call\n\n.. code-block:: python\n\n   # turn on endpoint 1\n   payload = '{\"function\": \"action_onoff\", \"args\": [\"522a\", 1, 1]}'\n   client.publish('zigate/command', payload)\n\n   # turn off endpoint 1\n   payload = '{\"function\": \"action_onoff\", \"args\": [\"522a\", 1, 0]}'\n   client.publish('zigate/command', payload)\n\n\n\n\n", 
    "lcname": "zigate", 
    "bugtrack_url": null, 
    "github": true, 
    "coveralls": false, 
    "name": "zigate", 
    "license": "", 
    "travis_ci": false, 
    "github_project": "zigate", 
    "summary": "python library for the zigate gateway (zigbee) http://zigate.fr", 
    "split_keywords": [
        "zigate", 
        "zigbee", 
        "python3"
    ], 
    "author_email": "sebastien.ramage@gmail.com", 
    "urls": [
        {
            "has_sig": false, 
            "upload_time": "2018-04-16T14:40:44", 
            "comment_text": "", 
            "python_version": "py3", 
            "url": "https://pypi.python.org/packages/9b/af/fd9ae2b17935c5f3b74dfd37c67739449c60848f71512969ec6fb4ae3ec6/zigate-0.15.0-py3-none-any.whl", 
            "md5_digest": "8a15dabce09a407c7c492e22ae97e7f6", 
            "downloads": 0, 
            "filename": "zigate-0.15.0-py3-none-any.whl", 
            "packagetype": "bdist_wheel", 
            "path": "9b/af/fd9ae2b17935c5f3b74dfd37c67739449c60848f71512969ec6fb4ae3ec6/zigate-0.15.0-py3-none-any.whl", 
            "digests": {
                "sha256": "4e93c5a615927f84bf4d43aa6159e14310ba10a976232f1cd67e459477ab9b74", 
                "md5": "8a15dabce09a407c7c492e22ae97e7f6"
            }, 
            "sha256_digest": "4e93c5a615927f84bf4d43aa6159e14310ba10a976232f1cd67e459477ab9b74", 
            "size": 29565
        }, 
        {
            "has_sig": false, 
            "upload_time": "2018-04-16T14:40:45", 
            "comment_text": "", 
            "python_version": "source", 
            "url": "https://pypi.python.org/packages/89/a7/f6786fd1f2b33d552486e47f6b5d7d32d07b65d5a32d4957ea3d866e202e/zigate-0.15.0.tar.gz", 
            "md5_digest": "bfff4ef3f0373a7199a0b5e45339cbe0", 
            "downloads": 0, 
            "filename": "zigate-0.15.0.tar.gz", 
            "packagetype": "sdist", 
            "path": "89/a7/f6786fd1f2b33d552486e47f6b5d7d32d07b65d5a32d4957ea3d866e202e/zigate-0.15.0.tar.gz", 
            "digests": {
                "sha256": "c2ff84bc37f3aad9d12a5f82423d6b8cd1a31a694e833dd83d5e9cde9d3378d9", 
                "md5": "bfff4ef3f0373a7199a0b5e45339cbe0"
            }, 
            "sha256_digest": "c2ff84bc37f3aad9d12a5f82423d6b8cd1a31a694e833dd83d5e9cde9d3378d9", 
            "size": 24428
        }
    ], 
    "_id": null, 
    "cheesecake_installability_id": null
}