dauden1184 / RaspiNukiBridge

Simple Nuki Bridge implementation using asyncio
GNU General Public License v3.0
47 stars 19 forks source link

Callbacks do not report state changes #15

Closed pichljan closed 1 year ago

pichljan commented 2 years ago

I can easily control my Nuki 3.0 Pro using the bridge in this repository, but the changes in Nuki state are not reported to Home Assistant using callbacks when I lock/unlock Nuki using original Nuki app. Is that something that should work or only the changes triggered using this bridge are reported through the callbacks? Thanks

dauden1184 commented 2 years ago

Are you using the default nuki integration you find in homeassistant?

pichljan commented 1 year ago

Yes, I tried both the default Nuki integration and hass nuki ng. Also, I don't see any state changes in the logs of RaspiNukiBridge.

pichljan commented 1 year ago

Maybe I just misunderstood the concept of the connection of the RaspiNukiBridge to the Nuki lock. However, I wonder how to make the bridge register the state changes that are not done over the bridge (but using the lock HW button, for example). When I start the bridge, it connects, reads the state, and disconnects. Then, it never shows the state changes in the logs. I attached the log snippet. What am I doing wrong?

I am using Nuki 3.0 Pro

======== Running on http://0.0.0.0:8080 ========
(Press CTRL+C to quit)
2022-11-16 18:52:46.290|I|nuki.py:186|Nuki: ..., RSSI: -52 AdvertisementData(local_name='Nuki_XY', manufacturer_data={76: .....})
2022-11-16 18:52:46.291|I|nuki.py:174|Stop scanning
2022-11-16 18:52:46.323|I|nuki.py:546|Nuki connecting
2022-11-16 18:52:50.104|I|nuki.py:250|Device type: DeviceType.SMARTLOCK_1_2
2022-11-16 18:52:50.163|I|nuki.py:558|Connected
2022-11-16 18:52:50.164|I|nuki.py:575|Updating nuki state
2022-11-16 18:52:50.255|I|nuki.py:438|State: {'nuki_state': <NukiState.DOOR_MODE: 2>, 'lock_state': <LockState.LOCKED: 1>, 'trigger': 0, 'current_time': datetime.datetime(2022, 11, 16, 17, 53, 2), 'timezone_offset': 0, 'critical_battery_state': 56, 'current_update_count': 11, 'lock_n_go_timer': 0, 'last_lock_action': <NukiAction.LOCK: 2>, 'last_lock_action_trigger': 0, 'last_lock_action_completion_status': 0, 'door_sensor_state': <DoorsensorState.UNAVAILABLE: 0>, 'nightmode_active': 0}
2022-11-16 18:52:50.255|I|nuki.py:609|Retrieve nuki configuration
2022-11-16 18:52:50.418|I|nuki.py:451|Config: {'id': 824859492, 'name': 'Nuki', 'latitude': ..., 'longitude': ..., 'auto_unlatch': 1, 'pairing_enabled': 0, 'button_enabled': 1, 'led_enabled': 0, 'led_brightness': 3, 'current_time': datetime.datetime(2022, 11, 16, 17, 53, 2), 'timezone_offset': 0, 'dst_mode': 0, 'has_fob': 0, 'fob_action_1': 4, 'fob_action_2': 1, 'fob_action_3': 2, 'single_lock': 0, 'advertising_mode': 0, 'has_keypad': 0, 'firmware_version': '3.4.10', 'hardware_revision': '2.10', 'homekit_status': 3, 'timezone_id': 37}
2022-11-16 18:52:50.418|I|nuki.py:567|Nuki disconnecting
2022-11-16 18:52:52.402|I|nuki.py:170|Start scanning
2022-11-16 18:52:53.472|I|nuki.py:186|Nuki: 54:D2:72:2A:5B:64, RSSI: -57 AdvertisementData(local_name='Nuki_312A5B64', manufacturer_data={76: b'\x02\x15\xa9.\xe2\x00U\x01\x11\xe4\x91l\x08\x00 \x0c\x9af1*[d\xc8'}, service_uuids=['0000003e-0000-1000-8000-0026bb765291', '00000044-0000-1000-8000-0026bb765291', '00000045-0000-1000-8000-0026bb765291', '00000055-0000-1000-8000-0026bb765291', '00000096-0000-1000-8000-0026bb765291', '000000a2-0000-1000-8000-0026bb765291', '00001800-0000-1000-8000-00805f9b34fb', '0000180a-0000-1000-8000-00805f9b34fb', 'a92ee100-5501-11e4-916c-0800200c9a66', 'a92ee200-5501-11e4-916c-0800200c9a66'])
dauden1184 commented 1 year ago

The nuki notify a change of state using a ble beacon (the one you can see in the last line of the logs you pasted). In the field "manufacturer_data" the last value is "\xc8" (that is 200 in decimal), when this number is odd, it means a new state is available and the software will perform a connection to get the new state, if that number is even there is no new state.

Can you try to trigger a change of state and check if the beacon is received and what is the value?

pichljan commented 1 year ago

I tried to perform a lock action and checked the value. The number is still even after the action. The lock action was triggered between last two lines.

2022-11-17 13:02:42.440|I|nuki.py:185|Nuki: 54:D2:72:2A:5B:64, RSSI: -54 AdvertisementData(local_name='Nuki_312A5B64', manufacturer_data={76: b'\x02\x15\xa9.\xe2\x00U\x01\x11\xe4\x91l\x08\x00 \x0c\x9af1*[d\xc8'}, service_uuids=['0000003e-0000-1000-8000-0026bb765291', '00000044-0000-1000-8000-0026bb765291', '00000045-0000-1000-8000-0026bb765291', '00000055-0000-1000-8000-0026bb765291', '00000096-0000-1000-8000-0026bb765291', '000000a2-0000-1000-8000-0026bb765291', '00001800-0000-1000-8000-00805f9b34fb', '0000180a-0000-1000-8000-00805f9b34fb', 'a92ee100-5501-11e4-916c-0800200c9a66', 'a92ee200-5501-11e4-916c-0800200c9a66'])
2022-11-17 13:03:36.566|I|nuki.py:185|Nuki: 54:D2:72:2A:5B:64, RSSI: -57 AdvertisementData(local_name='Nuki_312A5B64', manufacturer_data={76: b'\x02\x15\xa9.\xe2\x00U\x01\x11\xe4\x91l\x08\x00 \x0c\x9af1*[d\xc8'}, service_uuids=['0000003e-0000-1000-8000-0026bb765291', '00000044-0000-1000-8000-0026bb765291', '00000045-0000-1000-8000-0026bb765291', '00000055-0000-1000-8000-0026bb765291', '00000096-0000-1000-8000-0026bb765291', '000000a2-0000-1000-8000-0026bb765291', '00001800-0000-1000-8000-00805f9b34fb', '0000180a-0000-1000-8000-00805f9b34fb', 'a92ee100-5501-11e4-916c-0800200c9a66', 'a92ee200-5501-11e4-916c-0800200c9a66'])
2022-11-17 13:04:20.628|I|nuki.py:185|Nuki: 54:D2:72:2A:5B:64, RSSI: -57 AdvertisementData(local_name='Nuki_312A5B64', manufacturer_data={76: b'\x02\x15\xa9.\xe2\x00U\x01\x11\xe4\x91l\x08\x00 \x0c\x9af1*[d\xc8'}, service_uuids=['0000003e-0000-1000-8000-0026bb765291', '00000044-0000-1000-8000-0026bb765291', '00000045-0000-1000-8000-0026bb765291', '00000055-0000-1000-8000-0026bb765291', '00000096-0000-1000-8000-0026bb765291', '000000a2-0000-1000-8000-0026bb765291', '00001800-0000-1000-8000-00805f9b34fb', '0000180a-0000-1000-8000-00805f9b34fb', 'a92ee100-5501-11e4-916c-0800200c9a66', 'a92ee200-5501-11e4-916c-0800200c9a66'])
2022-11-17 13:05:05.970|I|nuki.py:185|Nuki: 54:D2:72:2A:5B:64, RSSI: -59 AdvertisementData(local_name='Nuki_312A5B64', manufacturer_data={76: b'\x02\x15\xa9.\xe2\x00U\x01\x11\xe4\x91l\x08\x00 \x0c\x9af1*[d\xc8'}, service_uuids=['0000003e-0000-1000-8000-0026bb765291', '00000044-0000-1000-8000-0026bb765291', '00000045-0000-1000-8000-0026bb765291', '00000055-0000-1000-8000-0026bb765291', '00000096-0000-1000-8000-0026bb765291', '000000a2-0000-1000-8000-0026bb765291', '00001800-0000-1000-8000-00805f9b34fb', '0000180a-0000-1000-8000-00805f9b34fb', 'a92ee100-5501-11e4-916c-0800200c9a66', 'a92ee200-5501-11e4-916c-0800200c9a66'])
2022-11-17 13:06:21.821|I|nuki.py:185|Nuki: 54:D2:72:2A:5B:64, RSSI: -57 AdvertisementData(local_name='Nuki_312A5B64', manufacturer_data={76: b'\x02\x15\xa9.\xe2\x00U\x01\x11\xe4\x91l\x08\x00 \x0c\x9af1*[d\xc8'}, service_uuids=['0000003e-0000-1000-8000-0026bb765291', '00000044-0000-1000-8000-0026bb765291', '00000045-0000-1000-8000-0026bb765291', '00000055-0000-1000-8000-0026bb765291', '00000096-0000-1000-8000-0026bb765291', '000000a2-0000-1000-8000-0026bb765291', '00001800-0000-1000-8000-00805f9b34fb', '0000180a-0000-1000-8000-00805f9b34fb', 'a92ee100-5501-11e4-916c-0800200c9a66', 'a92ee200-5501-11e4-916c-0800200c9a66'])
pichljan commented 1 year ago

I think I found what caused the problem. I re-paired the lock with RaspiNukiBridge, and it started working. The state is reported correctly, but with a significant delay, though (20 sec). Can I configure how often the state is reported or is it something that is hard-wired in Nuki? Additionally, I found out that after re-paring the Nuki lock, the built it wifi was disabled. Once I enabled it again, the state reporting over bluetooth stopped working again. I guess it cannot be using both bluetooth and wifi.

dauden1184 commented 1 year ago

Good to hear you found the issue! 20 seconds seems a lot, with my nuki v2 I get the notification after a couple of seconds (unfortunately I don't own a nuki v3, so i cannot test this), how far are the raspberry and the nuki?

I guess it cannot be using both bluetooth and wifi.

That's sad but probably it's because of the battery life? I'll try to search on the nuki developer forum if there are some info about this