[Python] Tinytuya's Raw data command and Tuya BLE smart locks

Discussão em 'Python' iniciado por Stack, Abril 9, 2025.

  1. Stack

    Stack Membro Participativo

    everyone. I hope you're doing fine.

    I'm trying to develop a little program to set up temporary passwords in two BLE locks at the same time using python. The locks are Raykube M5 Tuya (Link to AliExpress page) and I'm using a Moes multimode hub (Link to AliExpress page).

    So, after a lot of search, I've found tinytuya and the DP docs from Tuya (Bluetooth Lock Implementation Process and Data Point Reference). Since then, I was trying to code raw data with a temp password with the DP 51. I know I must be doing something wrong because I can't configure the password, but I was able to get the status of the lock.

    I've already read other threads from the tinytuya's github ([[https://github.com//discussions/434]] and [[https://github.com//discussions/373]]), but they didn't help me.

    Can anyone help me, please? Thank you so much in advanced.

    These are the DPS got from the docs and from the scan:

    {
    "name": "Test",
    "id": "<Lock ID>",
    "key": "<Local Key>",
    "mac": "<MAC Address>",
    "uuid": "<UUID>",
    "sn": "<Serial Number>",
    "category": "jtmspro",
    "product_name": "LA-T01",
    "product_id": "8gza4o8a",
    "biz_type": 0,
    "model": "",
    "sub": true,
    "icon": "https://images.tuyaeu.com/smart/icon/bay1665802448309laHv/409bb78774085d8696d28eadddc4c486.png",
    "node_id": "<NodeID>",
    "mapping": {
    "1": {
    "code": "unlock_method_create",
    "type": "Raw",
    "values": {}
    },
    "2": {
    "code": "unlock_method_delete",
    "type": "Raw",
    "values": {}
    },
    "3": {
    "code": "unlock_method_modify",
    "type": "Raw",
    "values": {}
    },
    "8": {
    "code": "residual_electricity",
    "type": "Integer",
    "values": {
    "min": 0,
    "max": 100,
    "scale": 0,
    "step": 1
    }
    },
    "12": {
    "code": "unlock_fingerprint",
    "type": "Integer",
    "values": {
    "min": 0,
    "max": 999,
    "scale": 0,
    "step": 1
    }
    },
    "13": {
    "code": "unlock_password",
    "type": "Integer",
    "values": {
    "min": 0,
    "max": 999,
    "scale": 0,
    "step": 1
    }
    },
    "15": {
    "code": "unlock_card",
    "type": "Integer",
    "values": {
    "min": 0,
    "max": 999,
    "scale": 0,
    "step": 1
    }
    },
    "18": {
    "code": "open_inside",
    "type": "Boolean",
    "values": {}
    },
    "19": {
    "code": "unlock_ble",
    "type": "Integer",
    "values": {
    "min": 0,
    "max": 999,
    "scale": 0,
    "step": 1
    }
    },
    "21": {
    "code": "alarm_lock",
    "type": "Enum",
    "values": {
    "range": [
    "wrong_finger",
    "wrong_password",
    "wrong_card",
    "wrong_face",
    "tongue_bad",
    "too_hot",
    "unclosed_time",
    "tongue_not_out",
    "pry",
    "key_in",
    "low_battery",
    "power_off",
    "shock",
    "defense"
    ]
    }
    },
    "31": {
    "code": "beep_volume",
    "type": "Enum",
    "values": {
    "range": [
    "mute",
    "low",
    "normal",
    "high"
    ]
    }
    },
    "32": {
    "code": "reverse_lock",
    "type": "Boolean",
    "values": {}
    },
    "33": {
    "code": "automatic_lock",
    "type": "Boolean",
    "values": {}
    },
    "36": {
    "code": "auto_lock_time",
    "type": "Integer",
    "values": {
    "min": 1,
    "max": 1800,
    "scale": 0,
    "step": 1
    }
    },
    "40": {
    "code": "closed_opened",
    "type": "Enum",
    "values": {
    "range": [
    "unknown",
    "open",
    "closed"
    ]
    }
    },
    "46": {
    "code": "manual_lock",
    "type": "Boolean",
    "values": {}
    },
    "47": {
    "code": "lock_motor_state",
    "type": "Boolean",
    "values": {}
    },
    "51": {
    "code": "temporary_password_creat",
    "type": "Raw",
    "values": {}
    },
    "52": {
    "code": "temporary_password_delete",
    "type": "Raw",
    "values": {}
    },
    "53": {
    "code": "temporary_password_modify",
    "type": "Raw",
    "values": {}
    },
    "54": {
    "code": "synch_method",
    "type": "Raw",
    "values": {}
    },
    "55": {
    "code": "unlock_temporary",
    "type": "Integer",
    "values": {
    "min": 0,
    "max": 999,
    "scale": 0,
    "step": 1
    }
    },
    "58": {
    "code": "arming_switch",
    "type": "Boolean",
    "values": {}
    },
    "61": {
    "code": "remote_no_dp_key",
    "type": "Raw",
    "values": {}
    },
    "62": {
    "code": "unlock_phone_remote",
    "type": "Integer",
    "values": {
    "min": 0,
    "max": 999,
    "scale": 0,
    "step": 1
    }
    },
    "63": {
    "code": "unlock_voice_remote",
    "type": "Integer",
    "values": {
    "min": 0,
    "max": 999,
    "scale": 0,
    "step": 1
    }
    },
    "64": {
    "code": "password_offline_time",
    "type": "String",
    "values": "{}"
    },
    "65": {
    "code": "unlock_offline_clear_single",
    "type": "Raw",
    "values": {}
    },
    "66": {
    "code": "unlock_offline_clear",
    "type": "Raw",
    "values": {}
    },
    "67": {
    "code": "unlock_offline_pd",
    "type": "Raw",
    "values": {}
    },
    "68": {
    "code": "special_function",
    "type": "Enum",
    "values": {
    "range": [
    "function1",
    "function2"
    ]
    }
    },
    "70": {
    "code": "check_code_set",
    "type": "Raw",
    "values": {}
    },
    "71": {
    "code": "ble_unlock_check",
    "type": "Raw",
    "values": {}
    },
    "73": {
    "code": "remote_pd_setkey_check",
    "type": "Raw",
    "values": {}
    }
    },
    "parent": "",
    "ip": "",
    "version": ""
    }


    This is the code I wrote:

    import tinytuya

    gwid='<Gateway ID>'
    addr='Auto'
    gwlk='<Gateway and Lock local key>'
    did='<Lock ID>'
    nid='<CID or NodeID>'

    p = tinytuya.Device(gwid,addr,gwlk, version=3.4)
    d = tinytuya.Device(did,node_id=nid,parent=p)

    payload = d.generate_payload(tinytuya.CONTROL, {'51': [0x01, [0x67EB90FF, 0x67ECE27F, 0x01, 0x00, 0x00, 0x00, 0x00, 0, 0, 0, 0], 0x00, 0x06, [0x01,0x02,0x03,0x04,0x05,0x06]]})
    stat = d._send_receive(payload)
    print(stat)

    Continue reading...

Compartilhe esta Página