Coder Social home page Coder Social logo

pyxiaomigateway's Introduction

pyxiaomigateway's People

Contributors

anderen2 avatar crhan avatar cxlwill avatar danielhiversen avatar dlashua avatar fabricepipart avatar karlkar avatar mickeprag avatar paulannekov avatar schumyhao avatar slhack83 avatar starkillerog avatar stayhf avatar syssi avatar tiandeyu avatar xiwenc avatar yegong avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

pyxiaomigateway's Issues

messages of magnet sensor's CLOSE events could been lost sometimes

home-assistant/core#14982

HA installed PyXiaomiGateway v0.9.4 which has the possibility of about 10% of losing close events of magnet sensor.
At the same time, I have a C# program running on another PC (windows), also collecting the multi-cast messages from the gateway, it's quite correct. Thus I can believe the reason is not network issue.

Could you pls help to find the reason? thks~

"Invalid key" after some requests

When im Wrong here fell free to close or delete or put me in the right direction.
Also please rename it, my creativity is at the end

just seted up the Gateway with Home Assistant, and well.. It refuses to work propertly.
seted up one button (lumi.sensor_switch.v2)
Also the host option HAVE to be configured - otherwise the gatwav wont be found

For example the Lux sensor on the gateway.
https://image.ibb.co/d4DgQd/Lux2.jpg
(it got data from 20:34 until 21:09 rest of the time.. dead?)

The Button just works for 25- 30 secconds after the first click.
You can click rapidly for minutes, but when you stop, its not reacting anymore
so click again after that time period and nothing happens. ( not even invalid key)

Turning the Light on the Gateway on and off is poison - instant error with invalid key

Restarting HA resetting this problem

I'ts maybe the hardware, not shure.
hw_ver: MW300 - model Lumi.gatewav.v3
just updated to 1.4.1_155 - didnt changed behaviur
mcu_fw 0143

The app says
version code 187
Plugin version 2.56.3

Home Assistant
0.69.0

Logs:
https://hastebin.com/nivazicifi.rb
https://hastebin.com/uconoqeden.hs
https://hastebin.com/ohiciribuq.coffeescript
https://hastebin.com/leguhoyava.scala

Xiaomi Aqara Wall Switch not detected correctly

I installed a Xiaomi Aqara ZigBee Wall Switch (single).
Here's the product:

It works fine with the Xiaomi ios app.
However, it's not detected in hass.

Here's the error from the log file:

2018-02-19 21:02:02 ERROR (Thread-2) [xiaomi_gateway] Unsupported device found! Please create an issue at https://github.com/Danielhiversen/PyXiaomiGateway/issues and provide the following data: {'sid': '158d0001f2b07e', 'data': '{"voltage":3600,"channel_0":"on"}', 'model': '', 'cmd': 'read_ack', 'short_id': 27328}

Rewrite the way of working with UDP traffic in XiaomiGateway._send_cmd()

The whole way of dealing with UDP traffic is wrong there. Compared to TCP, UDP guarantees almost nothing.
https://github.com/Danielhiversen/PyXiaomiGateway/blob/master/xiaomi_gateway/__init__.py#L268
The code assumes it will get a response to the request above, but it's too naive. UDP doesn't guarantee order and delivery. Multiple UDP dispatches at the same time can make a lot of bad things, like each recvfrom() will get the result of the neighbour. Here is an example of this bug in HA:

20:00:53 DEBUG (SyncWorker_12) [xiaomi_gateway] >> b'{ "cmd":"read","sid":"1"}'
20:00:53 DEBUG (SyncWorker_2) [xiaomi_gateway] >> b'{"cmd": "write", "sid": "2", "data": {"rgb": 0, "key": "xxx"}}'
20:00:53 DEBUG (SyncWorker_2) [xiaomi_gateway] << {'cmd': 'read_ack', 'model': 'magnet', 'sid': '1', 'short_id': 43528, 'data': '{"voltage":3035,"status":"open"}'}
20:00:53 ERROR (SyncWorker_2) [xiaomi_gateway] Non matching response. Expecting write_ack, but got read_ack. {'cmd': 'read_ack', 'model': 'magnet', 'sid': '1', 'short_id': 43528, 'data': '{"voltage":3035,"status":"open"}'}
20:00:53 ERROR (SyncWorker_2) [xiaomi_gateway] No data in response from hub None
20:00:53 DEBUG (SyncWorker_12) [xiaomi_gateway] << {'cmd': 'write_ack', 'model': 'gateway', 'sid': '2', 'short_id': 0, 'data': '{"rgb":0,"illumination":312,"proto_version":"1.0.9"}'}
20:00:53 ERROR (SyncWorker_12) [xiaomi_gateway] Non matching response. Expecting read_ack, but got write_ack. {'cmd': 'write_ack', 'model': 'gateway', 'sid': '2', 'short_id': 0, 'data': '{"rgb":0,"illumination":312,"proto_version":"1.0.9"}'}
20:00:53 ERROR (SyncWorker_12) [xiaomi_gateway] No data in response from hub None

Devices didn't get right responses, their states were not updated. In case of 2 simultaneous reads, devices can get each others states. As you understood - infinite space for bugs :).

It's OK to have send + immediate receive when you're 100% sure there will be no simultaneous dispatches. But it's not the case of write_to_hub() and get_from_hub() which can be executed asynchronously without waiting of the previous function to return the result.

What do I propose?

  1. Make a single while True: recvfrom() per XiaomiGateway at least after initialization. It will check for an error/invalid key or call push_data() on success which will update the device state.
  2. Don't call recvfrom() in _send_cmd() at least after initialization.
  3. Remove checking of write_to_hub() result in HA (e.g. https://github.com/home-assistant/home-assistant/blob/dev/homeassistant/components/light/xiaomi_aqara.py#L98). Hub will respond and single listener will call push_data.
  4. Add some tracker that will have a list of responses we are waiting. If we didn't get a response for any request in 10 seconds time frame - log an error. If we got a response, but was not waiting for it - log an error. You can use sid+cmd to identify the response (it's the best we can as there is no way to supply/receive request ids).

Related issue: https://community.home-assistant.io/t/xiaomi-gateway-errors-but-seems-to-be-working-fine/38633

Unsupported device Xiaomi Aqara cube

Hi @Danielhiversen ,

Im ussing HA v.0.69 in raspbian. I bought new device called xiaomi aqara cube .
When i start HA, i got error :

May 22 13:18:06 raspberrypi hass[2393]: 2018-05-22 13:18:06 ERROR (Thread-4) [xiaomi_gateway] Unsupported device found! Please create an issue at https://github.com/Danielhiversen/PyXiaomiGateway/issues and provide the following data: {'data': '{"voltage":2955}', 'short_id': 11544, 'model': 'sensor_cube.aqgl01', 'sid': '158d0002481496', 'cmd': 'read_ack'}
I hope you will be update code for support this device. I think my device is xiaomi cube version 2 :D

Looking forward to support aqara fingerprint door lock

After setup aqara fingerprint door lock and restart hass, I got the following msg at the console:

{'sid': '158d0001e17xxx', 'data': '{"voltage":3398}', 'model': '', 'cmd': 'read_ack', 'short_id': 183}

There is no model info.

Xiaomi Wall Scoket

Unsupported device found! Please create an issue at https://github.com/Danielhiversen/PyXiaomiGateway/issues and provide the following data: {'cmd': 'read_ack', 'sid': '158d0002251efb', 'model': 'ctrl_86plug.aq1', 'data': '{"voltage":3600,"status":"on","inuse":"1","power_consumed":"83","load_power":"34.84"}', 'short_id': 14419}

_20180304200406

Is this support at HA 0.65?

Gateway not responding to messages

I'm try to link up my Gateway with Home Assistant but it doesn't seem to be replying to the "whois" and "get_id_list" messages. Are there any common causes for this? I can see heartbeat and report messages coming in over the Multicast socket.

Wishlist feature: Only discovering the gateway if the sid is not provided

I checked there code.
https://github.com/octa22/org.openhab.binding.xiaomigateway/blob/master/src/main/java/org/openhab/binding/xiaomigateway/internal/XiaomiGatewayBinding.java#L964

They are only discovering the gateway if the sid or key is not provided.
It would be possible to add that to HA too. If someone is interested to do so, a pull request to
https://github.com/Danielhiversen/PyXiaomiGateway is welcome.

https://community.home-assistant.io/t/beta-xiaomi-gateway-integration/8213/2496

Aqara Wireless Switch (Double) have some trouble

when i press the wireless switch(long click press,single press or double press),the state in hass still keep "off". Why?

Thank you!

hass ver:0.60.0
xiaomi gateway ver:1.4.1_151.0143
Aqara Wireless Switch (Double):Model: lumi.sensor_86sw2.v1,did: lumi.158d0001639cf9

Stabilize the operation if multicast traffic isn't available or lossy

  1. Check if multicast messages was received in the past ("iam" discovery response / heartbeats) and log a warning.
  2. Recovery from "Invalid key" by retrieval of a new token (get_id_list)
  3. If every executed command needs a "token recovery" report a degraded performance because of the lack of multicast traffic.
  4. Implement an indicator if a command execution was successful (without invalid key response) to be sure a valid encryption key is used.

cp. https://community.home-assistant.io/t/pyxiaomigateway-problem-error-invalid-key/28168
https://community.home-assistant.io/t/xiaomi-gateway-integration-help-needed/28563/10
https://community.home-assistant.io/t/new-xiaomi-gateway-firmware-xiaomi-aqara-component/27637/30
https://community.home-assistant.io/t/xiaomi-gateway-not-discovered/25030/158
https://community.home-assistant.io/t/xiaomi-sensors-not-working-after-0-57-update-solved/31693/6
https://community.home-assistant.io/t/xiaomi-gateway-is-recognized-but-does-not-take-any-commands-or-brings-data-help-needed/28725

This is my explanation of the "invalid key" error:

Some responses (get_id_list (direct message), heartbeat (multicast)) of the gateway contains a "token" which is valid for a short period of time. The combination of the token plus the encryption key of the android app is used to calculate the "key" value of a "write" command:

{"cmd": "write", "sid": "34ce00909ed1", "data": {"rgb": 3036676095, "key": "5059aeccf37f66b5cfec0cdfaab76e29"}}

I don't know the behavior of the gateway exactly but if you miss one (or multiple) of the temporary tokens a old/invalid token is used and the misleading "Invalid key" error pops up although your encryption key (android key) is fine.

We will implement a safeguard for the "Invalid key" error so a new token will be requested and a retry of the failed command wil be sent. Do not forget: The cause of the issue is packet loss. :-(

cp. #21

Add Aqara Acpartner v3 (Advanced version) support

Related to this issue .
Accoring to Aqara's dev docs, acpartner.v3 officially support Gateway function. Here's debug log at HA when I try to add it:

2018-03-25 20:01:06 DEBUG (Thread-23) [xiaomi_gateway] MCAST (heartbeat) << {'model': 'acpartner.v3', 'sid': '7811dcb2a7d9', 'token': 'nZMYm8LUp0SwNAcc', 'params': [{'ip': '192.168.50.99'}], 'cmd': 'heartbeat'}
2018-03-25 20:01:06 ERROR (Thread-16) [xiaomi_gateway] No data in response from hub {'model': 'acpartner.v3', 'sid': '7811dcb2a7d9', 'token': 'nZMYm8LUp0SwNAcc', 'params': [{'ip': '192.168.50.99'}], 'cmd': 'heartbeat'}

namp test:

sudo nmap -sU -p 9898 192.168.50.99
Starting Nmap 7.40 ( https://nmap.org ) at 2018-03-25 16:53 CST
Nmap scan report for lumi-acpartner-v3_miio78478387 (192.168.50.99)
Host is up (0.020s latency).
PORT     STATE SERVICE
9898/udp open  monkeycom
MAC Address: 78:11:DC:B2:A7:D9 (Unknown)

nc test:

nc -v -uz 192.168.50.99 9898
found 0 associations
found 1 connections:
     1:	flags=82<CONNECTED,PREFERRED>
	outif (null)
	src 192.168.50.143 port 57240
	dst 192.168.50.99 port 9898
	rank info not available

Connection to 192.168.50.99 port 9898 [udp/monkeycom] succeeded!

Which means that Port 9898 is open at this device.

I use UDP/TCP tool to test JSON multicast and unicast like {"cmd":"discovery"} and {"cmd":"whois"} both got positive result. It reported itself and sub-devices like normal gateway.

Except illumination sensor and light(No hardware), it works like other gateway including ringtone.

I think it's time finally to expand this library to cover this device. According to docs, right now only v3 support this function. So previous v2 and v1 have to wait for Aqara to update firmware.

Unsupported device found!

2017-11-23 00:50:10 ERROR (SyncWorker_3) [PyXiaomiGateway] Unsupported device found! Please create an issue at https://github.com/Danielhiversen/PyXiaomiGateway/issues and provide the following data: {'cmd': 'read_ack', 'model': '', 'sid': '158d0001f24793', 'short_id': 14223, 'data': '{"voltage":3600}'}

The device is xiaomi switch(Aqara Wall Switch LN (Double) ,The newest version),I see information in gateway is (Model: lumi.ctrl_ln2.aq1), I found Model is change,last version is (Model: lumi.ctrl_ln2.v1),help me.pls...

Unsupported device found

Hi,
It logged out "Unsupported device found! Please create an issue at https://github.com/Danielhiversen/PyXiaomiGateway/issues and provide the following data: {'cmd': 'read_ack', 'model': 'sensor_switch.aq3', 'sid': '158d0001d47acd', 'short_id': 57945, 'data': '{"voltage":3015}'}".
with Home-Assistant 0.56.2. And I'm not sure which version of PyXiaoiGateway is included.

Unsupported device found of Xiaomi Cube

I've just bought Xiaomi Magic Cube and I had this error:

Unsupported device found! Please create an issue at https://github.com/Danielhiversen/PyXiaomiGateway/issues and provide the following data: {'cmd': 'read_ack', 'model': 'sensor_cube.aqgl01', 'sid': '158d0002310e95', 'short_id': 56893, 'data': '{"voltage":3600}'}

so I modified those two files to refer sensor_cube.aqgl01 in addition to cube and the device shows up properly.
(I'm on Hassio on docker, so there might be a little difference of the file path)

/usr/lib/python3.6/site-packages/xiaomi_gateway/__init__.py
/usr/lib/python3.6/site-packages/homeassistant/components/binary_sensor/xiaomi_aqara.py

R-wima Aqara lock support

Thank you for this project, it really gave me a head start trying to read the status of my smart lock. I bought a lock from AliExpress and it is being recognized as device in Mi Home. I do see the sid when I initialize the gateway.

The only problem is, is that the gateway returns an empty string as a for model and only a battery value (of 3600) as data.
voltage

Is this a firmware issue (i.e. do we have to wait for the Xiaomi API to support it) or did I do something wrong?

Unsupported device found!

[PyXiaomiGateway] Unsupported device found! Please create an issue at https://github.com/Danielhiversen/PyXiaomiGateway/issues and provide the following data: {'cmd': 'read_ack', 'model': '', 'sid': '158d0001f2ac76', 'short_id': 15011, 'data': '{"voltage":3600,"channel_0":"on"}'}

similar error here, but my device is lumi.ctrl_ln1.aq1.

i do change the init.py adding ctrl_ln1.aq1 and ctrl_ln2.aq1
and change the /components/xiaomi_aqara.py adding these two.
nothing happen.

maybe because the 'model‘ is blank? how to fix that? plz!

Install Failed

Command "/usr/bin/python3 -u -c "import setuptools, tokenize;__file__='/tmp/pip-build-tog0d3fl/pyCrypto/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record /tmp/pip-b94068hq-record/install-record.txt --single-version-externally-managed --compile" failed with error code 1 in /tmp/pip-build-tog0d3fl/pyCrypto/

Maybe switch to PyCryptodome?

Unsupported device found!

{'model': 'sensor_cube.aqgl01', 'short_id': 383, 'sid': '158d00024866f9', 'data': '{"voltage":2955}', 'cmd': 'read_ack'}

Unsupported device found!

{'cmd': 'read_ack', 'model': '', 'sid': '158d0001f4e65f', 'short_id': 9672, 'data': '{"voltage":3600}'}

Unsupported device found——Aqara Wireless Switch (Double)

{'model': 'sensor_86sw2', 'params': [{'battery_voltage': 3125}], 'sid': '158d0002338de6', 'cmd': 'read_rsp'}

Error message's above when HA's component said that Aqara Wireless Switch (Double) is in "xiaomi_aqara" 's Supported Device lists.

Aqara cube not recognized

I jus received an aqara cube i hoped to connect to home assistant, the log is however showing this:
2018-05-26 11:31:34 ERROR (SyncWorker_9) [xiaomi_gateway] Unsupported device found! Please create an issue at https://github.com/Danielhiversen/PyXiaomiGateway/issues and provide the following data: {'cmd': 'read_ack', 'model': 'sensor_cube.aqgl01', 'sid': '158d0002481631', 'short_id': 19614, 'data': '{"voltage":2965}'}

Support for water sensor

I can see my water sensor model lumi.sensor_wleak.aq1 in MiHome dev mode. Will home Assistant support it ?

Xiaomi Wall Switch not supported

Just bought 2 Xiaomi Wall Switch, one connected to the wall, one wireless. The wireless one is only detected as binary sensor, not sure how to enable it to switch. The wall connected one don't seem to have anything show up on hass.io. Got this error. I have some older wall connected switches that works just fine. any help?

Unsupported device found! Please create an issue at https://github.com/Danielhiversen/PyXiaomiGateway/issues and provide the following data: {'cmd': 'read_ack', 'model': 'ctrl_ln2.aq1', 'sid': '158d0001ef4230', 'short_id': 26646, 'data': '{"voltage":3600}'}

problem with new aqara wall plugin

ERROR (SyncWorker_10) [xiaomi_gateway] Unsupported device found!
{'cmd': 'read_ack', 'model': '', 'sid': '158d00020100d5', 'short_id': 4235, 'data': '{"voltage":3600}'}
QBCZ11LM made in 2017.11

Unsupported device found

{'cmd': 'read_ack', 'model': '', 'sid': '158d0001c2b51e', 'short_id': 30826, 'data': '{"voltage":3600,"channel_0":"
off"}'}

Aqara Wall Switch (LN) not discovered

{'model': 'ctrl_ln1.aq1', 'sid': '158d000233ccf3', 'cmd': 'read_ack', 'short_id': 2193, 'data': '{"voltage":3600,"channel_0":"on"}'}

Not discovered in Home Assistant

"Cannot connect to Gateway" should be followed by "Reconnected to Gateway"

I have setup a log watcher which checks for errors in logs and some trigger words and sends them to an email. Sometimes I see "Cannot connect to Gateway" error in HA logs which means we didn't receive response from socket in 10 seconds.
I want to ask you to add "Reconnected to Gateway" log message which will be printed once we see connection to Gateway is OK again, so I will add these words to log watcher and see two emails:

2017-11-27 12:55:00 Cannot connect to Gateway

2017-11-27 12:55:46 Reconnected to Gateway

Now I see only 1st and need to check manually if connection is OK again.

Unsupported device found!

Unsupported device found!
{'short_id': 47753, 'sid': '158d00010def23', 'cmd': 'read_ack', 'data': '{}', 'model': ''}
Xiaomi Cube

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.