python library for the zigate gateway (zigbee) http://zigate.fr
Project description
# zigate
[![Build Status](https://travis-ci.org/doudz/zigate.svg?branch=master)](https://travis-ci.org/doudz/zigate)
[![PyPI version](https://badge.fury.io/py/zigate.svg)](https://pypi-hypernode.com/pypi/zigate)
[![Average time to resolve an issue](http://isitmaintained.com/badge/resolution/doudz/zigate.svg)](http://isitmaintained.com/project/doudz/zigate "Average time to resolve an issue")
[![Percentage of issues still open](http://isitmaintained.com/badge/open/doudz/zigate.svg)](http://isitmaintained.com/project/doudz/zigate "Percentage of issues still open")
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:
```bash
pip3 install zigate
```
Or if you've planned to use mqtt
```bash
pip3 install zigate[mqtt]
```
### Usage
```python
# if you want logging
import logging
logging.basicConfig()
logging.root.setLevel(logging.DEBUG)
import zigate
z = zigate.connect(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
```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.connect()
# to catch any events
dispatcher.connect(my_callback, dispatcher.Any)
```
event can be :
```python
zigate.ZIGATE_DEVICE_ADDED
zigate.ZIGATE_DEVICE_UPDATED
zigate.ZIGATE_D
```
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:
```python
import zigate
z = zigate.connect(host='192.168.0.10')
# or if you want to set the port
z = zigate.connect(host='192.168.0.10:1234')
```
## MQTT Broker
This requires paho-mqtt. It could be install as a dependency with `pip3 install zigate[mqtt]`
```bash
python3 -m zigate.mqtt_broker --device auto --mqtt_host localhost:1883
```
Add `--mqtt_username` and `--mqtt_password` as 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 :
```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 :
```python
{"addr": "522a"}
```
zigate/attribute_changed/[addr]/[endpoint]/[cluster]/[attribute] payload is changed attribute.
Payload example :
```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:
```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 :
```python
{"function": "permit_join", "result": 0}
```
All the zigate functions can be call:
```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)
```
[![Build Status](https://travis-ci.org/doudz/zigate.svg?branch=master)](https://travis-ci.org/doudz/zigate)
[![PyPI version](https://badge.fury.io/py/zigate.svg)](https://pypi-hypernode.com/pypi/zigate)
[![Average time to resolve an issue](http://isitmaintained.com/badge/resolution/doudz/zigate.svg)](http://isitmaintained.com/project/doudz/zigate "Average time to resolve an issue")
[![Percentage of issues still open](http://isitmaintained.com/badge/open/doudz/zigate.svg)](http://isitmaintained.com/project/doudz/zigate "Percentage of issues still open")
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:
```bash
pip3 install zigate
```
Or if you've planned to use mqtt
```bash
pip3 install zigate[mqtt]
```
### Usage
```python
# if you want logging
import logging
logging.basicConfig()
logging.root.setLevel(logging.DEBUG)
import zigate
z = zigate.connect(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
```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.connect()
# to catch any events
dispatcher.connect(my_callback, dispatcher.Any)
```
event can be :
```python
zigate.ZIGATE_DEVICE_ADDED
zigate.ZIGATE_DEVICE_UPDATED
zigate.ZIGATE_D
```
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:
```python
import zigate
z = zigate.connect(host='192.168.0.10')
# or if you want to set the port
z = zigate.connect(host='192.168.0.10:1234')
```
## MQTT Broker
This requires paho-mqtt. It could be install as a dependency with `pip3 install zigate[mqtt]`
```bash
python3 -m zigate.mqtt_broker --device auto --mqtt_host localhost:1883
```
Add `--mqtt_username` and `--mqtt_password` as 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 :
```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 :
```python
{"addr": "522a"}
```
zigate/attribute_changed/[addr]/[endpoint]/[cluster]/[attribute] payload is changed attribute.
Payload example :
```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:
```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 :
```python
{"function": "permit_join", "result": 0}
```
All the zigate functions can be call:
```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)
```
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
zigate-0.20.0.tar.gz
(28.3 kB
view details)
Built Distribution
zigate-0.20.0-py3-none-any.whl
(34.7 kB
view details)
File details
Details for the file zigate-0.20.0.tar.gz
.
File metadata
- Download URL: zigate-0.20.0.tar.gz
- Upload date:
- Size: 28.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.18.4 setuptools/40.2.0 requests-toolbelt/0.8.0 tqdm/4.23.4 CPython/3.6.7rc1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | f1eec43f21194eb5be7bf9a1cae1ce8e5c3ee29fe383232485dfa23f6fe56b32 |
|
MD5 | 9328a19edf7d00e8c15aace93238afb0 |
|
BLAKE2b-256 | d1a78f41de1c019c6a582d47b68ec6ed4d57b486166969468cf2f1a00b7c52d6 |
Provenance
File details
Details for the file zigate-0.20.0-py3-none-any.whl
.
File metadata
- Download URL: zigate-0.20.0-py3-none-any.whl
- Upload date:
- Size: 34.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.18.4 setuptools/40.2.0 requests-toolbelt/0.8.0 tqdm/4.23.4 CPython/3.6.7rc1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | c6891e6211f4599e44c2248d2db59272790abcb17f31a5af6fc16364d8b07577 |
|
MD5 | b9f42c39d7e9687412e70e28e3991f35 |
|
BLAKE2b-256 | 82894adf56097cae9d4b0d36622849afc6aa0ab0d50d10e5e356fe0b84aa224a |