Nuki Smart Lock 2.0 - support all available API actions (i.e. add lock/unlock)

Hi,

Thanks for posting this solution to the door sensor but my door sensor state just shows ‘closed’ all the time even when the door is open. I tried changing the bridge API call to /lockstate and /list but did not see any difference. I also tried the code posted by @svh1985 and got the same result.

Both the /lockstate and /list return the correct values on the web browser and so does the nuki app. Its just it doesn’t change in home assistant.

Below is the template I used:
binary_sensor:

  • platform: rest
    name: Front Door Sensor
    device_class: door
    resource: http://192.168.1.30:8080/lockstate?token=XXXXXX
    value_template: >
    {% if value_json[0].lastKnownState.doorsensorState in [ 2, 3 ] %}
    {{ value_json[0].lastKnownState.doorsensorState == 3 }}
    {% else %}
    Unknown
    {% endif %}

Can someone please help?

  • Please ignore - finally got it to work. User error
1 Like

I want to get a nuki smart lock, but have a question for the home assistant integration: Is the opener also integrated, can it fire events if someone rings at the door, and is it possible to turn off the bell from Home Assistant?

As for me the Opener does not integrate with the doorbell signal, I can only answer the first part of your question:
Yes, at least for me the Opener was recognized without any further work by the HA Nuki integration. Ring-to-open functionality is activated by service lock.unlock, door opener by lock.open.

1 Like

ah ok, I used the Nello opener till they stopped the service, and I really liked that it fired events when somebody ringed at the door, so I could notify myself for example if I have headphones on and couldn’t hear the bell. If the nuki integration would have this feature I would buy it instantly

The problem in my case is the existing doorbell setup - the Opener cannot even be wired to recognize the doorbell signal. So I cannot test this.

Nuki Opener bell ring event discussion

Documentation Bridge API

Hi,
since bridge API update last year it is possible to get the Opener bell ring event. I guess a dev could integrate in few minutes for easier nuki integration. Miss that feature too… in my understanding it is possible to register a callback url. So all we need is a webhook? as trigger in Homeassistant to fire a bell ring event???

I tried this in the meantime and it was really easy. Once you setup the callback in nuki bridge just publish a mqtt message in homeassistant and voila, perfect to use in automation as bell ring event.

Use this payload instead:
payload: ‘{{ trigger.json.ringactionState }}’
I used as topic: nuki/klingel

Only thing to do is create 2nd automation with trigger mqtt, mqtt topic nuki/klingel and True as payload

2 Likes

I would love to have this as well. Sounds really promising and awesome to connect with a video doorbell or something like that.

they are working very actively on this on GitHub. We just need to wait a bit longer.

1 Like

Hi,

i create my lock, script, sensor on my HA because with integration (need bridge on internet) my smart lock every day is offline. I have problem with my bridge(?) or smartlock(?) when is on internet. I stop internet connection bridge on router. Only LAN.

Snímka obrazovky 2021-04-08 120851

configuration.yaml

# Includes
shell_command: !include shell_commands.yaml

lock:
  - platform: template
    name: Dvere
    value_template: "{{ is_state('sensor.nuki_stav_zamku', 'locked') }}"
    lock:
      service: script.turn_on
      data:
        entity_id: script.nuki_lock
    unlock:
      service: script.turn_on
      data:
        entity_id: script.nuki_unlock

scripts.yaml

nuki_lock:
  alias: nuki-lock
  sequence:
  - data: {}
    service: shell_command.nuki_lock
nuki_unlock:
  alias: nuki-unlock
  sequence:
  - data: {}
    service: shell_command.nuki_unlock
nuki_open:
  alias: nuki-open
  sequence:
  - data: {}
    service: shell_command.nuki_open

shell_commands.yaml

  nuki_unlock: "curl -s 'IP:PORT/lockAction?nukiId=IDNUKISMARTLOCK&deviceType=0&action=1&token=TOKEN'"
  nuki_open: "curl -s 'IP:PORT/lockAction?nukiId=IDNUKISMARTLOCK&deviceType=0&action=3&token=TOKEN'"
  nuki_lock: "curl -s 'IP:PORT/lockAction?nukiId=IDNUKISMARTLOCK&deviceType=0&action=2&token=TOKEN'"

sensors.yaml

# NUKI stav zamku
  - platform: rest
    scan_interval: 13 # for constant polling to avoid draining the batteries too fast.(?)
    resource: http://IP:PORT/list?token=TOKEN # cache in bridge
    name: "NUKI stav zámku"
    value_template: "{{ value_json[0]['lastKnownState']['stateName'] }}"
    json_attributes_path: "$[0].lastKnownState"
    json_attributes:
      - batteryCritical
      - batteryChargeState
      - timestamp
      
  - platform: rest
    scan_interval: 300
    resource: http://IP:PORT/info?token=TOKEN # info devices and bridge
    name: "NUKI stav spojenia"
    value_template: "{{ value_json['scanResults'][0]['paired'] }}"
    json_attributes_path: "$.scanResults[0]"
    json_attributes:
      - rssi
      
  - platform: template
    sensors:
      nuki_stav_baterie:
        friendly_name: "NUKI stav bateriek"
        value_template: "{{ state_attr('sensor.nuki_stav_zamku', 'batteryChargeState') }}"
        unit_of_measurement: '%'
      
  - platform: template
    sensors:
      nuki_stav_rssi:
        friendly_name: "NUKI stav pripojenia"
        value_template: "{{ state_attr('sensor.nuki_stav_spojenia', 'rssi') }}"
        unit_of_measurement: 'dB'

  - platform: template
    sensors:
      last_motion_nuki_zamok:
        friendly_name: Posledná akcia
        value_template: >-
           {{ (as_timestamp(states.sensor.nuki_stav_zamku.attributes.timestamp)+11*60) | timestamp_custom("%H:%M  %d/%m") }}
           
  - platform: template
    sensors:
      nuki_stav_pripojenia:
        friendly_name: "NUKI stav siete"
        value_template: >-
          {% if is_state('sensor.nuki_stav_spojenia','False') %}
            Nepripojený
          {% elif is_state('sensor.nuki_stav_spojenia','True') %}
            Pripojený
          {% else %}
            Neznámy
          {% endif %}
        icon_template: >-
          {% if is_state('sensor.nuki_stav_spojenia','False') %}
            mdi:server-network-off
          {% elif is_state('sensor.nuki_stav_spojenia','True') %}
            mdi:server-network
          {% else %}
            mdi:wifi-strength-alert-outline
          {% endif %}

Maybe useful for someone

4 Likes

Pardon my ignorance.
I just read through the whole thread and I have one question.
Is this lock local control?
I see some posts hinting that. Or did I misunderstand something.

Yes, you configure the local bridge IP after enabling local API in bridge settings.

1 Like

Wow!
This is what I have been searching for.
I’m just a bit unsure about the door in the apartment we bought.
It looks like one of those doors you need to lift the handle to be able to lock it.

But I will remember this lock!

I read some reviews about this lock and it seems it has the same issues as Danalock.
Unlocking the door when it shouldn’t and keeping it locked when it should unlock.

But those of you who use local control with HA. What is your opinions?
Is it reliable? How does your automations work and what do they look like?

I never had any of the problems you describe?! It goes offline once in a while, but that’s all. Using it locally over Nuki bridge API.

That’s what I thought.
How does the automation look like to unlock the door as you arrive home?
Do you use bluetooth or just gps, or some mix?

I use the automatic unlock from the app, I think it works via Bluetooth. You can finetune it in the settings how you like.
I use Hass mostly to show the status and announce unlocking via Alexa (to not be surprised by someone entering the house). There is a few seconds delay of the status to hass unfortunately.
The app has a protocol of every lock/unlock/door opening which I found very useful. Never had any problems, except when I ignored the battery warning for a day and couldn’t get in anymore. this works better with the powerpack they sell now, gives you more time. Just in case, have a spare key somewhere, I would not rely on Nuki 100%, it becomes a single point of failure. 99% of the time it works eprfect.

In my experience Homeassistant and its REST API sometimes goes offline. If you install the Nuki App as a backup, that also works if HA is offline.

1 Like

Thanks. Works like charm.

No automation by HA, but we have it automatically locked by the App when my wife or me leave a defined Geofence area and unlocked when one of us steps back into the defined area.
When we’re close enough for our mobiles are being recognized by Bluetooth (~8m) it opens the door after a short delay.

Since the lock is a bit noisy I don’t want to have it locked when one of us just went out to get something from the bakery or supermarket which are just 80m away.
So far we never had any problems.

Looks good, but where do you use the door_open-Script?