tuya-local icon indicating copy to clipboard operation
tuya-local copied to clipboard

Request for smart lock support

Open JanekSMC opened this issue 2 years ago • 18 comments

Specifically the Orion grid connect wifi smart deadlock. But I note an absence of any smart locks in the list of supported devices (also possible I totally missed them somehow!!)

I’ve never made a request before, but I’m happy to provide any required info!

When I add devid up and local key it just times out with an unknown error.

thanks!!

JanekSMC avatar Apr 16 '22 13:04 JanekSMC

After you add the device, and get either an error saying no matching devices or get offered simple switch as the only match, look in the Home Assistant logs. There should be a couple of warning messages from the tuya-local integration, one of which will have the actual data received from the device that it tried to match to a config.

That would be a starting point. Another good source of data if you signed up to the iot.tuya.com dev portal to get the local key, is under "Cloud" / "API Explorer", then "Smart Home Management System" / "Device Control" / "Get Device Specification Attributes". Choose the data center your device is registered to, and enter the device ID. This should contain an explanation of each field and ranges of the values, and tie the fields to local dp_ids. Often not all local dps are available in the cloud API, but the useful ones usually are.

make-all avatar Apr 16 '22 21:04 make-all

Probably some work is required to support actual security locks, as the current support for locks is only used for child locks on other devices, so is very simple.

make-all avatar Apr 16 '22 21:04 make-all

I’ll get into the API as soon as I can get to my laptop, it’s excruciating to use the cloud explorer site on mobile.

In all honesty, I would settle for remote lock, though remote unlock would be nice too, could make for some fantastic automations (especially with toddlers!!!)

JanekSMC avatar Apr 17 '22 02:04 JanekSMC

From the debugging menu in tuya developer: Device name: DL017HA Wi-Fi Deadbolt

standard status set:

unlock_fingerprint Integer { "unit": "", "min": 0, "max": 999, "scale": 0, "step": 1 }
unlock_password Integer { "unit": "", "min": 0, "max": 999, "scale": 0, "step": 1 }
unlock_temporary Integer { "unit": "", "min": 0, "max": 999, "scale": 0, "step": 1 }
unlock_dynamic Integer { "min": 0, "max": 999, "scale": 0, "step": 1 }
unlock_card Integer { "unit": "", "min": 0, "max": 999, "scale": 0, "step": 1 }
alarm_lock Enum { "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" ] }
unlock_request Integer { "unit": "", "min": 0, "max": 90, "scale": 0, "step": 1 }
residual_electricity Integer { "unit": "", "min": 0, "max": 100, "scale": 0, "step": 1 }
unlock_app Integer { "unit": "", "min": 0, "max": 999, "scale": 0, "step": 1 }
hijack Boolean "{true,false}"
update_all_finger List {}
update_all_password List {}
update_all_card List {}

JanekSMC avatar Apr 17 '22 05:04 JanekSMC

Please see the exact menu item I specified above. That is the only function in the cloud API that ties back to local commands.

make-all avatar Apr 17 '22 05:04 make-all

{ "result": { "category": "ms", "functions": [], "status": [ { "code": "unlock_fingerprint", "lang_config": { "unit": "" }, "name": "fingerprint unlock", "type": "Integer", "values": "{"unit":"","min":0,"max":999,"scale":0,"step":1}" }, { "code": "unlock_password", "lang_config": { "unit": "" }, "name": "password unlock", "type": "Integer", "values": "{"unit":"","min":0,"max":999,"scale":0,"step":1}" }, { "code": "unlock_temporary", "lang_config": { "unit": "" }, "name": "temporary password unlock", "type": "Integer", "values": "{"unit":"","min":0,"max":999,"scale":0,"step":1}" }, { "code": "unlock_dynamic", "lang_config": { "unit": "" }, "name": "dynamic password unlock", "type": "Integer", "values": "{"min":0,"max":999,"scale":0,"step":1}" }, { "code": "unlock_card", "lang_config": { "unit": "" }, "name": "card unlock", "type": "Integer", "values": "{"unit":"","min":0,"max":999,"scale":0,"step":1}" }, { "code": "alarm_lock", "lang_config": { "key_in": "key in use", "low_battery": "low battery", "power_off": "no power", "pry": "forceful tamper alert", "shock": "tamper alert", "tongue_bad": "deadbolt stuck", "tongue_not_out": "bolt extension unsuccessful", "too_hot": "temperature too high", "unclosed_time": "unlocked timeout", "wrong_card": "invalid tag", "wrong_face": "invalid facial recognition (not available)", "wrong_finger": "invalid fingerprint", "wrong_password": "invalid passcode" }, "name": "lock alert", "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"]}" }, { "code": "unlock_request", "lang_config": { "unit": "" }, "name": "Remote Unlock Request", "type": "Integer", "values": "{"unit":"","min":0,"max":90,"scale":0,"step":1}" }, { "code": "residual_electricity", "lang_config": { "unit": "" }, "name": "battery percentage", "type": "Integer", "values": "{"unit":"","min":0,"max":100,"scale":0,"step":1}" }, { "code": "unlock_app", "lang_config": { "unit": "" }, "name": "app request unlock", "type": "Integer", "values": "{"unit":"","min":0,"max":999,"scale":0,"step":1}" }, { "code": "hijack", "lang_config": { "false": "off", "true": "on" }, "name": "unlock alert", "type": "Boolean", "values": "{}" }, { "code": "update_all_finger", "lang_config": { "unit": "" }, "name": "Update all fingerprint", "type": "List", "values": "{}" }, { "code": "update_all_password", "lang_config": { "unit": "" }, "name": "Update all password", "type": "List", "values": "{}" }, { "code": "update_all_card", "lang_config": { "unit": "" }, "name": "Update all Card", "type": "List", "values": "{}" } ] }, "success": true, "t": , "tid": "" }

JanekSMC avatar Apr 17 '22 05:04 JanekSMC

Actually, apologies, that wasnt from the SHM segment of the developer console. I think this is what you're after? This is from "Get Device Specification Attribute" as opposed to "Get device specification attributes". the singular attribute page seems to me to have data more aligned with local control

{ "result": { "category": "ms", "functions": [], "status": [ { "code": "unlock_fingerprint", "dp_id": 1, "type": "Integer", "values": "{"unit":"","min":0,"max":999,"scale":0,"step":1}" }, { "code": "unlock_password", "dp_id": 2, "type": "Integer", "values": "{"unit":"","min":0,"max":999,"scale":0,"step":1}" }, { "code": "unlock_temporary", "dp_id": 3, "type": "Integer", "values": "{"unit":"","min":0,"max":999,"scale":0,"step":1}" }, { "code": "unlock_dynamic", "dp_id": 4, "type": "Integer", "values": "{"min":0,"max":999,"scale":0,"step":1}" }, { "code": "unlock_card", "dp_id": 5, "type": "Integer", "values": "{"unit":"","min":0,"max":999,"scale":0,"step":1}" }, { "code": "alarm_lock", "dp_id": 8, "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"]}" }, { "code": "unlock_request", "dp_id": 9, "type": "Integer", "values": "{"unit":"","min":0,"max":90,"scale":0,"step":1}" }, { "code": "residual_electricity", "dp_id": 12, "type": "Integer", "values": "{"unit":"","min":0,"max":100,"scale":0,"step":1}" }, { "code": "unlock_app", "dp_id": 15, "type": "Integer", "values": "{"unit":"","min":0,"max":999,"scale":0,"step":1}" }, { "code": "hijack", "dp_id": 16, "type": "Boolean", "values": "{}" }, { "code": "update_all_finger", "dp_id": 25, "type": "List", "values": "{}" }, { "code": "update_all_password", "dp_id": 26, "type": "List", "values": "{}" }, { "code": "update_all_card", "dp_id": 27, "type": "List", "values": "{}" } ] }, "success": true, "t": , "tid": "" }

JanekSMC avatar Apr 17 '22 06:04 JanekSMC

So based on this, it seems it isn't possible to control the device (maybe only applies to from the cloud), only to monitor status. I guess maybe for local API, the remote and/or app unlock dps can also be used to unlock, but I don't know if there will need to be some code provided for security.

make-all avatar Apr 17 '22 21:04 make-all

I've read Tuya's documentation on WiFi smart locks, and this seems to almost follow that reference design (unlock_app is documented as a boolean, while here is is documented as an integer). One issue is that it doesn't seem to report the current status of the lock - unless a non-zero report in one of the unlock_.. fields is indicating that (the docs say it reports the last finger etc that unlocked the lock, but if it clears back to 0 when the door is locked, then it could work as an indicator).

It is also unclear to me whether all of these dps are always reported, I suspect at least the update_... ones are only reported when there is an update, as they are potentially large fields (maybe 500 bytes each after hex encoding). Getting a list of the dps actually reported by the lock would help clear this up. You should see such a list in a Warning message in the Home Assistant log when you try to add the device and it is unrecognised.

It seems from the Tuya docs that there should be a dp_id 10 which is used to remotely unlock the door in response to a request on dp_id 9 - though the documentation says it is read-only, which is confusing. dp_id 9 can also be used to set the countdown timer in which a request needs to be approved after the request is made. The above dps list should also clear up whether this is reported, or a write only field.

make-all avatar Jul 03 '22 02:07 make-all

Hi @make-all great work on adding this since not even the official integration has lock support. Could any tuya wifi lock work with this?

ferbulous avatar Jul 09 '22 20:07 ferbulous

Other wifi locks could potentially work with this, but there are some other features in the Tuya docs such as face recognition unsupported by this lock which I have not implemented yet, so there is potentially more work needed.

make-all avatar Jul 10 '22 01:07 make-all

0.18.0 has the config I wrote for this lock. However, as there was no capture of the local data, only the Tuya portal info, I am not 100% sure it will work. If it is not detected still, please supply the WARNING messages from the Home Assistant log that relate to this device.

make-all avatar Jul 16 '22 15:07 make-all

I should be receiving my tuya wifi lock very soon. Should i post the logs here or just open a new issue?

ferbulous avatar Jul 17 '22 13:07 ferbulous

Please open a new issue if it is not the same device.

make-all avatar Jul 17 '22 13:07 make-all

Apologies I’ve been offline for so long, school holidays and all…

Wow, amazing work! Thankyou!! You are simply incredible! I am having issues connecting to the lock and I’m not sure what’s going on. I have my local ip, MAC address, devID localkey but it refuses to connect. I’ll dig up the logs ASAP for you.

JanekSMC avatar Jul 25 '22 00:07 JanekSMC

Just note if you pair with the app again, it will reassign a new local key. If you've already registered with the iot.tuya.com portal, you should be able to find the local key under some of the Cloud / API Explorer functions to confirm whether it has changed.

Also, tuya devices in general only handle one local connection at a time, so maybe turn off WiFi on your phone while you try connecting to HA to make sure the phone app is not hogging the local connection in the background.

make-all avatar Aug 03 '22 14:08 make-all

Something odd is happening with my lock, it only ever pops online for a moment when it’s activated externally. I cannot seem to access it from any software, including the phone app. it doesn’t appear in my router as active or anything. That includes assigning PINs to it or temporary access codes. Frustrating!!!! Therefore I can’t even add it to the integration at all :(

JanekSMC avatar Sep 09 '22 00:09 JanekSMC

I think that is not unusual for battery powered devices. Generally such devices will only work properly via the cloud, as they only wake periodically to contact the server then go back to sleep.

make-all avatar Sep 09 '22 04:09 make-all

I just got this kind of smart lock today. Sleep mode is a bummer as it prevents us from sending commands to the device. If only there is a way to wake the device up..

danieljohngomez avatar Feb 07 '23 12:02 danieljohngomez

Orion GridConnect sells quite a few Bluetooth locks that can integrate with their Bluetooth to WiFi hub. Is there a chance this integration could work through that hub, or does the hub prevent it? Thank you.

I've ordered one. Happy to be the guinea pig.

jaydisc avatar Mar 31 '23 03:03 jaydisc

Bluetooth and zigbee locks should now be possible to work via hubs in 2023.5.0. One such lock has already been added.

make-all avatar May 07 '23 09:05 make-all

Hey @make-all I'm planning to buy this one BT Tuya lock: https://www.aliexpress.com/item/1005005145369411.html There is also usb wifi hub in the description. Is it compatible with your software?

NicoxDJ avatar May 08 '23 22:05 NicoxDJ

Support for tuya hubs was just added. There have only been two reports though, one positive and one negative so it is not yet mature enough to give a definitive yes.

make-all avatar May 09 '23 11:05 make-all