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

lock state not updating properly #132

Closed
switey opened this issue Apr 2, 2024 · 11 comments
Closed

lock state not updating properly #132

switey opened this issue Apr 2, 2024 · 11 comments
Labels
enhancement New feature or request

Comments

@switey
Copy link

switey commented Apr 2, 2024

my setup is Nuki smart lock 4.0, Nuki Bridge and Nuki opener
homekit hub is Apple TV 4K 2nd gen

after unlocking the door lock it remains in "unlocked" state indefinitely even though the lock is auto-locked after a minute
restarting homebridge or just home bridge-nb childbridge sometimes fixes the issue

@ebaauw
Copy link
Owner

ebaauw commented Apr 2, 2024

Does the lock state change in the Nuki app?

Does the lock state change after you select Identify on the lock accessory in HomeKit? This causes Homebridge NB to ask the Nuki bridge to contact the smart lock and update its cache of the lock state.

Do you see any errors or warnings in the Homebridge log?

Please set Log Level on the Nuki bridge accessory to 2, run Homebridge in DEBUG mode, and capture and attach the Homebridge log file, from restarting the child bridge, through unlocking, waiting for the auto-lock and waiting a couple of minutes.

@switey
Copy link
Author

switey commented Apr 2, 2024

hi, thank you for a swift reply
to be honest I don't really see 'identify' button in HomeKit
Nuki app consistently shows lock state, doesn't matter if lock is auto (un)locked, or changes state via manual (un)lock through Nuki app or homekit
as for homebridge log file, I will try to reproduce the error, for now lock state is updated properly (the bug doesnt happen all the time)
can you confirm port number that should be used in homebridge nb settings for bridge communication?

@ebaauw
Copy link
Owner

ebaauw commented Apr 2, 2024

You might need to use Eve or another decent HomeKit app to find Identify; Apple's Home app doesn't support all of HomeKit.

Homebridge NB calls the API of the Nuki bridge. My bridge exposes this API on port 8080, which, I think, is the default. Not even sure if that can be changed. It is returned by nb discover.

In addition, Homebridge NB provides a web server for callbacks from the Nuki bridge. By default this uses a random port (>= 1024), but you can change this under the Advanced settings. Homebridge NB issues a log message on startup, which shows the port: "listening on http://0.0.0.0:45969/notify".

@switey
Copy link
Author

switey commented Apr 2, 2024

here's and excerpt of homebridge log
Here's what happened:
about 5:10 PM I left the house using lock'n'go which is set to lock the door after 20 seconds
the attached log fragment shows that homebridge nb still thinks the door is unlocked at 5:41 PM, it changed back to 'locked' when I re-entered the house at around 5:48 PM and Nuki re-locked after auto-opening.

[4/2/2024, 5:41:57 PM] [Nuki] Nuki_Bridge_689A091E: request 147: GET /callback/list

[4/2/2024, 5:41:57 PM] [Nuki] Nuki_Bridge_689A091E: request 147: 200 OK
[4/2/2024, 5:41:57 PM] [Nuki] Nuki_Bridge_689A091E: subscription: > {"id":0,"url":"http://192.168.0.8:62330/notify/689A091E"}
[4/2/2024, 5:41:57 PM] [Nuki] Nuki_Bridge_689A091E: request 148: GET /info
[4/2/2024, 5:41:57 PM] [Nuki] Nuki_Bridge_689A091E: request 148: 200 OK
[4/2/2024, 5:41:57 PM] [Nuki] Nuki_Bridge_689A091E: bridge: {"bridgeType":1,"ids":> {"hardwareId":1013065235,"serverId":1754925342},"versions":> {"firmwareVersion":"2.17.0","wifiFirmwareVersion":"2.4.0"},"uptime":293370,"currentTime":"2024-04-02T15:42:02+00:00","wlanConnected":true,"serverConnected":true,"scanResults":> [{"deviceType":2,"nukiId":930999314,"name":"Nuki_Opener_377DEC12","rssi":-68,"paired":true},> {"deviceType":4,"nukiId":1015571181,"name":"Nuki_3C8862ED","rssi":-54,"paired":true}]}
[4/2/2024, 5:41:57 PM] [Nuki] Nuki_Bridge_689A091E: Last Updated: set to "Tue Apr 02 2024 17:42:02" (from "Tue Apr 02 2024 17:41:02")
[4/2/2024, 5:41:57 PM] [Nuki] Nuki_Bridge_689A091E: request 149: GET /list
[4/2/2024, 5:41:57 PM] [Nuki] Nuki_Bridge_689A091E: request 149: 200 OK
[4/2/2024, 5:41:57 PM] [Nuki] Nuki_Bridge_689A091E: device: > {"deviceType":4,"nukiId":1015571181,"name":"Augustowska","firmwareVersion":"4.1.8","lastKnownState":{"mode":2,"state":6,"stateName":"unlocked (lock 'n' go)","batteryCritical":false,"batteryCharging":false,"batteryChargeState":100,"timestamp":"2024-04-02T15:08:33+00:00"}}
[4/2/2024, 5:41:57 PM] [Nuki] Nuki_Bridge_689A091E: device: > {"deviceType":2,"nukiId":930999314,"name":"Domofon","firmwareVersion":"1.10.1","lastKnownState":> {"mode":3,"state":1,"stateName":"online","batteryCritical":false,"ringactionTimestamp":"2024-04-02T12:49:39+00:00","ringactionState":false,"timestamp":"2024-04-02T12:49:49+00:00"}}

@ebaauw
Copy link
Owner

ebaauw commented Apr 2, 2024

The Nuki bridge reports it as unlocked (with lock 'n' go enabled):

[4/2/2024, 5:41:57 PM] [Nuki] Nuki_Bridge_689A091E: request 149: GET /list
[4/2/2024, 5:41:57 PM] [Nuki] Nuki_Bridge_689A091E: request 149: 200 OK
[4/2/2024, 5:41:57 PM] [Nuki] Nuki_Bridge_689A091E: device: > {"deviceType":4,"nukiId":1015571181,"name":"Augustowska","firmwareVersion":"4.1.8","lastKnownState":{"mode":2,"state":6,"stateName":"unlocked (lock 'n' go)","batteryCritical":false,"batteryCharging":false,"batteryChargeState":100,"timestamp":"2024-04-02T15:08:33+00:00"}}

Note the timestamp of the last known state (by the Nuki bridge): it hasn't updated since 15:08 (UTC). I've never used lock 'n' go myself, but I would expect the lock to report state 1, locked, after it auto locks. If it does, it doesn't seem to inform the Nuki bridge.

As I asked before, could you please force the Nuki bridge to update the last known state, by issuing Identify on the HomeKit accessory (as exposed by Homebridge NB), or by issuing nb lockState 1015571181 4 from the command line. That should at least update the timestamp, if not the state. You can run nb list to confirm, or wait for Homebridge NB to poll the Nuki bridge.

@ebaauw
Copy link
Owner

ebaauw commented Apr 2, 2024

Just tried myself (on my SmartLock 4): press twice to activate lock 'n' go with the door open. On closing the door (I have a door sensor), the SmartLock locks. The HomeKit accessory, as exposed by the lock itself over Matter, switches state immediately. The Nuki bridge (and, consequently, the accessory as exposed by Homebridge NB) continues to report unlocked. On Identify, the bridge refreshes its cached state and now reports locked, causing Homebridge NB to update the accessory.

I would quality this as a Nuki bug, probably in the Nuki smart lock firmware (it should inform the bridge of the new state).

@switey
Copy link
Author

switey commented Apr 2, 2024

that's a shame
any way you can work around it?
the funny thing is, my lock 4.0 doesn't work with HomeKit over matter natively, it's been buggy since I got it. people over at Nuki seem helpless. I've found your plugin to make the lock work somehow with my setup

ebaauw added a commit that referenced this issue Apr 3, 2024
@ebaauw
Copy link
Owner

ebaauw commented Apr 3, 2024

Could you try beta v1.4.17-1?

This version forces the Nuki bridge to refresh the smart lock's state, when it seems stuck on: unlocked (lock 'n' go), locking, unlocking, or unlatching.

I daren't do a regular force-refresh as this would drain the smart lock's battery.

@switey
Copy link
Author

switey commented Apr 3, 2024

hi!
thanks again for your cooperation. I'm one test in aaaaand it worked! will continue to test it with lock'n'go and report back in a day or two. this is my default way of leaving the house so I'm really happy with the progress
cheers

@ebaauw ebaauw added the enhancement New feature or request label Apr 3, 2024
@ebaauw
Copy link
Owner

ebaauw commented Apr 4, 2024

The beta seemed to be running fine in my house; I published v1.4.17.

@ebaauw ebaauw closed this as completed Apr 4, 2024
@switey
Copy link
Author

switey commented Apr 5, 2024

Now the lock seems to be stuck on regular unlock

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

2 participants