Configuration example for Nuki 3.0 Pro Lock working with the MQTT API (no bridge)

Prerequisites

  • You need to set up your MQTT broker beforehand
  • You need a username/password to allow access to the broker, modify the MQTT broker thing parameters accordingly
  • You can use a different MQTT broker name (“mosquitto” in the string “mqtt:broker:mosquitto”)
  • You need to set up your lock with the Nuki app.
  • You need to enable MQTT with the Nuki app for your lock.

Notes

  • This gives you the simple three commands in the sitemap: Unlock, Lock and Unlatch/Open. You can use the item to do what you want, if you a different solution as an interface to your lock.
  • The transform map is necessary to give the indication of the lock’s state in the sitemap. The action (command) side does not use the name numbers as the state (what is the lock actually doing).
  • This could be improved upon by using the error codes that the lock can give to display an error message.
  • You need to supply your Nuki Lock ID. The Nuki App will display it within the lock’s setting.
  • You do not need to register an account with Nuki or have some cloud thing. Everything is local!

items/mqtt.items

Number                 door_lockAction   "Door"     <keyring>              { channel = "mqtt:topic:door:lockAction"[profile="transform:MAP", function="nuki30pro.map"] }
Number                 door_battery      "Door"     <battery>  (gBattery)  { channel = "mqtt:topic:door:battery" }

sitemaps/main.sitemap

Switch      item=door_lockAction          mappings=[3="OPN",1="UNL",2="LCK"]

transform/nuki30pro.map

1=2
2=1
3=1
4=2
5=3
6=1
7=3

things/mqtt.things

Bridge mqtt:broker:mosquitto [ host="<yourMQTThostname>", secure=false, username="<yourMQTTusername>", password="<yourMQTTpassword>" ]


Thing mqtt:topic:haustuer "Door" (mqtt:broker:mosquitto) {
    Channels:
    Type number : lockAction   "Lock command"   [ commandTopic="nuki/<yourNukiLockIDhere>/lockAction" ]
    Type number : lockState    "Lock state"     [ stateTopic="nuki/<yourNukiLockIDhere>/state" ]
    Type number : battery      "Lock battery"   [ stateTopic="nuki/<yourNukiLockIDhere>/batteryChargeState" ]
}

Thx.

You can get a lot more of information from the mqtt api, for example subscribe to the lockActionEvent channel and then split the data into different items (sorry, transformation maps in German):

String Nuki_V_Action_LockAction "Lock Action [%s]" <lock> { channel="mqtt:topic:mosquitto:mynuki:lockActionEvent" } 
String Nuki_V_Action_LockAction_LockAction "Nuki Lock Action [MAP(nuki_lockaction.map):%s]"
String Nuki_V_Action_LockAction_NukiTrigger "Nuki Trigger [MAP(nuki_trigger.map):%s]"
String Nuki_V_Action_LockAction_NukiAuthID "Nuki Auth ID [MAP(nuki_authid.map):%s]"
String Nuki_V_Action_LockAction_NukiCodeID "Nuki Code ID [MAP(nuki_codeid.map):%s]"
String Nuki_V_Action_LockAction_NukiAutoUnlock "Nuki AutoUnlock [MAP(nuki_autounlock.map):%s]"
rule "Split Nuki Lock Action Events"
when
    Item Nuki_V_Action_LockAction changed
then
    val String NukiLockAction = Nuki_V_Action_LockAction.state.toString.split(",").get(0)
    val String NukiTrigger = Nuki_V_Action_LockAction.state.toString.split(",").get(1)
    val String NukiAuthID = Nuki_V_Action_LockAction.state.toString.split(",").get(2)
    val String NukiCodeID = Nuki_V_Action_LockAction.state.toString.split(",").get(3)
    val String NukiAutoUnlock = Nuki_V_Action_LockAction.state.toString.split(",").get(4)
    Nuki_V_Action_LockAction_LockAction.postUpdate(NukiLockAction)
    Nuki_V_Action_LockAction_NukiTrigger.postUpdate(NukiTrigger)
    Nuki_V_Action_LockAction_NukiAuthID.postUpdate(NukiAuthID)
    Nuki_V_Action_LockAction_NukiCodeID.postUpdate(NukiCodeID)
    Nuki_V_Action_LockAction_NukiAutoUnlock.postUpdate(NukiAutoUnlock)
end

nuki_lockaction.map:

1=aufgeschlossen
2=abgeschlossen
3=geöffnet
4=lock'n'go
5=lock'n'go mit öffnen
6=2 x abgeschlossen
80=Fernbedienung
90=Lock Button ohne weitere Aktion
NULL=unbekannt
-=unbekannt
UNDEF=unbekannt

nuki_trigger.map:

0=Bluetooth
1=reserviert
2=Lock Button
3=automatisch
6=auto lock
171=HomeKit
172=MQTT
NULL=unbekannt
-=unbekannt
UNDEF=unbekannt

nuki_authid.map:

123456789=ThisIsMe
234567890=ThisIsMyWife
0=Lock Button
NULL=unbekannt
-=unbekannt
UNDEF=unbekannt

nuki_codeid.map:

0=unbekannter Code
NULL=unbekannt
-=unbekannt
UNDEF=unbekannt

nuki_autounlock.map:

0=ohne auto-unlock
1=mit auto-unlock
2=Lock Button 2x
NULL=unbekannt
-=unbekannt
UNDEF=unbekannt

3 Likes

could you please post your .things-file configuration? I got battery-status and state written to items, but the item “Nuki_V_Action_LockAction” stays “NULL”

//working:
Number nukiFrontDoor_Lock_state   "Lock state"     ["Point"]  { channel="mqtt:topic:nukiFrontDoor:lockState" }
Number nukiFrontDoor_Lock_battery "Lock battery"   ["Point"]  { channel="mqtt:topic:nukiFrontDoor:battery" }

//stays NULL:
String Nuki_V_Action_LockAction "Lock Action" <lock> { channel="mqtt:topic:nukiFrontDoor:lockActionEvent" }

Sure, but I don’t think that will help much as your mqtt connection seems to work fine …

UID: mqtt:topic:mosquitto:nukivorne
label: MQTT Nuki Vordereingang
thingTypeUID: mqtt:topic
configuration: {}
bridgeUID: mqtt:broker:mosquitto
channels:
  - id: connected
    channelTypeUID: mqtt:switch
    label: connected
    description: ""
    configuration:
      stateTopic: nuki/ABCDEFGH/connected
      off: "false"
      on: "true"
  - id: devicetype
    channelTypeUID: mqtt:number
    label: devicetype
    description: ""
    configuration:
      stateTopic: nuki/ABCDEFGH/deviceType
  - id: name
    channelTypeUID: mqtt:string
    label: name
    description: ""
    configuration:
      stateTopic: nuki/ABCDEFGH/name
  - id: serverconnected
    channelTypeUID: mqtt:switch
    label: serverconnected
    description: ""
    configuration:
      stateTopic: nuki/ABCDEFGH/serverConnected
      off: "false"
      on: "true"
  - id: state
    channelTypeUID: mqtt:number
    label: state
    description: ""
    configuration:
      stateTopic: nuki/ABCDEFGH/state
  - id: mode
    channelTypeUID: mqtt:number
    label: mode
    description: ""
    configuration:
      stateTopic: nuki/ABCDEFGH/mode
  - id: battcritic
    channelTypeUID: mqtt:switch
    label: battcritic
    description: ""
    configuration:
      stateTopic: nuki/ABCDEFGH/batteryCritical
      off: "false"
      on: "true"
  - id: battcharge
    channelTypeUID: mqtt:number
    label: battcharge
    description: ""
    configuration:
      stateTopic: nuki/ABCDEFGH/batteryChargeState
  - id: battcharging
    channelTypeUID: mqtt:switch
    label: battcharging
    description: ""
    configuration:
      stateTopic: nuki/ABCDEFGH/batteryCharging
      off: "false"
      on: "true"
  - id: lastseen
    channelTypeUID: mqtt:datetime
    label: lastseen
    description: ""
    configuration:
      stateTopic: nuki/ABCDEFGH/timestamp
  - id: lock
    channelTypeUID: mqtt:switch
    label: lock
    description: ""
    configuration:
      commandTopic: nuki/ABCDEFGH/lock
      off: "false"
      on: "true"
  - id: unlock
    channelTypeUID: mqtt:switch
    label: unlock
    description: ""
    configuration:
      commandTopic: nuki/ABCDEFGH/unlock
      off: "false"
      on: "true"
  - id: lockaction
    channelTypeUID: mqtt:string
    label: lockaction
    description: ""
    configuration:
      commandTopic: nuki/ABCDEFGH/lockAction
  - id: firmware
    channelTypeUID: mqtt:string
    label: firmware
    description: ""
    configuration:
      stateTopic: nuki/ABCDEFGH/firmware
  - id: actionevent
    channelTypeUID: mqtt:string
    label: actionevent
    description: ""
    configuration:
      stateTopic: nuki/ABCDEFGH/lockActionEvent
  - id: doorsensor
    channelTypeUID: mqtt:number
    label: doorsensor
    description: ""
    configuration:
      stateTopic: nuki/ABCDEFGH/doorsensorState

Please be aware that I changed the Things id meanwhile (had to reset my phone …)

it did :slight_smile:
It turned out, that mqtt of the device stopped working in a strange way… Batteries out and back in and it ran smoothly.

With your thing/channel configuriation, I was able to create items via the “add points to model” function. I copied them to my .items file:

Group    nukiFrontDoor                  "Nuki Haustür"
String   nukiFrontDoor_LockActionEvent  "Nuki Lock Action Event [%s]"                       <lock>  (nukiFrontDoor)                 ["Point"]  { channel="mqtt:topic:Bridge2stueBroker:nukiFrontDoor:actionevent" } 
String   nukiFrontDoor_LockAction       "Nuki Lock Action [MAP(nuki_lockaction.map):%s]"            (nukiFrontDoor, gPersMariaCha)  ["Point"]  
String   nukiFrontDoor_Trigger          "Nuki Trigger [MAP(nuki_trigger.map):%s]"                   (nukiFrontDoor)                 ["Point"]  
String   nukiFrontDoor_AuthID           "Nuki Auth ID [MAP(nuki_authid.map):%s]"                    (nukiFrontDoor)                 ["Point"]  
String   nukiFrontDoor_CodeID           "Nuki Code ID [MAP(nuki_codeid.map):%s]"                    (nukiFrontDoor)                 ["Point"]  
String   nukiFrontDoor_AutoUnlock       "Nuki AutoUnlock [MAP(nuki_autounlock.map):%s]"             (nukiFrontDoor)                 ["Point"]  

//WebUI generated:
Switch   nukiFrontDoor_connected       "connected"         (nukiFrontDoor)                 ["Point"]  { channel="mqtt:topic:Bridge2stueBroker:nukiFrontDoor:connected" }       
Number   nukiFrontDoor_devicetype      "devicetype"        (nukiFrontDoor)                 ["Point"]  { channel="mqtt:topic:Bridge2stueBroker:nukiFrontDoor:devicetype" }      
String   nukiFrontDoor_name            "name"              (nukiFrontDoor)                 ["Point"]  { channel="mqtt:topic:Bridge2stueBroker:nukiFrontDoor:name" }            
Switch   nukiFrontDoor_serverconnected "serverconnected"   (nukiFrontDoor)                 ["Point"]  { channel="mqtt:topic:Bridge2stueBroker:nukiFrontDoor:serverconnected" } 
Number   nukiFrontDoor_state           "state"             (nukiFrontDoor, gPersMariaCha)  ["Point"]  { channel="mqtt:topic:Bridge2stueBroker:nukiFrontDoor:state" }           
Number   nukiFrontDoor_mode            "mode"              (nukiFrontDoor)                 ["Point"]  { channel="mqtt:topic:Bridge2stueBroker:nukiFrontDoor:mode" }            
Switch   nukiFrontDoor_battcritic      "battcritic"        (nukiFrontDoor)                 ["Point"]  { channel="mqtt:topic:Bridge2stueBroker:nukiFrontDoor:battcritic" }      
Number   nukiFrontDoor_battcharge      "battcharge"        (nukiFrontDoor, gPersMariaCha)  ["Point"]  { channel="mqtt:topic:Bridge2stueBroker:nukiFrontDoor:battcharge" }      
Switch   nukiFrontDoor_battcharging    "battcharging"      (nukiFrontDoor)                 ["Point"]  { channel="mqtt:topic:Bridge2stueBroker:nukiFrontDoor:battcharging" }    
DateTime nukiFrontDoor_lastseen        "lastseen"          (nukiFrontDoor, gPersMariaCha)  ["Point"]  { channel="mqtt:topic:Bridge2stueBroker:nukiFrontDoor:lastseen" }        
Switch   nukiFrontDoor_lock            "lock"              (nukiFrontDoor)                 ["Point"]  { channel="mqtt:topic:Bridge2stueBroker:nukiFrontDoor:lock" }            
Switch   nukiFrontDoor_unlock          "unlock"            (nukiFrontDoor)                 ["Point"]  { channel="mqtt:topic:Bridge2stueBroker:nukiFrontDoor:unlock" }          
String   nukiFrontDoor_lockaction      "lockaction"        (nukiFrontDoor)                 ["Point"]  { channel="mqtt:topic:Bridge2stueBroker:nukiFrontDoor:lockaction" }      
String   nukiFrontDoor_firmware        "firmware"          (nukiFrontDoor)                 ["Point"]  { channel="mqtt:topic:Bridge2stueBroker:nukiFrontDoor:firmware" }        
//String   nukiFrontDoor_actionevent     "actionevent"       ["Point"]  { channel="mqtt:topic:Bridge2stueBroker:nukiFrontDoor:actionevent" }     
//Number   nukiFrontDoor_doorsensor      "doorsensor"        (nukiFrontDoor)                 ["Point"]  { channel="mqtt:topic:Bridge2stueBroker:nukiFrontDoor:doorsensor" }  

all items have been set, and I can turn my smart-lock via webUI.
mqtt response:

Start: locked

1. ["unlock" switch set to ON in WebUI]
=
nuki/ABCDEFGH/unlock true
nuki/ABCDEFGH/state 7
nuki/ABCDEFGH/lockActionEvent 3,172,0,0,0
nuki/ABCDEFGH/timestamp 2024-01-30T19:37:50Z
...smart-lock rotates and stops...
nuki/ABCDEFGH/state 5
nuki/ABCDEFGH/timestamp 2024-01-30T19:37:56Z
nuki/ABCDEFGH/commandResponse 0
nuki/ABCDEFGH/timestamp 2024-01-30T19:37:59Z
nuki/ABCDEFGH/state 3
nuki/ABCDEFGH/timestamp 2024-01-30T19:38:01Z

2. ["unlock" switch set to OFF in WebUI]
=
nuki/ABCDEFGH/unlock false
(...no rotation on smart-lock...)

3. ["lock" switch set to ON in WebUI]
=
nuki/ABCDEFGH/lock true
nuki/ABCDEFGH/state 4
nuki/ABCDEFGH/lockActionEvent 2,172,0,0,0
nuki/ABCDEFGH/timestamp 2024-01-30T19:41:41Z
...smart-lock rotates and stops...
nuki/ABCDEFGH/commandResponse 0
nuki/ABCDEFGH/timestamp 2024-01-30T19:41:46Z
nuki/ABCDEFGH/state 1
nuki/ABCDEFGH/timestamp 2024-01-30T19:41:47Z

4. ["lock" switch set to OFF in WebUI]
=
nuki/ABCDEFGH/lock false

But now I’m struggling to implement a wife-friendly solution for the Overview-Page…

finally my questions:
How do you switch the smart-lock via openhab.

  • one switch with multiple actions?
    [“UNLOCK to ON” & “LOCK to OFF” vs. “LOCK to ON” & “UNLOCK to OFF”)

  • one item with two commandtopics?

  • …?

I followed your link to the MQTT API Spec, but couldn’t find any commandlsist or something like this.

I do everything simple and without fancy graphical stuff, I am using Sitemaps with BasicUI:

String Nuki_V_Action "Nuki Action [%s]" <lock> { channel="mqtt:topic:mosquitto:nukivorne:lockaction"}
Selection item=Nuki_V_Action  mappings=["1"="aufschliessen","2"="abschliessen","3"="Tür öffnen"]

on Android:

nuki_andro

on Windows Browser:

got it :slight_smile: thank you, for your help

for other, who may be interested: here are my steps

//1. - configure NUKI Smartlock without NUKI bridge
install and configure Smartlock
activate MQTT
lookup ID for MQTT-channel (on your mqtt broker)
→ in my case on a RasPi
mosquitto_sub -v -h localhost -p 1883 -t 'nuki/#'
initiate a publish via APP or just press the button on your smartlock
mqtt result:

nuki/12A345B5/timestamp

→ 12A345B5 is your ID

//2. - create Thing (Web-UI)
openhab → Things → + → MQTT-Binding → Generic MQTT Thing

Unique ID:		<myNUKIlock>
Identifier:     mqtt:topic:<myNUKIlock>
Label:			<myNUKIlock>
Bridge:			MQTT Connection to local MQTT Broker (has to be configured already)

…Create Thing

//3. - configure Thing - set Channels (Web-UI)
openhab → Things → myNUKIlock → Code
paste following code:

channels:
  - id: connected
    channelTypeUID: mqtt:switch
    label: connected
    description: null
    configuration:
      stateTopic: nuki/12A345B5/connected
      off: "false"
      on: "true"
  - id: devicetype
    channelTypeUID: mqtt:number
    label: devicetype
    description: null
    configuration:
      stateTopic: nuki/12A345B5/deviceType
  - id: name
    channelTypeUID: mqtt:string
    label: name
    description: null
    configuration:
      stateTopic: nuki/12A345B5/name
  - id: serverconnected
    channelTypeUID: mqtt:switch
    label: serverconnected
    description: null
    configuration:
      stateTopic: nuki/12A345B5/serverConnected
      off: "false"
      on: "true"
  - id: state
    channelTypeUID: mqtt:number
    label: state
    description: null
    configuration:
      stateTopic: nuki/12A345B5/state
  - id: mode
    channelTypeUID: mqtt:number
    label: mode
    description: null
    configuration:
      stateTopic: nuki/12A345B5/mode
  - id: battcritic
    channelTypeUID: mqtt:switch
    label: battcritic
    description: null
    configuration:
      stateTopic: nuki/12A345B5/batteryCritical
      off: "false"
      on: "true"
  - id: battcharge
    channelTypeUID: mqtt:number
    label: battcharge
    description: null
    configuration:
      stateTopic: nuki/12A345B5/batteryChargeState
  - id: battcharging
    channelTypeUID: mqtt:switch
    label: battcharging
    description: null
    configuration:
      stateTopic: nuki/12A345B5/batteryCharging
      off: "false"
      on: "true"
  - id: lastseen
    channelTypeUID: mqtt:datetime
    label: lastseen
    description: null
    configuration:
      stateTopic: nuki/12A345B5/timestamp
  - id: lock
    channelTypeUID: mqtt:switch
    label: lock
    description: null
    configuration:
      commandTopic: nuki/12A345B5/lock
      off: "false"
      on: "true"
  - id: unlock
    channelTypeUID: mqtt:switch
    label: unlock
    description: null
    configuration:
      commandTopic: nuki/12A345B5/unlock
      off: "false"
      on: "true"
  - id: lockaction
    channelTypeUID: mqtt:string
    label: lockaction
    description: null
    configuration:
      commandTopic: nuki/12A345B5/lockAction
  - id: firmware
    channelTypeUID: mqtt:string
    label: firmware
    description: null
    configuration:
      stateTopic: nuki/12A345B5/firmware
  - id: actionevent
    channelTypeUID: mqtt:string
    label: actionevent
    description: null
    configuration:
      stateTopic: nuki/12A345B5/lockActionEvent
  - id: doorsensor
    channelTypeUID: mqtt:number
    label: doorsensor
    description: null
    configuration:
      stateTopic: nuki/12A345B5/doorsensorState

replace 12A345B5 with your ID from step 1

//4. - generate items (Web-UI/VSC)
method1 (VSC):
create NUKI.items in VSC
paste following code

method2: (Web-UI)
openhab → Things → myNUKIlock → Channels → Add Points to Model → Expert Mode
paste following code

Group    <myNUKIlock>                 "<myNUKIlock>"
Switch   <myNUKIlock>_connected       "connected"         (<myNUKIlock>) ["Point"]  { channel="<mqtt:topic:yourMQTTbroker:myNUKIlockUID>:connected" }       
Number   <myNUKIlock>_devicetype      "devicetype"        (<myNUKIlock>) ["Point"]  { channel="<mqtt:topic:yourMQTTbroker:myNUKIlockUID>:devicetype" }      
String   <myNUKIlock>_name            "name"              (<myNUKIlock>) ["Point"]  { channel="<mqtt:topic:yourMQTTbroker:myNUKIlockUID>:name" }            
Switch   <myNUKIlock>_serverconnected "serverconnected"   (<myNUKIlock>) ["Point"]  { channel="<mqtt:topic:yourMQTTbroker:myNUKIlockUID>:serverconnected" } 
Number   <myNUKIlock>_state           "state"             (<myNUKIlock>) ["Point"]  { channel="<mqtt:topic:yourMQTTbroker:myNUKIlockUID>:state" ,stateDescription=" "[options="0=nicht kalibriert,1=Verriegelt,2=schließt auf,3=Entriegelt,4=schließt ab,5=Offen,6=lock'n'go,7=kann geöffnet werden,254=Motor blockiert,255=Undefiniert"]}
Number   <myNUKIlock>_mode            "mode"              (<myNUKIlock>) ["Point"]  { channel="<mqtt:topic:yourMQTTbroker:myNUKIlockUID>:mode" }            
Switch   <myNUKIlock>_battcritic      "battcritic"        (<myNUKIlock>) ["Point"]  { channel="<mqtt:topic:yourMQTTbroker:myNUKIlockUID>:battcritic" }      
Number   <myNUKIlock>_battcharge      "battcharge"        (<myNUKIlock>) ["Point"]  { channel="<mqtt:topic:yourMQTTbroker:myNUKIlockUID>:battcharge" }      
Switch   <myNUKIlock>_battcharging    "battcharging"      (<myNUKIlock>) ["Point"]  { channel="<mqtt:topic:yourMQTTbroker:myNUKIlockUID>:battcharging" }    
DateTime <myNUKIlock>_lastseen        "lastseen"          (<myNUKIlock>) ["Point"]  { channel="<mqtt:topic:yourMQTTbroker:myNUKIlockUID>:lastseen" }        
Switch   <myNUKIlock>_lock            "lock"              (<myNUKIlock>) ["Point"]  { channel="<mqtt:topic:yourMQTTbroker:myNUKIlockUID>:lock" }            
Switch   <myNUKIlock>_unlock          "unlock"            (<myNUKIlock>) ["Point"]  { channel="<mqtt:topic:yourMQTTbroker:myNUKIlockUID>:unlock" }          
String   <myNUKIlock>_lockaction      "lockaction"        (<myNUKIlock>) ["Point"]  { channel="<mqtt:topic:yourMQTTbroker:myNUKIlockUID>:lockaction" ,stateDescription=" "[options="1=aufschließen,2=abschließen,3=öffnen,4=lock'n'go,5=lock'n'go mit öffnen,6=2 x abschließen,NULL=unbekannt"]}      
String   <myNUKIlock>_firmware        "firmware"          (<myNUKIlock>) ["Point"]  { channel="<mqtt:topic:yourMQTTbroker:myNUKIlockUID>:firmware" }        
//String   <myNUKIlock>_actionevent     "actionevent"       (<myNUKIlock>) ["Point"]  { channel="<mqtt:topic:yourMQTTbroker:myNUKIlockUID>:actionevent" }     
//Number   <myNUKIlock>_doorsensor      "doorsensor"        (<myNUKIlock>) ["Point"]  { channel="<mqtt:topic:yourMQTTbroker:myNUKIlockUID>:doorsensor" }
maybe replace <myNUKIlock> with your desired Name
maybe replace <mqtt:topic:yourMQTTbroker:myNUKIlockUID> with UID/Identifier from thing created in step 2
maybe translate the German stateDescription

//5. - Button Example (Web-UI)
openhab → Pages → + → Add Label-Card

component: oh-label-card
config:
  action: options
  actionItem: <myNUKIlock>_lockaction
  item: <myNUKIlock>_state
  title: <myNUKIlock>