Nuki lock setup

Others (MiLight, Hue, Toon etc...)
dimk
Posts: 28
Joined: Sunday 17 September 2017 17:30
Target OS: -
Domoticz version:
Contact:

Re: Nuki lock setup

Post by dimk » Wednesday 20 September 2017 16:41

Hello,

the "old" script doorlock_change.sh runs now if i start the script via terminal.
I get the following return
{
"status" : "ERR"
}
In the syslog stand this
Sep 20 16:25:59 raspberrypi pi: Doorlock change Received message POST /nuki HTTP/1.0#015 User-Agent: NukiBridge_++++#015 Host: 192.168.1.4#015 Connection: Close#015 Content-Type: application/json;charset=utf-8#015 Content-Length: 81#015 #015 {"nukiId": +++++, "state": 1, "stateName": "locked", "batteryCritical": false}
Sep 20 16:25:59 raspberrypi logger: handle_doorlock_event: received {"nukiId": ++++, "state": 1, "stateName": "locked", "batteryCritical": false}
Sep 20 16:25:59 raspberrypi logger: handle_doorlock_event: got locked for ++++++
Sep 20 16:25:59 raspberrypi logger: handle_doorlock_event: setting mode to OFF for ++++++

If i change in the second script $[idx] to 887 (this is the ID in Domoticz) than this script change on or off in domoticz.
curl -s "http://192.168.1.4:8080/json.htm?type=c ... e}&svalue="

Whats wrong?
I think i am short before it works correct.

Thanks
Martin

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

Re: Nuki lock setup

Post by heggink » Wednesday 20 September 2017 16:47

The good news is that it receives message from the lock. The bad news is that domoticz complains about the device. If you only have 1 lock then fine to replace idx with your device id. It seems that ${idx} is not expanded correctly. It should say idx=887 at the beginning of that script.
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

dimk
Posts: 28
Joined: Sunday 17 September 2017 17:30
Target OS: -
Domoticz version:
Contact:

Re: Nuki lock setup

Post by dimk » Wednesday 20 September 2017 18:03

Hello,

I have 2 nuki device.
What is the best way to implement this Script to start at boot.

Do you know an workaround regarding my 2 device?

Thanks
Martin

Gesendet von meinem MHA-L29 mit Tapatalk


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

Re: Nuki lock setup

Post by heggink » Wednesday 20 September 2017 18:04

Do you have 1 or 2 bridges?
Start at boot is easiest through cron. It supports @boot at the start of the file.
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

dimk
Posts: 28
Joined: Sunday 17 September 2017 17:30
Target OS: -
Domoticz version:
Contact:

Re: Nuki lock setup

Post by dimk » Wednesday 20 September 2017 18:19

I have two Bridge and two nuki look.
How does it work with cron?

Thanks
Martin

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

Re: Nuki lock setup

Post by heggink » Wednesday 20 September 2017 18:38

Ok then the handle doorlock script should work as is as that is what I have. I'll post the cron entry when I am at my computer.
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

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

Re: Nuki lock setup

Post by heggink » Wednesday 20 September 2017 21:50

Here's the cron entry to start at boot:

@reboot /usr/local/bin/doorlock_change.sh > /tmp/doorlock_change.txt

put this at the start of the cron (crontab -e) before the entries that need to start on a timed basis.

In terms of the multiple bridges, that is the setup I have as well. Since both bridges should have a callback configured for the lock, they both send their status changes to the same ip/port (ie your domoticz system IP and port 15003 in this case). The handle_doorlock_event.sh script only needs to check which lock it is and then switch the right switch in domoticz. this is done in the case statement as follows:

Code: Select all

case "${nukiId}" in
"id of you first lock")
        idx=domoticz id of the respective decice in domoticz
       ;;

"id of the second lock")
        idx=domoticx id of the other lock device in domoticz
       ;;

esac
So you need to make sure that the idx's of your 2 domoticz devices are filled in correctly. Since you got the { "ERR" } resonse, I suspect something is not correct here since you could replace ${idx} in the curl statement with the domoticz id and it did work.

If you want, post (or pm) the script and i'll take a look.

Good news is that everything seems to be close to working.
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

dimk
Posts: 28
Joined: Sunday 17 September 2017 17:30
Target OS: -
Domoticz version:
Contact:

Re: Nuki lock setup

Post by dimk » Thursday 21 September 2017 12:10

Hello,

thanks for your greate support script 1 and 2 now works. Also start script 1 via boot works with cron.

Now i start with the 3 script. Why is this so complex?
Would it also work only with the lock command from nuki for on and off instead of your script?

Regards
Martin

Gesendet von meinem MHA-L29 mit Tapatalk


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

Re: Nuki lock setup

Post by heggink » Thursday 21 September 2017 12:18

Not sure I understand. Why so complex? Because I am not a domoticz developer and just hacked together a couple of scripts to integrate the locks. As mentioned, polling kills battery life so is not an option. The callback hook is quite nice but, with 2 locks, you run the risk of multiple messages at once hence splitting the reception and handling into 2 scripts. These are just my 2 scripts for anyone who has an interest. Feel free to change.
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

dimk
Posts: 28
Joined: Sunday 17 September 2017 17:30
Target OS: -
Domoticz version:
Contact:

Re: Nuki lock setup

Post by dimk » Thursday 21 September 2017 12:33

Sorry i do not mean script 1 and 2, i mean the script 3 where you lock and unlock the door in domoticz.

Script 3 is also for 2 nuki Switch/bridge? Because in the script there stand only 1 nuki ID but 2 token and 2 idx in the beginning of the Script.

if [ $lock = [NUKI ID of the lock] ] then idx=[domoticz idx of the lock] token=[API TOKEN] ip=[BRIDGE ip OF THE NUKI BRIDGE] else idx=[OTHER IDX OF OTHER LOCK] token=[other api token in case of another bridge] ip=[IP of the other bridge] fi

Can you help me again to become running Script 3?

Thanks
Martin

Gesendet von meinem MHA-L29 mit Tapatalk


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

Re: Nuki lock setup

Post by heggink » Thursday 21 September 2017 12:45

Ah, ok, understand now. Sure, no problem. Not at my computer until later today so will assist when I get home. Script 3 is what I use so it will work with multiple bridges. I should really clean up the scripts but I have too many other priorities. That said, script 3 operates the locks based on the nuki switches in domoticz which is different from updating domoticz based on lock actions. You could integrate in one big script but that makes it less maintainable IMO.
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

chatjozef
Posts: 14
Joined: Monday 12 September 2016 14:19
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: Nuki lock setup

Post by chatjozef » Monday 19 February 2018 9:25

First of all, excuse me for my bad English.

My situation: 2 locks, 1 bridge

After a lot of trying, I do not get this working.

I have working script 1 (version 2).
I sent it to handle_doorlock_event.sh, but it stops there.
Sending to Domoticz gives problems, when I manually enter the IDX it goes well.
When I let this through the script, I get an error, just like above.

I enter the IDX manually in the handle_doorlock_event.sh in the curl part, but it works for one lock, not for both.

Somebody might have an idea?

melsver
Posts: 1
Joined: Monday 02 April 2018 10:13
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: Nuki lock setup

Post by melsver » Monday 02 April 2018 10:29

case "${stateName}" in
"unlocked")
logger "handle_doorlock_event: setting mode to ON for ${nukiId}"
mode="1"

"locked")
logger "handle_doorlock_event: setting mode to OFF for ${nukiId}"
mode="0"


Could it be that you've mixed up the mode's in your script "handle_doorlock_event.sh" (see above)?
Should it not be:
Case Unlocked -> mode to OFF -> mode="0"
and
Case Locked -> mode ON -> mode="1"

Anyway, great scripting!!

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

Re: Nuki lock setup

Post by heggink » Tuesday 11 September 2018 12:59

I have just released a python nuki lock plugin that replaces all the scripts. Couple of comments:
  • Only tested for raspberry pi
  • A recent bug fix in domoticz requires you to be an a very recent beta as otherwise domoticz will crash.
  • it should work with multiple locks on 1 bridge but I cannot test that (I have one lock per bridge)
  • it's BETA until multiple locks on 1 bridge has been tested
  • it automatically installs the callbacks in the bridge BUT IT WON'T DELETE EXISTING so if you install on the same box where the scripts are then USE OTHER PORTS or things will get messy ;-)
  • deleting callbacks from the bridge needs to be done manually
  • the script creates LOCK devices instead of standard switches. You can still use dzvents switchOn/Off but you need to test Locked and Unlocked instead of On/Off. Also, a LOCK device does not have a timer (unfortunately) so I created a "Lock Schedule" switch manually with timers and a dzv-script in order to lock the locks at night.
I already run the plugin on my system with no scripts anymore (yes, I eat my own dog food) and they work quite nicely for now (no issues so far but let's see).

https://github.com/heggink/domoticz-nuki
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