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

Not depending on NUKI here, but on HA to perform an API call that already works with the bridge currently.

I have a few addresses that I can use (beyond the DHCP range that my ISP uses) but it is very limited and I have used it for a variety of network devices (2 x NAS, switchm, 3 x wireless AP, printers…) and don’t have enough for the ton of IoT stuff in my house.
So unless HA can auto discover the bridge IP addres sduring reboot using the API call that I provided, I need to manually update it each time the lease expires and a new IP is handed off through DHCP.

That sucks not having enough static leases. You could try to raise your DHCP lease time to a week? They you only deal with the issue when your router reboots and loses his DHCP lease table.

is there any tutorial on what are exactly the option for NUKI and how a have to implement it?

What do you mean - options for the Nuki integration in HA or for the API of the Nuki bridge?

Hello,

I have the Nuki bridge and want to review the status mainly.
So I would like to integrate this in HA…

BR

Hi there !

I’d be happy to help by trying using my own Nuki Opener.
It’s actually well recognised as mentioned by @Larx, but unlocking/locking feature itself seems not to work… :sweat_smile:

Let me know if you want me to try anything.

BTW, I was using Homebridge before discovering this amazing Home Assistant, and Nuki Opener was working perfectly using this plugin:
https://github.com/lukasroegner/homebridge-nuki

Did you try the service lock.open for the Nuki Opener?

For me, lock.unlock activates “ring to open”. lock.open actually activates the door opener. That fooled me in the beginning, but seems quite logical in retrospect.

However, the Opener sometimes goes offline for me in HomeAssistant, but reappears after some minutes.

You are right, it actually works ! I missed the lock.open service.
I could bring a button in lovelace, calling for this service and my opener works.
But how to bring this button through Homekit now ?
Because HomeKit just received the default lock.unlock one and that’s it…
I understand the meaning, but I don’t think this is so useful as lock.open…

OK I could finally find my own answer:

Just need to create a new lock by editing my configuration.yaml and creating a specific platform template, just after the Nuki lock configuration:

lock:
  - platform: nuki
    host: 10.0.17.5
    token: !secret nuki_token
  - platform: template
    name: Garden Gate
#    value_template: "{{ is_state('sensor.door', 'on') }}"
    value_template: "{{ true }}"
    lock:
      service: lock.open
      data:
        entity_id: lock.mygate
    unlock:
      service: lock.open
      data:
        entity_id: lock.mygate

Then, I needed to remove the default lock.unlock button to be displayed and add this new one to Homekit. The can be done by:

  • clicking into the OPTIONS button from Homekit Bridge,
  • then clicking on submit which will reveal the Select entities to be exposed menu,
  • select exclude and lock.mygate.

Easy when you know how to do, complex, when you start from nowhere…
:face_with_raised_eyebrow:

1 Like

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.