Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Zigbee devices #69

Closed
darth-aragoth opened this issue Oct 7, 2020 · 31 comments
Closed

Zigbee devices #69

darth-aragoth opened this issue Oct 7, 2020 · 31 comments
Labels
enhancement New feature or request

Comments

@darth-aragoth
Copy link

Hi, could you please consider adding support for Zigbee devices connected via Tuya gateway, e.g. temperature / humidity sensors, thermostatic radiator valves etc.?

@postlund postlund added the enhancement New feature or request label Oct 11, 2020
@HansHM
Copy link

HansHM commented Oct 13, 2020

Yes please.

@postlund
Copy link
Collaborator

How is communication done with the gateway? Are there different kinds of gateways? I feel that I know nothing about this.

@darth-aragoth
Copy link
Author

darth-aragoth commented Oct 15, 2020

Zigbee gateway is connected via WiFi/LAN (depends on version) and configured in SmartLife as Gateway Control --> Gateway (Zigbee). After opening this device, there is possibility to pair compatible devices like temperature sensors, scene switches etc. After pairing, these devices are visible in LocalTuya main view, like other devices. In config file I noticed, that Zigbee devices have only key (no localKey):

{
"activeTime": xxx,
"devId": "some id",
"displayOrder": 0,
"dpMaxTime": xxx,
"dps": {
"101": 5430,
"102": 100,
"103": 2420
},
"errorCode": 0,
"iconUrl": "https://images.tuyaeu.com/smart/icon/ay1558597489826VMjh1/68c71c709c4baa72c5b4c6336063449a.png",
"isShare": false,
"key": "same as devId",
"lat": "50.0",
"lon": "18.0",
"meshId": "zigbee gateway's devId",
"moduleMap": {
"zigbee": {
"cadv": "",
"isOnline": true,
"verSw": "1.0.3"
}
},
"name": "Temperature",
"nodeId": "another id",
"productId": "another id",
"resptime": 0,
"runtimeEnv": "prod",
"timezoneId": "Europe/Warsaw",
"uuid": "same as devId",
"virtual": false
}

DPS - probably three values reported by temperature sensor (humidity 54.3%, battery level 100%, temperature 24.2°C) - that's my guess :)

EDIT: meshId is equal to gateway's devId.

@darth-aragoth
Copy link
Author

I just set up Moes thermostatic valves (https://www.moeshouse.com/collections/trv-radiator-valve/products/tuya-zigbee3-0-new-mini-wifi-radiator-actuator-smart-programmable-thermostat-temperature-trv-controller) with my Tuya account, they are connected via Zigbee gateway. I found that built-in tuya integration sees these devices, displays temperatures etc. I would be happy to be able to control them locally :-)

Currently I also use Zigbee temperature and humidity sensors and some switches, if any of the developers would like to try to add support for such devices, I can provide logs, testing, TCP tunnel to gateway etc.

@rospogrigio
Copy link
Owner

Dear @postlund , I am joining to those who would need support for the Zigbee gateway since I have just purchased one to control a smart door lock. The smart lock is a BT device, and the gateway allows to command it being a wifi-to-BT gateway.
Do you have any suggestion on how we could interact with it? What I have seen until now is:

  1. the config flow has the same behavior described in Connection to device succeeded but no datapoints found #271: Connection to device succeeded but no DPs found
  2. tuyadebug times out like this:
INFO:localtuya:localtuya version 1.0.0
INFO:localtuya:Python 3.7.3 (default, Jul 25 2020, 13:03:44)
[GCC 8.3.0] on linux
INFO:localtuya:Using pytuya version '8.1.0'
INFO:localtuya:Detecting list of available DPS of device bf7...wy7 [192.168.1.16], protocol 3.3.
DEBUG:localtuya.pytuya:Sending command status (device type: type_0a)
DEBUG:localtuya.pytuya:paylod=b'{"gwId":"bf7...wy7","devId":"bf7...wy7"}'
DEBUG:localtuya.pytuya:DATA RECEIVED!
DEBUG:localtuya.pytuya:decode payload=b'\xb9J\xc8\xcc\xfdj\xe9\xf7\xe5\x05ce\x10\xc6\x06\x8c\x8b\xed\xfd61U\x8c\xa3[\xf0\xe7\xa7>\xdeM-'
DEBUG:localtuya.pytuya:'data unvalid' error detected: switching to dev_type 'type_0d'
DEBUG:localtuya.pytuya:Re-send status due to device type change (type_0a -> type_0d)
DEBUG:localtuya.pytuya:Sending command status (device type: type_0d)
DEBUG:localtuya.pytuya:paylod=b'{"devId":"bf7...wy7","uid":"bf7...wy7","t":"1610116170","dps":{"1":null,"2":null,"3":null,"4":null,"5":null,"6":null,"7":null,"8":null,"9":null,"10":null}}'
DEBUG:localtuya.pytuya:DATA RECEIVED!
DEBUG:localtuya.pytuya:READING AGAIN!
DEBUG:localtuya.pytuya:Failed to connect to 192.168.1.16. Raising Exception.
WARNING:localtuya.pytuya:Failed to get status: timed out
  1. launching tuya-cli wizard, I see 2 devices: one for the smart lock and one for the gateway, showing different deviceIDs but the same localKey. However, launching tuyadebug with the smark lock devID gives the same result

  2. could this link be of any help? https://developer.tuya.com/en/docs/iot/device-development/embedded-software-development/mcu-development-access/zigbee-general-solution/tuya-zigbee-module-uart-communication-protocol?id=K9ear5khsqoty

Do you have any suggestion on what we can try in order to get some communication?
Thank you!

@rospogrigio
Copy link
Owner

Also, can this be of any help? Maybe there is another command to be sent to the gateway in order get the status (I tried 250 and others with no luck):
https://github.com/TradeFace/tuyaface/blob/development/tuyaface/const.py

@postlund
Copy link
Collaborator

postlund commented Jan 8, 2021

@rospogrigio I don't have much to give you here, but as I understand it the hub is likely transparent and you need to include id to both gateway and device when sending requests. Have a look here:

codetheweb/tuyapi#366

@rospogrigio
Copy link
Owner

Yeah, I was thinking of something similar, I tried some things but it doesn't work. Unfortunately, even the tuya official integration is not able to make them work (doesn't even detect them...).
Well, if you happen to have any other idea, I'm all ears, thank you! 😉

@darth-aragoth
Copy link
Author

Actually Tuya official integration supports some of Zigbee devices. I can control switches and thermostatic valves (there is an error when I try to change temperature, but integration shows temperature and some settings). I also use temp/pressure sensors, but they are not visible in integration.

@rospogrigio
Copy link
Owner

Mmm, very interesting, will try again then... is there any way you can find some details about the communication? Like protocol version, and the payload that they exchange?

@darth-aragoth
Copy link
Author

I can extract values from SmartLive app, I don't know how to intercept any exchanged data.

@rospogrigio
Copy link
Owner

@darth-aragoth I retried and Tuya integration does not show both the gateway and the zigbee devices. I am starting to believe that this is related to the gateway or the device being a "0d" device, maybe yours are "0a". Is there any way you can figure it out? Are you able to communicate with the devices using tuya-cli ?

@darth-aragoth
Copy link
Author

Tuya integration doesn't show Zigbee gateway direct (SmartLife does and allows to pair new devices), but I can see some devices connected to this gateway. I can control Zigbee switches from SmartLife and from HomeAssistant via official integration, exactly the same way that I control WiFi switches. I don't know, how to figure out, if my device is '0d' or '0a' (actually I don't know what it is), I can try to figure it out, if you tell me how to do it ;)

@rospogrigio
Copy link
Owner

What if you install tuya-cli and launch:
tuya-cli get --ip [gateway IP] --id [DEVICE id] --key [DEVICE key] --protocol-version 3.3 -a
??

@darth-aragoth
Copy link
Author

Do you know how to install it on Rasbberry Pi? npm seems to be unavailable on hassio.

@rospogrigio
Copy link
Owner

are you on Raspbian? Just apt-get install npm ...

@darth-aragoth
Copy link
Author

darth-aragoth commented Jan 13, 2021

OK I installed CLI (apk get npm to get npm). I'm not sure, which ID's and keys should I use. In SmartLife config I extracted DevID and localkey of gateway. Zigbee device doesn't seem to have localkey, I see only DevID and meshID, that is equal to gateway's devid. I tried various combinations with ID's, key, protocol version etc. but I always get some error.

~ $ tuya-cli get --ip x.x.x.x --id gateway/devicekey --key localkey --protocol-version 3.3 -a
devid not found
~ $ tuya-cli get --ip x.x.x.x --id gateway/devicekey --key localkey --protocol-version 3.1 -a
parse data error
~ $ tuya-cli get --ip x.x.x.x --id gateway/devicekey --key localkey --protocol-version 3.3 (the same with 3.1, but without -a switch)
TypeError: Cannot read property '1' of undefined
    at Object.get (/usr/lib/node_modules/@tuyapi/cli/lib/control.js:56:30)
    at processTicksAndRejections (internal/process/task_queues.js:97:5)

Maybe I'm doing something wrong, it doesn't work even when I try to communicate with wifi device:

events.js:291
      throw er; // Unhandled 'error' event
      ^

Error: Error from socket
    at Socket.<anonymous> (/usr/lib/node_modules/@tuyapi/cli/node_modules/tuyapi/index.js:388:30)
    at Socket.emit (events.js:314:20)
    at emitErrorNT (internal/streams/destroy.js:92:8)
    at emitErrorAndCloseNT (internal/streams/destroy.js:60:3)
    at processTicksAndRejections (internal/process/task_queues.js:84:21)
Emitted 'error' event on TuyaDevice instance at:
    at Socket.<anonymous> (/usr/lib/node_modules/@tuyapi/cli/node_modules/tuyapi/index.js:388:16)
    at Socket.emit (events.js:314:20)
    [... lines matching original stack trace ...]
    at processTicksAndRejections (internal/process/task_queues.js:84:21)

@rospogrigio
Copy link
Owner

Do you have any other non-zigbee-connected devices you can test?

@darth-aragoth
Copy link
Author

Yes, I tried with WiFi switch (working in LocalTuya, official integration and SmartLife). I pasted error in previous post (events.js:291...). I checked now WiFi light and got the same error.

@postlund
Copy link
Collaborator

@darth-aragoth It's because your version of node is too old. Try to follow according to nvm: https://medium.com/stackfame/how-to-update-node-js-to-latest-version-linux-ubuntu-osx-windows-others-105749e90040

@rospogrigio
Copy link
Owner

I'm shocked, tuya-cli still doesn't support "0d" devices. Unbelievable...

@darth-aragoth
Copy link
Author

OK thank you, I'm trying to update to v14.15.4, but I got some errors. I rebooted HA and had to install all once again, I don't know why, but all commands: npm, tuya-cli... were not found:

~ $ tuya-cli
-bash: tuya-cli: command not found
~ $ npm i @tuyapi/cli -g
-bash: npm: command not found
~ $ apk add npm
fetch http://dl-cdn.alpinelinux.org/alpine/v3.12/main/armv7/APKINDEX.tar.gz
fetch http://dl-cdn.alpinelinux.org/alpine/v3.12/community/armv7/APKINDEX.tar.gz
(1/3) Installing brotli-libs (1.0.9-r1)
(2/3) Installing nodejs (12.20.1-r0)
(3/3) Installing npm (12.20.1-r0)
Executing busybox-1.31.1-r19.trigger
OK: 138 MiB in 98 packages
~ $ n
-bash: n: command not found
~ $ npm -v
6.14.10
~ $ npm install npm@latest -g
/usr/bin/npm -> /usr/lib/node_modules/npm/bin/npm-cli.js
/usr/bin/npx -> /usr/lib/node_modules/npm/bin/npx-cli.js
+ npm@6.14.11
updated 2 packages in 26.786s
~ $ n
-bash: n: command not found
~ $ npm install -g n
/usr/bin/n -> /usr/lib/node_modules/n/bin/n
+ n@7.0.0
added 1 package from 4 contributors in 0.999s

Now, when I try to install latest node, I get some error that prevents installing:

~ $ n stable
/usr/bin/n: line 646: /usr/local/bin/node: No such file or directory
   installed :  (with npm 6.14.10)

I checked and binary file seems to be in right place:

~ $ ls -l /usr/local/bin/node
-rwxr-xr-x    1 root     root      67198024 Jan 13 16:28 /usr/local/bin/node

but for some reason I cannot execute it:

~ $ /usr/local/bin/node
-bash: /usr/local/bin/node: No such file or directory

@rospogrigio
Copy link
Owner

@darth-aragoth , I don't know...is the file binary or text? Watch it with less and try to understand...
@postlund , do you think this could be useful? https://github.com/Koenkk/zigbee2mqtt

@postlund
Copy link
Collaborator

@darth-aragoth Docker containers are not persistent so you lose everything you do in them when they are destroyed. It would be better if you tried to install tuya-close on another computer (it doesn't have to be the same as you run HA on).

@rospogrigio No idea, how does it interact with a controller? Because I guess that's what is interesting in our case.

@darth-aragoth
Copy link
Author

@darth-aragoth , I don't know...is the file binary or text? Watch it with less and try to understand...
@postlund , do you think this could be useful? https://github.com/Koenkk/zigbee2mqtt

It's binary file. I found out that node is also in /usr/bin/node. I can execute it, but when I symlinked this binary to /usr/local/bin/, I can't execute the symlink.

@rospogrigio
Copy link
Owner

OK @postlund , I got it. After a lot of banging my head, reading posts, asking to people and making attempts, I managed to make it work. A PR is coming... 😉

@postlund
Copy link
Collaborator

@rospogrigio 🤓👍

@rospogrigio
Copy link
Owner

Here it is: #318 !

@darth-aragoth
Copy link
Author

Hello, are there any news in adding support for Zigbee devices?

@leeyuentuen
Copy link

Hello, are there any news in adding support for Zigbee devices?

there is here an pull request with some zigbee changes. I've also test them out on my fork and it works
#739

my fork: https://github.com/leeyuentuen/localtuya

@rospogrigio
Copy link
Owner

Sorry, I didn't notice the fork. I have introduced Zigbee support in PR #1493, if anybody wants to test it and provide feedback, please comment in the PR.

PaulCavill pushed a commit to PaulCavill/localtuya that referenced this issue May 9, 2024
MkDocs based documentation
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

5 participants