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

Matter ZigBee Hub #592

Open
SergioLuxx opened this issue Feb 6, 2025 · 10 comments
Open

Matter ZigBee Hub #592

SergioLuxx opened this issue Feb 6, 2025 · 10 comments
Labels
tuya_device Support for specific Tuya Devices

Comments

@SergioLuxx
Copy link

SergioLuxx commented Feb 6, 2025

I decided to update my gateway and bought a new version. The old one is a wireless gateway also from Moes and it works well with tinytuya. But the new one refuses.

    {
        "name": "Matter ZigBee Hub",
        "id": "###",                     I deleted all the keys
        "key": "###,
        "mac": "###",
        "uuid": "###",
        "sn": "###",
        "category": "wg2",
        "product_name": "Matter ZigBee Hub",
        "product_id": "vxs0ltrakomksi3h",
        "biz_type": 0,
        "model": "MZHUB",
        "sub": false,
        "icon": "https://images.tuyaeu.com/smart/icon/ay15327721968035jwx9/1b192ad585c6b41f6ca6986499f8fa95.png",
        "mapping": {
            "4": {
                "code": "switch_alarm_sound",
                "type": "Boolean",
                "values": {}
            },
            "32": {
                "code": "master_state",
                "type": "Enum",
                "values": {
                    "range": [
                        "normal",
                        "alarm"
                    ]
                }
            },
            "34": {
                "code": "factory_reset",
                "type": "Boolean",
                "values": {}
            },
            "45": {
                "code": "alarm_active",
                "type": "String",
                "values": "{\"maxlen\":255}"
            }
        },
        "ip": "",
        "version": ""         version not detected?
    },

https://moeshouse.com/products/tuya-zigbee-matter-thread-gateway-smart-home-bridge-matter-hub
when trying to connect with any version returns an error
tinytuya.Device(dev_id=Gateway_s[0][1], address=Gateway_s[0][3], local_key=Gateway_s[0][4], version=3.3, connection_timeout=3)

{
    'Error': 'Unexpected Payload from `Device',`
    'Err': '904',
    'Payload': None
}

Is this device not supported or am I doing something wrong?

@uzlonewolf
Copy link
Collaborator

Are you sure it's a v3.3 device? Newer ones tend to be 3.4 or 3.5. Is it picked up by the scanner (python -m tinytuya scan)?

@uzlonewolf uzlonewolf added the tuya_device Support for specific Tuya Devices label Feb 7, 2025
@SergioLuxx
Copy link
Author

Are you sure it's a v3.3 device? Newer ones tend to be 3.4 or 3.5. Is it picked up by the scanner (python -m tinytuya scan)?
I tried all versions.
And here are the results of the scanner

I tried all versions, everywhere error 904

Unknown v?? Device   Product ID = ?  [Failed to Force-Scan]:
    Address = 192.168.10.200   Device ID =  (len:0)  Local Key =   Version = ??  Type = default, MAC =

python -m tinytuya wizard
the old hub works correctly

}
        "name": "Gateway",
        "id": "bf3848e3ded856aa7frdlq",
        "key": "23y@{p<x[9(jE5vj",
        "mac": "70:89:76:84:05:e5",
        "uuid": "765d2039408f009a",
        "sn": "10002274500E92",
        "category": "wg2",
        "product_name": "Gateway",
        "product_id": "ysgynkrk",
        "biz_type": 0,
        "model": "ZHUB-W",
        "sub": false,
        "icon": "https://images.tuyaeu.com/smart/icon/ay15327721968035jwx9/f3ee42e90b543f1c0a50279f8f450cad.png",
        "mapping": {},
        "ip": "",
        "version": ""
    },

The new one refuses

    {
        "name": "Matter ZigBee Hub",
        "id": "bf3a80ccfb821ae74790eg",
        "key": "/|USg{KR_PdPIR<Y",
        "mac": "38:a5:c9:6c:33:8b",
        "uuid": "20918e833c15802b",
        "sn": "10016878500DDD",
        "category": "wg2",
        "product_name": "Matter ZigBee Hub",
        "product_id": "vxs0ltrakomksi3h",
        "biz_type": 0,
        "model": "MZHUB",
        "sub": false,
        "icon": "https://images.tuyaeu.com/smart/icon/ay15327721968035jwx9/1b192ad585c6b41f6ca6986499f8fa95.png",
        "mapping": {
            "4": {
                "code": "switch_alarm_sound",
                "type": "Boolean",
                "values": {}
            },
            "32": {
                "code": "master_state",
                "type": "Enum",
                "values": {
                    "range": [
                        "normal",
                        "alarm"
                    ]
                }
            },
            "34": {
                "code": "factory_reset",
                "type": "Boolean",
                "values": {}
            },
            "45": {
                "code": "alarm_active",
                "type": "String",
                "values": "{\"maxlen\":255}"
            }
        },
        "ip": "",
        "version": ""
    }

@make-all
Copy link

Maybe it is Matter only for the local protocol?

@SergioLuxx
Copy link
Author

SergioLuxx commented Feb 12, 2025

Maybe it is Matter only for the local protocol?

I would be happy to be able to control at least Zigbee devices from my new hub. Its technical characteristics are better than the old one, it is newer.
But I do not understand why when trying to run tinytuya.Device() with the keys of this hub and substituting any version, I always get the error 'Error': 'Unexpected Payload from Device'` and nothing else.
I think this is due to the lack of support for this device in this library. Since it cannot decrypt or initially send correct data to the device, when communicating with it.

@jasonacox
Copy link
Owner

@SergioLuxx I see your code clip but suggest trying something like: https://github.com/jasonacox/tinytuya/blob/master/examples/zigbee_gateway.py

In any case, it would be good to see debug:

import tinytuya

tinytuya.set_debug(True)

# configure the parent device
#   address=None will cause it to search the network for the device
gw = tinytuya.Device( 'eb...4', 
    address=None,
    local_key='aabbccddeeffgghh', 
    persist=True, 
    version=3.3 )

print( 'GW IP found:', gw.address )

# configure one or more children.  Every dev_id must be unique!
#   cid is the "node_id" from devices.json
#   node_id can be used as an alias for cid
zigbee1 = tinytuya.OutletDevice( 'eb14...w', cid='0011223344556601', parent=gw )

print(zigbee1.status())

@SergioLuxx
Copy link
Author

@jasonacox

Here are the results of running this code for different versions

v3.3

DEBUG:TinyTuya [1.15.1]

DEBUG:Python 3.13.1 (tags/v3.13.1:0671451, Dec  3 
2024, 19:06:28) [MSC v.1942 64 bit (AMD64)] on win32
DEBUG:Using pyca/cryptography 44.0.0 for crypto, GCM is supported
DEBUG:Listening for Tuya devices on UDP ports 6666, 6667 and 7000
DEBUG:Sending discovery broadcast from '192.168.1.101' to '255.255.255.255' on port 7000
DEBUG:Received valid UDP packet: {'from': 'app', 'ip': '192.168.1.101'}
DEBUG:Received valid UDP packet: {'from': 'app', 'ip': '192.168.1.101'}
DEBUG:Received valid UDP packet: {'ip': '192.168.10.200', 'gwId': 'bfdf25a2ec8c5c5912ikqp', 'uuid': 
'20918e833c15802b', 'active': 2, 'ablilty': 0, 'encrypt': True, 'productKey': 'keyc8cur5mh8kcqj', 'version': '3.5', 'pro_ability': 1, 'lan_cap': 5030, 'lan_seq': 21, 'lan_ablilty': 1, 'token': True, 'wf_cfg': True, 'clientLink': 32}
DEBUG:Scan complete with 1 devices found
DEBUG:find() is returning: {'ip': '192.168.10.200', 'version': '3.5', 'id': 'bfdf25a2ec8c5c5912ikqp', 'product_id': 'keyc8cur5mh8kcqj', 'data': {'ip': '192.168.10.200', 'gwId': 'bfdf25a2ec8c5c5912ikqp', 'uuid': '20918e833c15802b', 'active': 2, 'encrypt': True, 'productKey': 'keyc8cur5mh8kcqj', 'version': '3.5', 'pro_ability': 1, 'lan_cap': 5030, 'lan_seq': 21, 'lan_ablilty': 1, 'token': True, 'wf_cfg': True, 'clientLink': 32, 'name': '', 'key': '', 'mac': '', 'id': 'bfdf25a2ec8c5c5912ikqp', 'ability': 0, 'dev_type': 'default', 'origin': 'broadcast'}}
GW IP found: 192.168.10.200
DEBUG:status() entry (dev_type is default)        
DEBUG:final payload_dict for 'bf9518a17c8c5f03dexdy9' ('v3.5'/'default'): {1: {'command': {'gwId': '', 'devId': '', 'uid': '', 't': ''}}, 7: {'command': {'protocol': 5, 't': 'int', 'data': {'cid': ''}}, 'command_override': 13}, 8: {'command': {'gwId': '', 'devId': ''}}, 9: {'command': {'gwId': '', 'devId': ''}}, 10: {'command': {}, 'command_override': 16}, 13: {'command': {'protocol': 5, 't': 'int', 'data': {'cid': ''}}}, 16: {'command': {}}, 18: {'command': {'dpId': [18, 19, 20]}}, 64: {'command': {'reqType': '', 'data': {}}}}
DEBUG:building command 10 payload=b'{"cid":"a4c138b58b9f50d3"}'
DEBUG:socket unable to connect (timeout) - retry 1/5
DEBUG:Listening for Tuya devices on UDP ports 6666, 6667 and 7000
DEBUG:Sending discovery broadcast from '192.168.1.101' to '255.255.255.255' on port 7000
DEBUG:Received valid UDP packet: {'from': 'app', 'ip': '192.168.1.101'}
DEBUG:Received valid UDP packet: {'from': 'app', 'ip': '192.168.1.101'}
DEBUG:Received valid UDP packet: {'ip': '192.168.10.200', 'gwId': 'bfdf25a2ec8c5c5912ikqp', 'uuid': 
'20918e833c15802b', 'active': 2, 'ablilty': 0, 'encrypt': True, 'productKey': 'keyc8cur5mh8kcqj', 'version': '3.5', 'pro_ability': 1, 'lan_cap': 5030, 'lan_seq': 21, 'lan_ablilty': 1, 'token': True, 'wf_cfg': True, 'clientLink': 32}
DEBUG:Scan complete with 1 devices found
DEBUG:find() is returning: {'ip': '192.168.10.200', 'version': '3.5', 'id': 'bfdf25a2ec8c5c5912ikqp', 'product_id': 'keyc8cur5mh8kcqj', 'data': {'ip': '192.168.10.200', 'gwId': 'bfdf25a2ec8c5c5912ikqp', 'uuid': '20918e833c15802b', 'active': 2, 'encrypt': True, 'productKey': 'keyc8cur5mh8kcqj', 'version': '3.5', 'pro_ability': 1, 'lan_cap': 5030, 'lan_seq': 21, 'lan_ablilty': 1, 'token': True, 'wf_cfg': True, 'clientLink': 32, 'name': '', 'key': '', 'mac': '', 'id': 'bfdf25a2ec8c5c5912ikqp', 'ability': 0, 'dev_type': 'default', 'origin': 'broadcast'}}

v3.4

DEBUG:TinyTuya [1.15.1]

DEBUG:Python 3.13.1 (tags/v3.13.1:0671451, Dec  3 
2024, 19:06:28) [MSC v.1942 64 bit (AMD64)] on win32
DEBUG:Using pyca/cryptography 44.0.0 for crypto, GCM is supported
DEBUG:Listening for Tuya devices on UDP ports 6666, 6667 and 7000
DEBUG:Sending discovery broadcast from '192.168.1.101' to '255.255.255.255' on port 7000
DEBUG:Received valid UDP packet: {'from': 'app', 'ip': '192.168.1.101'}
DEBUG:Received valid UDP packet: {'from': 'app', 'ip': '192.168.1.101'}
DEBUG:Received valid UDP packet: {'ip': '192.168.10.200', 'gwId': 'bfdf25a2ec8c5c5912ikqp', 'uuid': 
'20918e833c15802b', 'active': 2, 'ablilty': 0, 'encrypt': True, 'productKey': 'keyc8cur5mh8kcqj', 'version': '3.5', 'pro_ability': 1, 'lan_cap': 5030, 'lan_seq': 21, 'lan_ablilty': 1, 'token': True, 'wf_cfg': True, 'clientLink': 32}
DEBUG:Scan complete with 1 devices found
DEBUG:find() is returning: {'ip': '192.168.10.200', 'version': '3.5', 'id': 'bfdf25a2ec8c5c5912ikqp', 'product_id': 'keyc8cur5mh8kcqj', 'data': {'ip': '192.168.10.200', 'gwId': 'bfdf25a2ec8c5c5912ikqp', 'uuid': '20918e833c15802b', 'active': 2, 'encrypt': True, 'productKey': 'keyc8cur5mh8kcqj', 'version': '3.5', 'pro_ability': 1, 'lan_cap': 5030, 'lan_seq': 21, 'lan_ablilty': 1, 'token': True, 'wf_cfg': True, 'clientLink': 32, 'name': '', 'key': '', 'mac': '', 'id': 'bfdf25a2ec8c5c5912ikqp', 'ability': 0, 'dev_type': 'default', 'origin': 'broadcast'}}
GW IP found: 192.168.10.200
DEBUG:status() entry (dev_type is default)        
DEBUG:final payload_dict for 'bf9518a17c8c5f03dexdy9' ('v3.5'/'default'): {1: {'command': {'gwId': '', 'devId': '', 'uid': '', 't': ''}}, 7: {'command': {'protocol': 5, 't': 'int', 'data': {'cid': ''}}, 'command_override': 13}, 8: {'command': {'gwId': '', 'devId': ''}}, 9: {'command': {'gwId': '', 'devId': ''}}, 10: {'command': {}, 'command_override': 16}, 13: {'command': {'protocol': 5, 't': 'int', 'data': {'cid': ''}}}, 16: {'command': {}}, 18: {'command': {'dpId': [18, 19, 20]}}, 64: {'command': {'reqType': '', 'data': {}}}}
DEBUG:building command 10 payload=b'{"cid":"a4c138b58b9f50d3"}'
DEBUG:socket unable to connect (timeout) - retry 1/5
DEBUG:Listening for Tuya devices on UDP ports 6666, 6667 and 7000
DEBUG:Sending discovery broadcast from '192.168.1.101' to '255.255.255.255' on port 7000
DEBUG:Received valid UDP packet: {'from': 'app', 'ip': '192.168.1.101'}
DEBUG:Received valid UDP packet: {'from': 'app', 'ip': '192.168.1.101'}
DEBUG:Received valid UDP packet: {'ip': '192.168.10.200', 'gwId': 'bfdf25a2ec8c5c5912ikqp', 'uuid': 
'20918e833c15802b', 'active': 2, 'ablilty': 0, 'encrypt': True, 'productKey': 'keyc8cur5mh8kcqj', 'version': '3.5', 'pro_ability': 1, 'lan_cap': 5030, 'lan_seq': 21, 'lan_ablilty': 1, 'token': True, 'wf_cfg': True, 'clientLink': 32}
DEBUG:Scan complete with 1 devices found
DEBUG:find() is returning: {'ip': '192.168.10.200', 'version': '3.5', 'id': 'bfdf25a2ec8c5c5912ikqp', 'product_id': 'keyc8cur5mh8kcqj', 'data': {'ip': '192.168.10.200', 'gwId': 'bfdf25a2ec8c5c5912ikqp', 'uuid': '20918e833c15802b', 'active': 2, 'encrypt': True, 'productKey': 'keyc8cur5mh8kcqj', 'version': '3.5', 'pro_ability': 1, 'lan_cap': 5030, 'lan_seq': 21, 'lan_ablilty': 1, 'token': True, 'wf_cfg': True, 'clientLink': 32, 'name': '', 'key': '', 'mac': '', 'id': 'bfdf25a2ec8c5c5912ikqp', 'ability': 0, 'dev_type': 'default', 'origin': 'broadcast'}}

v3.5

DEBUG:TinyTuya [1.15.1]

DEBUG:Python 3.13.1 (tags/v3.13.1:0671451, Dec  3 
2024, 19:06:28) [MSC v.1942 64 bit (AMD64)] on win32
DEBUG:Using pyca/cryptography 44.0.0 for crypto, GCM is supported
DEBUG:Listening for Tuya devices on UDP ports 6666, 6667 and 7000
DEBUG:Sending discovery broadcast from '192.168.1.101' to '255.255.255.255' on port 7000
DEBUG:Received valid UDP packet: {'from': 'app', 'ip': '192.168.1.101'}
DEBUG:Received valid UDP packet: {'from': 'app', 'ip': '192.168.1.101'}
DEBUG:Received valid UDP packet: {'ip': '192.168.10.200', 'gwId': 'bfdf25a2ec8c5c5912ikqp', 'uuid': 
'20918e833c15802b', 'active': 2, 'ablilty': 0, 'encrypt': True, 'productKey': 'keyc8cur5mh8kcqj', 'version': '3.5', 'pro_ability': 1, 'lan_cap': 5030, 'lan_seq': 21, 'lan_ablilty': 1, 'token': True, 'wf_cfg': True, 'clientLink': 32}
DEBUG:Scan complete with 1 devices found
DEBUG:find() is returning: {'ip': '192.168.10.200', 'version': '3.5', 'id': 'bfdf25a2ec8c5c5912ikqp', 'product_id': 'keyc8cur5mh8kcqj', 'data': {'ip': '192.168.10.200', 'gwId': 'bfdf25a2ec8c5c5912ikqp', 'uuid': '20918e833c15802b', 'active': 2, 'encrypt': True, 'productKey': 'keyc8cur5mh8kcqj', 'version': '3.5', 'pro_ability': 1, 'lan_cap': 5030, 'lan_seq': 21, 'lan_ablilty': 1, 'token': True, 'wf_cfg': True, 'clientLink': 32, 'name': '', 'key': '', 'mac': '', 'id': 'bfdf25a2ec8c5c5912ikqp', 'ability': 0, 'dev_type': 'default', 'origin': 'broadcast'}}
GW IP found: 192.168.10.200
DEBUG:status() entry (dev_type is default)        
DEBUG:final payload_dict for 'bf9518a17c8c5f03dexdy9' ('v3.5'/'default'): {1: {'command': {'gwId': '', 'devId': '', 'uid': '', 't': ''}}, 7: {'command': {'protocol': 5, 't': 'int', 'data': {'cid': ''}}, 'command_override': 13}, 8: {'command': {'gwId': '', 'devId': ''}}, 9: {'command': {'gwId': '', 'devId': ''}}, 10: {'command': {}, 'command_override': 16}, 13: {'command': {'protocol': 5, 't': 'int', 'data': {'cid': ''}}}, 16: {'command': {}}, 18: {'command': {'dpId': [18, 19, 20]}}, 64: {'command': {'reqType': '', 'data': {}}}}
DEBUG:building command 10 payload=b'{"cid":"a4c138b58b9f50d3"}'
DEBUG:socket unable to connect (timeout) - retry 1/5
DEBUG:Listening for Tuya devices on UDP ports 6666, 6667 and 7000
DEBUG:Sending discovery broadcast from '192.168.1.101' to '255.255.255.255' on port 7000
DEBUG:Received valid UDP packet: {'from': 'app', 'ip': '192.168.1.101'}
DEBUG:Received valid UDP packet: {'from': 'app', 'ip': '192.168.1.101'}
DEBUG:Received valid UDP packet: {'ip': '192.168.10.200', 'gwId': 'bfdf25a2ec8c5c5912ikqp', 'uuid': 
'20918e833c15802b', 'active': 2, 'ablilty': 0, 'encrypt': True, 'productKey': 'keyc8cur5mh8kcqj', 'version': '3.5', 'pro_ability': 1, 'lan_cap': 5030, 'lan_seq': 21, 'lan_ablilty': 1, 'token': True, 'wf_cfg': True, 'clientLink': 32}
DEBUG:Scan complete with 1 devices found
DEBUG:find() is returning: {'ip': '192.168.10.200', 'version': '3.5', 'id': 'bfdf25a2ec8c5c5912ikqp', 'product_id': 'keyc8cur5mh8kcqj', 'data': {'ip': '192.168.10.200', 'gwId': 'bfdf25a2ec8c5c5912ikqp', 'uuid': '20918e833c15802b', 'active': 2, 'encrypt': True, 'productKey': 'keyc8cur5mh8kcqj', 'version': '3.5', 'pro_ability': 1, 'lan_cap': 5030, 'lan_seq': 21, 'lan_ablilty': 1, 'token': True, 'wf_cfg': True, 'clientLink': 32, 'name': '', 'key': '', 'mac': '', 'id': 'bfdf25a2ec8c5c5912ikqp', 'ability': 0, 'dev_type': 'default', 'origin': 'broadcast'}}

You can't even do print(gw.status())

DEBUG:TinyTuya [1.15.1]

DEBUG:Python 3.13.1 (tags/v3.13.1:0671451, Dec  3 
2024, 19:06:28) [MSC v.1942 64 bit (AMD64)] on win32
DEBUG:Using pyca/cryptography 44.0.0 for crypto, GCM is supported
DEBUG:Listening for Tuya devices on UDP ports 6666, 6667 and 7000
DEBUG:Sending discovery broadcast from '192.168.1.101' to '255.255.255.255' on port 7000
DEBUG:Received valid UDP packet: {'from': 'app', 'ip': '192.168.1.101'}
DEBUG:Received valid UDP packet: {'from': 'app', 'ip': '192.168.1.101'}
DEBUG:Received valid UDP packet: {'ip': '192.168.10.200', 'gwId': 'bfdf25a2ec8c5c5912ikqp', 'uuid': 
'20918e833c15802b', 'active': 2, 'ablilty': 0, 'encrypt': True, 'productKey': 'keyc8cur5mh8kcqj', 'version': '3.5', 'pro_ability': 1, 'lan_cap': 5030, 'lan_seq': 21, 'lan_ablilty': 1, 'token': True, 'wf_cfg': True, 'clientLink': 32}
DEBUG:Scan complete with 1 devices found
DEBUG:find() is returning: {'ip': '192.168.10.200', 'version': '3.5', 'id': 'bfdf25a2ec8c5c5912ikqp', 'product_id': 'keyc8cur5mh8kcqj', 'data': {'ip': '192.168.10.200', 'gwId': 'bfdf25a2ec8c5c5912ikqp', 'uuid': '20918e833c15802b', 'active': 2, 'encrypt': True, 'productKey': 'keyc8cur5mh8kcqj', 'version': '3.5', 'pro_ability': 1, 'lan_cap': 5030, 'lan_seq': 21, 'lan_ablilty': 1, 'token': True, 'wf_cfg': True, 'clientLink': 32, 'name': '', 'key': '', 'mac': '', 'id': 'bfdf25a2ec8c5c5912ikqp', 'ability': 0, 'dev_type': 'default', 'origin': 'broadcast'}}
GW IP found: 192.168.10.200
DEBUG:status() entry (dev_type is default)        
DEBUG:final payload_dict for 'bfdf25a2ec8c5c5912ikqp' ('v3.5'/'default'): {1: {'command': {'gwId': '', 'devId': '', 'uid': '', 't': ''}}, 7: {'command': {'protocol': 5, 't': 'int', 'data': {}}, 'command_override': 13}, 8: {'command': {'gwId': '', 'devId': ''}}, 9: {'command': {'gwId': '', 'devId': ''}}, 10: {'command': {}, 'command_override': 16}, 
13: {'command': {'protocol': 5, 't': 'int', 'data': {}}}, 16: {'command': {}}, 18: {'command': {'dpId': [18, 19, 20]}}, 64: {'command': {'reqType': '', 'data': {}}}}
DEBUG:building command 10 payload=b'{}'
DEBUG:socket unable to connect (timeout) - retry 1/5
DEBUG:Listening for Tuya devices on UDP ports 6666, 6667 and 7000
DEBUG:Sending discovery broadcast from '192.168.1.101' to '255.255.255.255' on port 7000
DEBUG:Received valid UDP packet: {'from': 'app', 'ip': '192.168.1.101'}
DEBUG:Received valid UDP packet: {'from': 'app', 'ip': '192.168.1.101'}
DEBUG:Received valid UDP packet: {'ip': '192.168.10.200', 'gwId': 'bfdf25a2ec8c5c5912ikqp', 'uuid': 
'20918e833c15802b', 'active': 2, 'ablilty': 0, 'encrypt': True, 'productKey': 'keyc8cur5mh8kcqj', 'version': '3.5', 'pro_ability': 1, 'lan_cap': 5030, 'lan_seq': 21, 'lan_ablilty': 1, 'token': True, 'wf_cfg': True, 'clientLink': 32}
DEBUG:Scan complete with 1 devices found
DEBUG:find() is returning: {'ip': '192.168.10.200', 'version': '3.5', 'id': 'bfdf25a2ec8c5c5912ikqp', 'product_id': 'keyc8cur5mh8kcqj', 'data': {'ip': '192.168.10.200', 'gwId': 'bfdf25a2ec8c5c5912ikqp', 'uuid': '20918e833c15802b', 'active': 2, 'encrypt': True, 'productKey': 'keyc8cur5mh8kcqj', 'version': '3.5', 'pro_ability': 1, 'lan_cap': 5030, 'lan_seq': 21, 'lan_ablilty': 1, 'token': True, 'wf_cfg': True, 'clientLink': 32, 'name': '', 'key': '', 'mac': '', 'id': 'bfdf25a2ec8c5c5912ikqp', 'ability': 0, 'dev_type': 'default', 'origin': 'broadcast'}}

@SergioLuxx
Copy link
Author

@jasonacox
So, I have achieved success.
After repeatedly reconnecting the gateway to the router, as well as forcibly specifying its IP address, I began to receive a response from the Zigbee device connected to it!

import tinytuya

tinytuya.set_debug(True)

gw = tinytuya.Device('bfdf25a2ec8c5c5912ikqp',
    address="192.168.10.200",
    local_key="=vwHbH'2'L/-Ls+j",
    persist=True,
    version=3.5)

zigbee1 = tinytuya.Device('bf9518a17c8c5f03dexdy9', cid='a4c138b58b9f50d3', parent=gw)
print(zigbee1.status())

Now it gives out this:

DEBUG:TinyTuya [1.15.1]

DEBUG:Python 3.13.1 (tags/v3.13.1:0671451, Dec  3 
2024, 19:06:28) [MSC v.1942 64 bit (AMD64)] on win32
DEBUG:Using pyca/cryptography 44.0.0 for crypto, GCM is supported
DEBUG:status() entry (dev_type is default)        
DEBUG:final payload_dict for 'bf9518a17c8c5f03dexdy9' ('v3.5'/'default'): {1: {'command': {'gwId': '', 'devId': '', 'uid': '', 't': ''}}, 7: {'command': {'protocol': 5, 't': 'int', 'data': {'cid': ''}}, 'command_override': 13}, 8: {'command': {'gwId': '', 'devId': ''}}, 9: {'command': {'gwId': '', 'devId': ''}}, 10: {'command': {}, 'command_override': 16}, 13: {'command': {'protocol': 5, 't': 'int', 'data': {'cid': ''}}}, 16: {'command': {}}, 18: {'command': {'dpId': [18, 19, 20]}}, 64: {'command': {'reqType': '', 'data': {}}}}
DEBUG:building command 10 payload=b'{"cid":"a4c138b58b9f50d3"}'
DEBUG:sending payload quick
DEBUG:final payload: b'0123456789abcdef'
DEBUG:payload encrypted=b'00006699000000000001000000030000002c303132333435363738396162328d2f7462593fce01644492322d01acc4880d55764cfd25fe808756f79883a900009966'
DEBUG:received data=b'0000669900000000a6a5000000040000005001a4111170b27d5b2b65d039e1bf25b10871791dd665275785c107fb29a2743974d7ed88cbf68e0eb8ea4d73abf1d00f8549e2afe468d736503a46cfa2e9c9baf479bd1c2b6182b999f744028787c58e00009966'
DEBUG:decrypted session key negotiation step 2 payload=b'8e2ee78851f9e31cnF]\xb8\xdc;\xc1\xd6 0\x7f\xe5*I\xe21J\xa5\xac\xbf\xda\x02\xbca\x85\xe2s1\x1b\xfd\xa1\x9e'
DEBUG:payload type = <class 'bytes'> len = 48     
DEBUG:session local nonce: b'0123456789abcdef' remote nonce: b'8e2ee78851f9e31c'
DEBUG:sending payload quick
DEBUG:final payload: b'\x19\xa9\xaa+\xd8\x01r\x80o\x8fN\x92A#C\x8b3>\x88\x0f\x17\xf4\x18\x91\x91\x86d`M$"\xbd'
DEBUG:payload encrypted=b'00006699000000000002000000050000003c3031323334353637383961621b15b76c8e6d7b7956d26b62106a274149b0f182f6f7ec6a5512c8e3cf323df0ba055d227e2991efd2f777731b8765ab00009966'
DEBUG:Session nonce XOR'd: b'\x08T\x00VQ\x02\x0e\x0f\r\x08\x07[\x06WT\x05'
DEBUG:Session IV: b'0123456789ab'
DEBUG:Session key negotiate success! session key: 
b'\n\xe8\x1d\x11\x07n\x07\xf64U"\xabW\x1e0\xcf'   
DEBUG:sending payload
DEBUG:final payload: b'{"cid":"a4c138b58b9f50d3"}'DEBUG:payload encrypted=b'00006699000000000003000000100000003630313233343536373839616259f50a46bd1e086e1eb508baa43ec9b7d8f458595c6eb5d6d975c055136d7f3fabf60d3ddc6220c2f4f200009966'
DEBUG:received data=b'0000669900000000a6a600000010000000521d970941f43699e925505520f1cf1b72b41f3ba3d9611283bfb42263310a166261e1f28fb755da41b3b283e0a015705156ed877f139b1eb08cbdcaaeba4b2f4255c2f9c92dae81cff25b62f48089374471db00009966'
DEBUG:received message=TuyaMessage(seqno=42662, cmd=16, retcode=0, payload=b'{"dps":{"1":252,"2":440},"cid":"a4c138b58b9f50d3"}', crc=b'\xf9\xc9-\xae\x81\xcf\xf2[b\xf4\x80\x897Dq\xdb', crc_good=True, 
prefix=26265, iv=b'\x1d\x97\tA\xf46\x99\xe9%PU ') 
DEBUG:raw unpacked message = TuyaMessage(seqno=42662, cmd=16, retcode=0, payload=b'{"dps":{"1":252,"2":440},"cid":"a4c138b58b9f50d3"}', crc=b'\xf9\xc9-\xae\x81\xcf\xf2[b\xf4\x80\x897Dq\xdb', crc_good=True, prefix=26265, iv=b'\x1d\x97\tA\xf46\x99\xe9%PU ')
DEBUG:decode payload=b'{"dps":{"1":252,"2":440},"cid":"a4c138b58b9f50d3"}'
DEBUG:decoded results='{"dps":{"1":252,"2":440},"cid":"a4c138b58b9f50d3"}'
DEBUG:status() received data={'dps': {'1': 252, '2': 440}, 'cid': 'a4c138b58b9f50d3', 'device': Device( 'bf9518a17c8c5f03dexdy9', address=None, local_key='', dev_type='default', connection_timeout=5, 
version=3.5, persist=False, cid='a4c138b58b9f50d3', parent='bfdf25a2ec8c5c5912ikqp', children={} )} 
{'dps': {'1': 252, '2': 440}, 'cid': 'a4c138b58b9f50d3', 'device': Device( 'bf9518a17c8c5f03dexdy9', address=None, local_key='', dev_type='default', connection_timeout=5, version=3.5, persist=False, cid='a4c138b58b9f50d3', parent='bfdf25a2ec8c5c5912ikqp', children={} )}

This is the temperature sensor reading.

However, I still get an error when doing this:
import tinytuya

tinytuya.set_debug(True)

gw = tinytuya.Device('bfdf25a2ec8c5c5912ikqp',
    address="192.168.10.200",
    local_key="=vwHbH'2'L/-Ls+j",
    persist=True,
    version=3.5)

print(gw.status())
DEBUG:TinyTuya [1.15.1]

DEBUG:Python 3.13.1 (tags/v3.13.1:0671451, Dec  3 
2024, 19:06:28) [MSC v.1942 64 bit (AMD64)] on win32
DEBUG:Using pyca/cryptography 44.0.0 for crypto, GCM is supported
DEBUG:status() entry (dev_type is default)        
DEBUG:final payload_dict for 'bfdf25a2ec8c5c5912ikqp' ('v3.5'/'default'): {1: {'command': {'gwId': '', 'devId': '', 'uid': '', 't': ''}}, 7: {'command': {'protocol': 5, 't': 'int', 'data': {}}, 'command_override': 13}, 8: {'command': {'gwId': '', 'devId': ''}}, 9: {'command': {'gwId': '', 'devId': ''}}, 10: {'command': {}, 'command_override': 16}, 
13: {'command': {'protocol': 5, 't': 'int', 'data': {}}}, 16: {'command': {}}, 18: {'command': {'dpId': [18, 19, 20]}}, 64: {'command': {'reqType': '', 'data': {}}}}
DEBUG:building command 10 payload=b'{}'
DEBUG:sending payload quick
DEBUG:final payload: b'0123456789abcdef'
DEBUG:payload encrypted=b'00006699000000000001000000030000002c303132333435363738396162328d2f7462593fce01644492322d01acc4880d55764cfd25fe808756f79883a900009966'
DEBUG:received data=b'0000669900000000317100000004000000501e93171574880dba46163dc5c9988b7f39750a3332ba9f98061752ba393945d24c6e79fbd8f1ea2d43496c5407bf6caea193b5a8270cff97ad6d5dce28c790ed93fda01c0356162c42832338ab7542bc00009966'
DEBUG:decrypted session key negotiation step 2 payload=b'9e16a13cf2a7096anF]\xb8\xdc;\xc1\xd6 0\x7f\xe5*I\xe21J\xa5\xac\xbf\xda\x02\xbca\x85\xe2s1\x1b\xfd\xa1\x9e'
DEBUG:payload type = <class 'bytes'> len = 48     
DEBUG:session local nonce: b'0123456789abcdef' remote nonce: b'9e16a13cf2a7096a'
DEBUG:sending payload quick
DEBUG:final payload: b"<\x8b'\xd9JV\x88-\xfc\xa5\xd9\xa3\xd8\xaf\x98\xeb\xbb\xe7\xcd\x9aP;*\xb3\x8e\x04\x10\xb7,\xac\x04z"
DEBUG:payload encrypted=b'00006699000000000002000000050000003c3031323334353637383961623e373a9e1c3a81d4c5f8fc5389e6fc21c169b417b138de484a90bc34aeba1b37968440d709d3319f127cb4ac38c8ab8100009966'
DEBUG:Session nonce XOR'd: b'\tT\x03\x05U\x04\x05T^\x0b\x00US]S\x07'
DEBUG:Session IV: b'0123456789ab'
DEBUG:Session key negotiate success! session key: 
b'\x0b\xe8\x1eB\x03h\x0c\xadgV%\xa5\x02\x147\xcd' 
DEBUG:sending payload
DEBUG:final payload: b'{}'
DEBUG:payload encrypted=b'00006699000000000003000000100000001e303132333435363738396162a28025a1ec6f7776da5aff46e2218ae0922f00009966'
DEBUG:received data=b'000066990000000031720000001000000035b0969c2bdf0a905275183d0291261e71d694097c8d9b327793d54be02c9e0e660ee387d1760ef76de9a9759067893005a37ee38bcc00009966'
DEBUG:received message=TuyaMessage(seqno=12658, cmd=16, retcode=16777216, payload=b'json obj data unvalid', crc=b'\x0e\xf7m\xe9\xa9u\x90g\x890\x05\xa3~\xe3\x8b\xcc', crc_good=True, prefix=26265, iv=b'\xb0\x96\x9c+\xdf\n\x90Ru\x18=\x02')
DEBUG:raw unpacked message = TuyaMessage(seqno=12658, cmd=16, retcode=16777216, payload=b'json obj data unvalid', crc=b'\x0e\xf7m\xe9\xa9u\x90g\x890\x05\xa3~\xe3\x8b\xcc', crc_good=True, prefix=26265, iv=b'\xb0\x96\x9c+\xdf\n\x90Ru\x18=\x02')        
DEBUG:decode payload=b'json obj data unvalid'     
DEBUG:'data unvalid' error detected: switching to 
dev_type 'device22'
DEBUG:_decode_payload() failed!
DEBUG:Device22 detected and updated (default -> device22) - Update payload and try again
DEBUG:ERROR Device22 Detected: Retry Command - 908 - payload: null
DEBUG:status() received data={'Error': 'Device22 Detected: Retry Command', 'Err': '908', 'Payload': 
None}
DEBUG:status() rebuilding payload for device22    
DEBUG:final payload_dict for 'bfdf25a2ec8c5c5912ikqp' ('v3.5'/'device22'): {1: {'command': {'gwId': 
'', 'devId': '', 'uid': '', 't': ''}}, 7: {'command': {'protocol': 5, 't': 'int', 'data': {}}, 'command_override': 13}, 8: {'command': {'gwId': '', 'devId': ''}}, 9: {'command': {'gwId': '', 'devId': 
''}}, 10: {'command': {'devId': '', 'uid': '', 't': ''}, 'command_override': 13}, 13: {'command': {'protocol': 5, 't': 'int', 'data': {}}}, 16: {'command': {}}, 18: {'command': {'dpId': [18, 19, 20]}}, 64: {'command': {'reqType': '', 'data': {}}}}   
DEBUG:building command 10 payload=b'{"devId":"bfdf25a2ec8c5c5912ikqp","uid":"bfdf25a2ec8c5c5912ikqp","t":"1739385626","dps":{"1":null}}'
DEBUG:sending payload
DEBUG:final payload: b'3.5\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00{"devId":"bfdf25a2ec8c5c5912ikqp","uid":"bfdf25a2ec8c5c5912ikqp","t":"1739385626","dps":{"1":null}}'
DEBUG:payload encrypted=b'000066990000000000040000000d0000008e303132333435363738396162ead326b63ea8e8a979b7f3c416d6d43abe82da741c9a5b669ef1bdee8feaefaf8c99f501e9e01ae1bcd57d497e84f1f250e69853bd7d21449a920c2a620c54adad0333dc2af600592f117fb97e82527324bd4f9c3ff79cee6f61623fdfbd9b20f892d48f438d2f48ce8fc6774ebc63328d42048c79fcb1e4f5f87de4ea5514ec446200009966'
DEBUG:Timeout in _send_receive() - retry 1 / 5
DEBUG:sending payload quick
DEBUG:final payload: b'0123456789abcdef'
DEBUG:payload encrypted=b'00006699000000000005000000030000002c303132333435363738396162328d2f7462593fce01644492322d01ac3a437f55452a7ce5016351cfd3dd4bc700009966'
DEBUG:received data=b'0000669900000000112600000004000000502974c467795d6f269174fa056749828f37a8a78a6f1bb8fe8328f0bf19198208f3fee79ce2f8fb7d9ffa3f45e41b1e4c73736eb256ff4e719e5d0fd5a6274a791462654f73cc1b4986f3014ba556e84e00009966'
DEBUG:decrypted session key negotiation step 2 payload=b'f45a8ce5d9f208d1nF]\xb8\xdc;\xc1\xd6 0\x7f\xe5*I\xe21J\xa5\xac\xbf\xda\x02\xbca\x85\xe2s1\x1b\xfd\xa1\x9e'
DEBUG:payload type = <class 'bytes'> len = 48     
DEBUG:session local nonce: b'0123456789abcdef' remote nonce: b'f45a8ce5d9f208d1'
DEBUG:sending payload quick
DEBUG:final payload: b'\xc8\xde\xbd\xa6&\xe3lF\\%\xa3ww ^\xf4:\x01Q\xd1IZ\x1fe\x8dS\x90"K\x17\xd54' 
DEBUG:payload encrypted=b'00006699000000000006000000050000003c303132333435363738396162ca62a0e1708f65bf6578868726693a3e408f285ca859eb9e49c73ca1c901ca795af0a471a0cbdf25229bda1a8c2cb6ee00009966'
DEBUG:Session nonce XOR'd: b'V\x05\x07R\x0cVS\x02\\\x00\x07PS\\\x01W'
DEBUG:Session IV: b'0123456789ab'
DEBUG:Session key negotiate success! session key: 
b'T\xb9\x1a\x15Z:Z\xfbe]"\xa0\x02\x15e\x9d'       
DEBUG:sending payload
DEBUG:final payload: b'3.5\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00{"devId":"bfdf25a2ec8c5c5912ikqp","uid":"bfdf25a2ec8c5c5912ikqp","t":"1739385626","dps":{"1":null}}'
DEBUG:payload encrypted=b'000066990000000000070000000d0000008e303132333435363738396162392a2a3f6822439eba3e45f094b0cd42db41b4821e55c73863d686a37f4f9876f8e685d0a51d2447cca95df0be87acc490153f4b45d3740f6ef50f34500c28b50c90b61e48f44232bf42ab42f452be3669db7ad6e88cb4ba2113378260b676312614d5499bbf34625a35663dcbce80d2d5c6f5a6f172d4f5df9cc47e93f52e717d7f00009966'
DEBUG:Timeout in _send_receive() - retry 2 / 5
{'Error': 'Check device key or version', 'Err': '914', 'Payload': None}

@uzlonewolf
Copy link
Collaborator

print(gw.status())

Yeah, a lot of hubs do not allow querying their status, you can only query sub-devices. You should be able to get a list of connected sub-devices with print( gw.subdev_query() ).

@SergioLuxx
Copy link
Author

@uzlonewolf
I successfully migrated from my old gateway to the new one, connected all Zigbee devices and manage them locally.
Also, there is another piece of news, even gw.status() started working, which returns
{'protocol': 4, 't': 1739422270, 'data': {'dps': {'2': 460}, 'cid': 'a4c13853c0dae4ca'}, 'dps': {'2': 460}}
Either it was necessary to connect many devices to the hub, or it just stood for some time.
In general, it looks like everything is working.
A possible solution is to
reconnect the hub to the router until any Zigbee device starts returning its status. Force IP and version (only guessing the version is not easy if the hub initially returns nothing, as in my case)
gw.status() - connect multiple devices to the hub or let it stand

@SergioLuxx
Copy link
Author

No, it looks like this is the status of the last device connected to the gateway.
And gw.subdev_query() does return a list of devices

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
tuya_device Support for specific Tuya Devices
Projects
None yet
Development

No branches or pull requests

4 participants