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

@Joerg @alexdelprete Have you Nuki app installed (and running in the background) ?

You mean the App or the integration?

Native Nuki app (android or iOS).

Yes sure. (ok, in order to answer I have to write 10 characters)

I think the “door sensor jammed” problem could come from concurrency between Nuki app and HA “callback solution” (see my post above). If @alexdelprete does not use it that may explain why he does not have the problem. Moreover, a concurrency problem (related to the Nuki app 20" period to refresh door sensor) could explain the difficulty to find a reproducible sequence driving to the problem.

The problem is the trigger. Your templates won’t be evaluated until there is a trigger. In what your propose, you still have only the callback event, so the values will still only be calculated only when a callback arrives.
You could try the solution proposed here: Enhance Trigger-based Template Sensors
Or add a state trigger based on your sensor.nuki_door_state entity (if this is the correct entity). This latter solution will also make this trigger template updates every time your polled sensor updates
Then for your ifs, you should test on the trigger.platform / event_type, I think.

I use it all the time. The bridge should serialize the calls and queue them, I don’t think that is the problem. If they’ve done a good job on the firmware, the bridge should also have a cache for very near requests. It’s strange that I don’t see any sensor warning in my app.

What fw are you on? Bridge and Lock firmware…here are my versions:

image

Yes. I use it for notifications, etc.

So I can have more trigger types for the same sensor? that’s interesting, because if I can filter the trigger I can then use a value in case of the callback and another in case of the polling…

From the docs I didn’t notice you could have more triggers…I’ll have to read it again.

Thanks for the suggestions…if I can’t solve the puzzle I’ll write you, if you don’t mind…I’m still a beginner with HA stuff.

No problem (I’m not an expert either!)

Thank you.

Found this…good start…I have to find some concrete examples to understand better.

Maybe this is what you want:

- trigger:
    - platform: webhook
      webhook_id: !secret nuki_bridge_webhook
    - platform: event
      event_type: event_template_reloaded
    - platform: homeassistant
      event: start
  binary_sensor:
    - name: "Nuki Door State"
      unique_id: nuki_door_state
      device_class: door
      state: >
        {% if trigger.platform == 'webhook' %}
          {{ trigger.json.doorsensorState == 3 }}
        {% else %}
          {{ states('sensor.nuki_door_state') }}
        {% endif %}
  • If it is triggered by the Webhook Trigger, it evaluates the trigger variable.
  • If it is triggered by either the Event Trigger (Template Entities Reloaded) or Home Assistant Trigger (Start), it gets the sensor’s state.

Taras, you saved me hours of researching and experimenting and most of all 350 HA restarts…:smiley:

As soon as I have some time I’ll work on it and let you know if it works.

I was looking since 2 hours for these:

    - platform: homeassistant
      event: start
{% if trigger.platform == 'webhook' %}
    - platform: homeassistant
      event: start

@Friedrieck pointed me this morning to your FR and the event_template_reloaded.

Thank you, I hope I can contact you in case of problems. :slight_smile:

And to save even more time: you do not need to restart HA each time. Go in the config page, server control, you can reload there the templates entities with a single click!

1 Like

Are you joking? Why didn’t you tell me before? last night I didn’t sleep mostly waiting for HA to restart at every try. :rofl:

That’s the price you pay for inexperience I guess…

That’s why the example I posted includes the following trigger:

    - platform: event
      event_type: event_template_reloaded

It will trigger whenever you execute Configuration > Server Controls > Reload Template Entities.

1 Like

You two saved me hours of unpaid work during the night. I owe you a good italian coffee or a good glass of our wine. :slight_smile:

2 Likes

What fw are you on? Bridge and Lock firmware…

Screenshot_20210528_164248

The Nuki app says my smart lock firmware is up to date. No 2.11 proposed. Are you part of a beta program ?

I tried also 192.168.0.xxx:8080/fwupdate?token=XXXXXXXXX without any change.

I was in beta a long time ago…don’t know if that’s a beta versione of the fw. Check on their forum what’s the latest official version. I suspect they fixed some of the issues you are seeing in that version, but I’m not sure.

Going to get some rest now, tomorrow I’ll release last version of the card, it was a long day and I don’t have the energy to do it now.

Talk to you tomorrow.