Nuki Card with Callback support (supports both Lock & Opener, it replaces the official integration)

I think the automation isn’t triggered when I ring. When I execute the automation / action manually, it unlatches the door.

Take a look in HA->Settings->Automation, there you can see when it was last executed.

(Sorry, mine is in german). If it doesn’t start when you ring, delete (or comment out with #, only for the debug purpose) all of the conditions so there is only the trigger and the action. Try it, does it trigger now?

In the automation list, if you click on the circled “I” you can see when it has been triggered.

image image

If you click on the second icon, you can DEBUG/TRACE the automation to see what has done step by step in last run.

Don’t worry, I’m German aswell! :wink: For testing purposes I reverted back to not using the numeric values of sensor.nuki_opener_state:

alias: Wohnungstür öffnen, wenn zuhause und rto active und jemand klingelt
description: ''
trigger:
  - platform: state
    entity_id: sensor.nuki_opener_state
    to: online
    for:
      hours: 0
      minutes: 0
      seconds: 1
      milliseconds: 0
condition:
  - condition: and
    conditions:
      - condition: state
        entity_id: group.awesome_people
        state: home
      - condition: state
        entity_id: binary_sensor.nuki_opener_ring_action_state
        state: 'on'
action:
  - service: rest_command.nuki_lock_action
    data:
      nuki_id: 123456789
      dev_type: 0
      action: 3
mode: single

This time the automation fired! Although it unlatched twice. I don’t know why attribute: opener_state_id did not work for me.

My god, I’m surrounded by too many Germans here. :smiley:
Glad to have a lot of you guys testing things etc., you’ve contributed a lot to have a working version.

Strange. Can you click on “Nuki Opener State” in Nuki Card, it should show this window, expand the attributes list and show me the screenshot of that please. Thanks.

image

There you go!

image

So Opener State ID is 1, it’s correct, and I’m not surprised, because Opener State is just the label of that number, the real sensor is Opener State ID.

Can you try quoting 1 in the trigger, and also the seconds? Like this:

  trigger:
    - platform: state
      entity_id: sensor.nuki_opener_state
      attribute: opener_state_id
      to: "1"
      for:
        seconds: "3"

If you could also test this, it would be great. :wink:

  trigger:
    - platform: template
      value_template: "{{ is_state_attr('sensor.nuki_opener_state', 'opener_state_id', 1) }}"
      for:
        seconds: 3

This one is working aswell! :slight_smile: Though also unlatching twice. Anyway to unlatch only once?

The rest_command should be executed once. If it’s executed twice it means the automation is being triggered twice.

@Ey3scr34m @madface probably the fact that it unlatches two times is due to the fact that the Opener transitions to state_id 1 after the ring, then the unlatch rest_command is executed and it transitions to 7 (opening) and 5 (open) and then to 1 again, so it triggers again. :slight_smile:

I don’t have the opener connected, this is only speculation, you guys need to confirm this.

If you want to confirm this open this window on the mobile phone, values will change in real-time, so you will see the transition of state_id while ringing/unlatching/etc.

image

Today was first time use in real life for me, coming home after work. Works (and unlatches only one time for me), but when the external gate buzzers (opens) to the moment the house door opens it’s 8 to 10 seconds. This is not a problem of the automation, it takes about 3 seconds from buzzing the gate until the ringstate comes to ha and opening the door takes another x seconds. Since i have only 2 meters from gate to door it’s a little bit slow.
I am thinking of a way without rto and doing it completely with ha with 2 restful calls (one for the nuki and one for the opener). If i have i will post it here.
But @alexdelprete thank you very much, it’s really fine and working really good now.

We configured 3 seconds for the holding state, maybe you can optimize it a little bit.

That’s the physical time to turn the key. Can’t do much for that, you can configure Nuki to not do all the turns, you know that? I use it to speed up the process and save battery.

2 meters? Basically it’s like having 2 doors. :smiley:

Mike, thanks for your kind words, I appreciate it. Spent many nights trying to make everything work, and words of appreciations are always welcome, also because I didn’t even use the opener, had to really implement it blindly, but I knew I had good testers. :wink:

You know why I’m so proud of Nuki Card? Because it’s basically a monster automation, I only used standard HA functionalities, no python. It’s incredible how powerful HA has become. I’m still surprised some times that I managed to achieve this. :slight_smile:

Thanks again.

Alessandro

I now also have a double unlatch. Seems the state of the opener switches a short second again to online while opening and then after the process again.
The second problem (i wrote above) was the reaction time. First i planned to use it without the rto feature and to do all with HA, but what i forgot is that the doorbell would ring :roll_eyes:
So now my approach which in tests worked really fine:

- id: "nuki_rto_unlock_smartlock"
  alias: "Nuki RTO Unlock SmartLock "
  mode: single
  max_exceeded: silent
  trigger:
    - platform: state
      entity_id: sensor.nuki_opener_state
      attribute: opener_state_id
      from: 3
      to: 7
  condition:
    - condition: and
      conditions:
        - condition: state
          entity_id: person.katja
          state: 'home'
        - condition: or
          conditions: 
            - condition: state
              entity_id: person.mad
              state: 'home'
            - condition: state
              entity_id: person.mad
              state: 'BigHome'   
  action:
    - service: rest_command.nuki_lock_action
      data:
        nuki_id: "471234567"
        dev_type: 0
        action: 3
    - service: notify.pushover_notify
      data:
        message: "Tür wird geöffnet"
        title: NUKI door open
        data:
          sound: haustuer
    - delay: '00:00:30'

The action is called in the moment the opener buzzers the external gate and does not wait until the state of the opener goes back to online. From 3 to 7 means it goes from rto to opening and somebody must have rang the bell.
Mode single and the delay at the end prevents from double unlatch.
I tested 4 times, three of them the house door opened in the moment the external gate buzzed, one time it took about 3 seconds for the house door, but for me thats ok.

1 Like

That’s what I suspected when I wrote the post above thinking about the double unlatch.

Excellent idea: opening means that rto has been executed, so also the rest_command can be executed.

Well done Mike. :slight_smile:

@madface I think this is more consistent, regarding the states to check, Nuki Opener goes in “opening” (that means RTO was active and someone rang) and with the first condition, you also make sure someone actually rang. You could also skip checking the ring_action_state, but I left it just for sake of completeness.

It’s the same code I published before, but with a 7 instead of 1. :slight_smile:

- id: "nuki_rto_unlock_smartlock"
  alias: "Nuki RTO Unlock SmartLock "
  trigger:
    - platform: template
      value_template: "{{ is_state_attr('sensor.nuki_opener_state', 'opener_state_id', 7) }}"
  condition:
    - condition: and
      conditions:
        - condition: state
          entity_id: binary_sensor.nuki_opener_ring_action_state
          state: "on"
        - condition: state
          entity_id: group.awesome_people
          state: home
  action:
    - service: rest_command.nuki_lock_action
      data:
        nuki_id: "123456AB89"
        dev_type: 0
        action: 3
1 Like

Did not try it, but i think with the ring_action_state condition it will not fire. The ringaction is submitted at last of the opening sequence (why this is so only the nuki devs know, i think it should be on in every callback of the opening sequence). So when the opener_state goes to 7 the ringaction is still off.
But without the ring_action_state condition it is really fast for me, just returned from the bakery and the house door opened in the moment the external gate buzzed and opened. Perfect :+1:
@alexdelprete i would add the delay at the end (and maybe the single mode + silent option so it would not throw a warning) so the automation can fire only once in 30 seconds. Since the ringaction state is on for 30 seconds there is no disadvantage but it preserves from a double execution and a double unlatch.

1 Like

I just implemented this without the ring action state condition and it’s working really well so far. Thanks a lot to both of you Alex and @madface! :slight_smile:

Edit: Now I tried it again and it somehow did not work… Strange :thinking: The automation did not trigger at all, so the jump to 7 was not registered I guess.

I just started using your Nuki card but it doesn’t seem to work. It doesn’t see the changes for example when I open the door or lock the door with the app. I can’t lock/unlock the door with the card. The only thing it does is unlock the door if it’s already locked with the app. It even unlocks even though I click on lock :sweat_smile:
Can anybody help me out here?

Really? So you’re saying that I ring the bell, and the opener first does all its actions and only in the end it sets ring_action_state to true? I need to talk to Nuki devs…serously…:rofl: :rofl: