Python Plugin: NUKI locks

Python and python framework
Post Reply
User avatar
heggink
Posts: 536
Joined: Tuesday 08 September 2015 21:44
Target OS: Raspberry Pi
Domoticz version: V4.9999
Location: NL
Contact:

Python Plugin: NUKI locks

Post by heggink » Monday 10 September 2018 22:10

If anyone is interested to test drive the nuki lock plugin then please find it at https://github.com/heggink/domoticz-nuki

I am pretty sure that not all branches in the code have been tested especially since I own to bridges where both bridges have a single lock (due to the distance between the locks in relation to Bluetooth comms between lock and bridge). The plugin 'should' support multiple locks per bridge but I cannot easily test that without creating a bridge emulator.

Also, as per the README, if you have multiple bridges, you will need separate domoticz HW devices per bridge each with their own free port (bridge1 8008, bridge2 8009 or any other free port on your system, and so on).

I have been running it in test myself and so far so good :lol: but I suspect some issues along the way.

Herman
ps: thanks for dnpwwo for nudging in the right direction here and there
ps2: The plugin currently uses s.connect(("192.168.1.1", 80)) and s.getsockname()[0] to get its own IP for the callback url. This will definitely cause problems for those on a 10.XX.XX.XX network adressing. Need to fix this urgently. If anyone knows how to get domoticz' IP address then please send.
Pi3, latest beta
RFXCOM, z-wave (AEOTEC, switches, temhum, pir, contacts),
Plugwise2py, P1 'smart'meter & solar panel
Alexa, Wifi Cams motion detection
ESP: relays, PIR & Temp/TempHum
Geofence iCloud, Bluetooth & Wifi ping
Harmony hub, Nest

olafmarcos
Posts: 13
Joined: Sunday 27 December 2015 2:09
Target OS: NAS (Synology & others)
Domoticz version: 6277
Location: Santander - Spain
Contact:

Re: Python Plugin: NUKI locks

Post by olafmarcos » Tuesday 18 September 2018 16:00

Hi heggink:

First of all, thank you very much for this plugin. I come from your bash scripts.

Tested in Synology with latest Beta with Python 3.5.1 and working. At least, the device is created fine.

I'm very curious if there is a possibility to implement the unlatch function in the same device. I was thining to implement in the bash scripts, but i don't know how to implement a new "function button" in the device. I was looking a device (dummy, etc.) that was configurable the number of buttons to implement on it, but i didn't found any which make the conmbination of our needs:
  • Button to show/do the unlock/lock state.
  • ¿Button to do an unlacth action?
I'm lost how to implement due to the device options in Domoticz (implement a new button in the same device)...

Do you have any clue about it?

User avatar
heggink
Posts: 536
Joined: Tuesday 08 September 2015 21:44
Target OS: Raspberry Pi
Domoticz version: V4.9999
Location: NL
Contact:

Re: Python Plugin: NUKI locks

Post by heggink » Tuesday 18 September 2018 17:45

Hi Olaf,
It was easier with the scripts since you could just define your own device with multiple states.
When creating the python plugin, I decided to go back to teh standard lock device which only has an open and a locked state + no timer functionality (which is not nice).
I need to see if I can create a device that acts as a lock but also allows another action on it. No idea but will ask around.
H
Pi3, latest beta
RFXCOM, z-wave (AEOTEC, switches, temhum, pir, contacts),
Plugwise2py, P1 'smart'meter & solar panel
Alexa, Wifi Cams motion detection
ESP: relays, PIR & Temp/TempHum
Geofence iCloud, Bluetooth & Wifi ping
Harmony hub, Nest

olafmarcos
Posts: 13
Joined: Sunday 27 December 2015 2:09
Target OS: NAS (Synology & others)
Domoticz version: 6277
Location: Santander - Spain
Contact:

Re: Python Plugin: NUKI locks

Post by olafmarcos » Wednesday 19 September 2018 22:43

Thank you for your support.

By the way, i noticed that there are errors in the logs:
Spoiler: show
2018-09-19 22:10:58.086 (Nuki DoorLock) onHeartbeat check locks
2018-09-19 22:11:04.433 Error: (Nuki DoorLock) 'onHeartbeat' failed 'KeyError'.
2018-09-19 22:11:04.433 Error: (Nuki DoorLock) ----> Line 354 in '/usr/local/domoticz/var/plugins/domoticz-nuki-master/plugin.py', function onHeartbeat
2018-09-19 22:11:04.433 Error: (Nuki DoorLock) ----> Line 302 in '/usr/local/domoticz/var/plugins/domoticz-nuki-master/plugin.py', function onHeartbeat
I will enable Debug mode and update...

P.D.: Do you have any picture about how you power the Nuki directly??? I'm guessing how to put a cable across the door... :S

olafmarcos
Posts: 13
Joined: Sunday 27 December 2015 2:09
Target OS: NAS (Synology & others)
Domoticz version: 6277
Location: Santander - Spain
Contact:

Re: Python Plugin: NUKI locks

Post by olafmarcos » Wednesday 19 September 2018 22:54

Debug logs:
Spoiler: show
2018-09-19 22:44:32.120 Status: (Nuki DoorLock) Started.
2018-09-19 22:44:33.334 (Nuki DoorLock) Debug logging mask set to: PYTHON PLUGIN QUEUE IMAGE DEVICE CONNECTION MESSAGE ALL
2018-09-19 22:44:33.334 (Nuki DoorLock) 'Mode3':'60'
2018-09-19 22:44:33.334 (Nuki DoorLock) 'DomoticzHash':'9e8ea72-modified'
2018-09-19 22:44:33.334 (Nuki DoorLock) 'Author':'heggink'
2018-09-19 22:44:33.334 (Nuki DoorLock) 'DomoticzBuildTime':'2018-09-09 18:27:57'
2018-09-19 22:44:33.334 (Nuki DoorLock) 'Name':'Nuki DoorLock'
2018-09-19 22:44:33.334 (Nuki DoorLock) 'Mode2':'------'
2018-09-19 22:44:33.334 (Nuki DoorLock) 'Version':'1.0.0'
2018-09-19 22:44:33.334 (Nuki DoorLock) 'Mode6':'File'
2018-09-19 22:44:33.335 (Nuki DoorLock) 'DomoticzVersion':'4.9999'
2018-09-19 22:44:33.335 (Nuki DoorLock) 'HomeFolder':'/usr/local/domoticz/var/plugins/domoticz-nuki-master/'
2018-09-19 22:44:33.335 (Nuki DoorLock) 'Key':'NukiLock'
2018-09-19 22:44:33.335 (Nuki DoorLock) 'Port':'8008'
2018-09-19 22:44:33.335 (Nuki DoorLock) 'HardwareID':'6'
2018-09-19 22:44:33.335 (Nuki DoorLock) 'Mode1':'192.168.1.17'
2018-09-19 22:44:33.335 (Nuki DoorLock) Device count: 1
2018-09-19 22:44:33.335 (Nuki DoorLock) Device: 1 - ID: 144, Name: 'Nuki DoorLock - Principal Chalet', nValue: 1, sValue: 'Locked'
2018-09-19 22:44:33.335 (Nuki DoorLock) Device ID: '144'
2018-09-19 22:44:33.335 (Nuki DoorLock) Device Name: 'Nuki DoorLock - Principal Chalet'
2018-09-19 22:44:33.335 (Nuki DoorLock) Device nValue: 1
2018-09-19 22:44:33.335 (Nuki DoorLock) Device sValue: 'Locked'
2018-09-19 22:44:33.335 (Nuki DoorLock) Device LastLevel: 0
2018-09-19 22:44:33.336 (Nuki DoorLock) My IP is 192.168.1.15
2018-09-19 22:44:33.336 (Nuki DoorLock) Nuki plugin started on IP 192.168.1.15 and port 8008
2018-09-19 22:44:33.336 (Nuki DoorLock) REQUESTING http://192.168.1.17:8080/list?token=-------
2018-09-19 22:44:33.465 (Nuki DoorLock) Lock list received [{"nukiId": ---------, "name": "Principal Chalet", "lastKnownState": {"state": 1, "stateName": "locked", "batteryCritical": false, "timestamp": "2018-09-19T18:08:24+00:00"}}]
2018-09-19 22:44:33.465 (Nuki DoorLock) I count 1 locks
2018-09-19 22:44:33.466 (Nuki DoorLock) Lock Principal Chalet already exists.
2018-09-19 22:44:33.466 (Nuki DoorLock) Lock batt False
2018-09-19 22:44:33.466 (Nuki DoorLock) Lock stateName locked
2018-09-19 22:44:33.466 (Nuki DoorLock) Lock state 1
2018-09-19 22:44:33.466 (Nuki DoorLock - Principal Chalet) Updating device from 1:'Locked' to have values 1:'Locked'.
2018-09-19 22:44:33.469 (Nuki DoorLock) Lock(s) created
2018-09-19 22:44:33.469 (Nuki DoorLock) 'Mode3':'60'
2018-09-19 22:44:33.469 (Nuki DoorLock) 'DomoticzHash':'9e8ea72-modified'
2018-09-19 22:44:33.469 (Nuki DoorLock) 'Author':'heggink'
2018-09-19 22:44:33.469 (Nuki DoorLock) 'DomoticzBuildTime':'2018-09-09 18:27:57'
2018-09-19 22:44:33.469 (Nuki DoorLock) 'Name':'Nuki DoorLock'
2018-09-19 22:44:33.469 (Nuki DoorLock) 'Mode2':'------'
2018-09-19 22:44:33.469 (Nuki DoorLock) 'Version':'1.0.0'
2018-09-19 22:44:33.469 (Nuki DoorLock) 'Mode6':'File'
2018-09-19 22:44:33.469 (Nuki DoorLock) 'DomoticzVersion':'4.9999'
2018-09-19 22:44:33.470 (Nuki DoorLock) 'HomeFolder':'/usr/local/domoticz/var/plugins/domoticz-nuki-master/'
2018-09-19 22:44:33.470 (Nuki DoorLock) 'Key':'NukiLock'
2018-09-19 22:44:33.470 (Nuki DoorLock) 'Port':'8008'
2018-09-19 22:44:33.470 (Nuki DoorLock) 'HardwareID':'6'
2018-09-19 22:44:33.470 (Nuki DoorLock) 'Mode1':'192.168.1.17'
2018-09-19 22:44:33.470 (Nuki DoorLock) Device count: 1
2018-09-19 22:44:33.470 (Nuki DoorLock) Device: 1 - ID: 144, Name: 'Nuki DoorLock - Principal Chalet', nValue: 1, sValue: 'Locked'
2018-09-19 22:44:33.470 (Nuki DoorLock) Device ID: '144'
2018-09-19 22:44:33.470 (Nuki DoorLock) Device Name: 'Nuki DoorLock - Principal Chalet'
2018-09-19 22:44:33.470 (Nuki DoorLock) Device nValue: 1
2018-09-19 22:44:33.470 (Nuki DoorLock) Device sValue: 'Locked'
2018-09-19 22:44:33.470 (Nuki DoorLock) Device LastLevel: 0
2018-09-19 22:44:33.470 (Nuki DoorLock) checking callback http://192.168.1.17:8080/callback/list&token=------
2018-09-19 22:44:33.515 (Nuki DoorLock) Callback list received {"callbacks": [{"id": 0, "url": "http://192.168.1.15:8008"}]}
2018-09-19 22:44:33.515 (Nuki DoorLock) Found callbacks: 1
2018-09-19 22:44:33.515 (Nuki DoorLock) Callback already installed
2018-09-19 22:44:33.515 (Nuki DoorLock) Pushing 'ProtocolDirective' on to queue
2018-09-19 22:44:33.529 (Nuki DoorLock) Pushing 'ListenDirective' on to queue
2018-09-19 22:44:33.529 (Nuki DoorLock) Leaving on start
2018-09-19 22:44:33.530 (Nuki DoorLock) Processing 'ProtocolDirective' message
2018-09-19 22:44:33.530 (Nuki DoorLock) Protocol set to: 'HTML'.
2018-09-19 22:44:33.530 (Nuki DoorLock) Processing 'ListenDirective' message
2018-09-19 22:44:33.530 (Nuki DoorLock) Transport set to: 'TCP/IP', :8008.
2018-09-19 22:44:33.551 (Nuki DoorLock) Listen directive received, action initiated successfully.
2018-09-19 22:44:33.330 Status: (Nuki DoorLock) Entering work loop.
2018-09-19 22:44:33.330 Status: (Nuki DoorLock) Initialized version 1.0.0, author 'heggink'
2018-09-19 22:44:43.525 (Nuki DoorLock) Pushing 'onHeartbeatCallback' on to queue
2018-09-19 22:44:43.575 (Nuki DoorLock) Processing 'onHeartbeatCallback' message
2018-09-19 22:44:43.575 (Nuki DoorLock) Calling message handler 'onHeartbeat'.
2018-09-19 22:44:43.576 (Nuki DoorLock) onHeartbeat called 1
2018-09-19 22:44:53.721 (Nuki DoorLock) Pushing 'onHeartbeatCallback' on to queue
2018-09-19 22:44:53.771 (Nuki DoorLock) Processing 'onHeartbeatCallback' message
2018-09-19 22:44:53.771 (Nuki DoorLock) Calling message handler 'onHeartbeat'.
2018-09-19 22:44:53.771 (Nuki DoorLock) onHeartbeat called 2
2018-09-19 22:45:03.937 (Nuki DoorLock) Pushing 'onHeartbeatCallback' on to queue
2018-09-19 22:45:03.957 (Nuki DoorLock) Processing 'onHeartbeatCallback' message
2018-09-19 22:45:03.957 (Nuki DoorLock) Calling message handler 'onHeartbeat'.
2018-09-19 22:45:03.957 (Nuki DoorLock) onHeartbeat called 3
2018-09-19 22:45:14.132 (Nuki DoorLock) Pushing 'onHeartbeatCallback' on to queue
2018-09-19 22:45:14.152 (Nuki DoorLock) Processing 'onHeartbeatCallback' message
2018-09-19 22:45:14.152 (Nuki DoorLock) Calling message handler 'onHeartbeat'.
2018-09-19 22:45:14.153 (Nuki DoorLock) onHeartbeat called 4
2018-09-19 22:45:24.348 (Nuki DoorLock) Pushing 'onHeartbeatCallback' on to queue
2018-09-19 22:45:24.388 (Nuki DoorLock) Processing 'onHeartbeatCallback' message
2018-09-19 22:45:24.388 (Nuki DoorLock) Calling message handler 'onHeartbeat'.
2018-09-19 22:45:24.388 (Nuki DoorLock) onHeartbeat called 5
last logs repeated every 10 sec. aprox. everytime... is it normal??

User avatar
heggink
Posts: 536
Joined: Tuesday 08 September 2015 21:44
Target OS: Raspberry Pi
Domoticz version: V4.9999
Location: NL
Contact:

Re: Python Plugin: NUKI locks

Post by heggink » Wednesday 19 September 2018 22:59

Hmmm, that's weird. Can you tell me about your setup? Bridge type, #locks on the bridge? Appreciate if you can indeed turn on debug if it happens again. The returned message from the lock should be displayed right before the error. I suspect the message is a "success": false... It happens in some cases in my setup as well. Not sure why but it's no biggie unless it happens every 10 secs in which case the heartbeat is failing :-(.

In terms of the power, I used a 6V 3A power supply, bought a piece of wooden rod same diameter as a penlight, screwed the + to one side and the - to another, drilled a hole in the battery hatch and put everything together. I used a mini 6V UPS before but it struggled to provide adequate power which is a nightmare. Indeed you need to run the 6V wire through the door in some way. Luckily, the electrical cabinet is right next to my front door.
Pi3, latest beta
RFXCOM, z-wave (AEOTEC, switches, temhum, pir, contacts),
Plugwise2py, P1 'smart'meter & solar panel
Alexa, Wifi Cams motion detection
ESP: relays, PIR & Temp/TempHum
Geofence iCloud, Bluetooth & Wifi ping
Harmony hub, Nest

Post Reply

Who is online

Users browsing this forum: No registered users and 2 guests