How to get activity log from Nuki 3.0 Pro connected via MQTT?

I would like to know in HA who unlocked the door. That way I can notify myself when someone unexpected unlocks the door. For example “the code for the cleaning lady was used on an unexpected day”.

I can see this info in Nuki app Activity Lock, but it’s nowhere to be seen in HA.

This is the event I see, but it doesn’t contain info about who did the action:

vent_type: state_changed
data:
  entity_id: lock.nuki_door_lock
  old_state:
    entity_id: lock.nuki_door_lock
    state: locked
    attributes:
      friendly_name: Nuki door lock
      supported_features: 1
    last_changed: "2023-08-24T12:15:26.278244+00:00"
    last_updated: "2023-08-24T12:15:26.278244+00:00"
    context:
      id: 01H8KQH326ESACD24EWJEE741W
      parent_id: null
      user_id: null
  new_state:
    entity_id: lock.nuki_door_lock
    state: unlocking
    attributes:
      friendly_name: Nuki door lock
      supported_features: 1
    last_changed: "2023-08-24T12:34:03.127050+00:00"
    last_updated: "2023-08-24T12:34:03.127050+00:00"
    context:
      id: 01H8KRK5QQYJN2EVNZPYB8RF1P
      parent_id: null
      user_id: null
origin: LOCAL
time_fired: "2023-08-24T12:34:03.127050+00:00"
context:
  id: 01H8KRK5QQYJN2EVNZPYB8RF1P
  parent_id: null
  user_id: null

Any way to get that info in HA or it’s a problem of Nuki not sending it over via MQTT?

Did you get an answer or a solution? I have the same need… i want to know who locked/unlocked the nuki lock.

Nope, didn’t solve it.

It’s not published in the HomeAssistant auto discovery topics.
you have to listen to nuki/your-id/lockActionEvent on the MQTT broker.

The docs that can be found here describe how to the payload for these messages is structured:

Depending on whether you want so listen for fob / keypad / smartphone / auto-unlock you have to build yourself some logic that identifies the user and then fire a notifcation or write it to an entity.

Hi everyone,
I am trying to get this done and have this now, which seems to work providing the required info:

- sensor:
    state_topic: "nuki/ID_of_the_lock/lockActionEvent"
    value_template:  "{{ value | regex_findall_index('\\d,\\d,\\d{6},\\d{4},(.*)') }}"
    name: "Letzter Haustürschloss Benutzer"
    icon: mdi:account-lock
    unique_id: sensor_letzter_hausturschloss_benutzer

The topic above provides this:
n,n,nnnnnn,nnnn,x
Whereas n is an numeric value and x the index of the user entry (first user in the NUKI App = 1, second = 2, …)

Now I would like to translate this to a String (Name) and tried:

value_template: "{% if value == 'n,n,nnnnnn,nnnn,x' %} 'Arnold' {% else if value == 'n,n,nnnnnn,nnnn,y' %} 'Predator'
    {% else if value == 'n,n,nnnnnn,nnnn,z' %} 'Terminator' {% else %} 'John_McLane' {% endif %}"

To be continued…
(Any hint would be greatly appreciated)

EDIT:
I have a working setup - although there are possibly neater ways to implement this:

- sensor:
    state_topic: "nuki/ID_of_the_lock/lockActionEvent"
    value_template:  "{{ value | regex_replace(find='\\d,\\d,\\d{6},\\d{4},2', replace='Arnold') | regex_replace(find='\\d,\\d,\\d{6},\\d{4},3', replace='Predator') | regex_replace(find='\\d,\\d,\\d{6},\\d{4},4', replace='John_McLane') | regex_replace(find='\\d,\\d,\\d{6},\\d{4},1', replace='Terminator')
    | regex_replace(find='2,172,0,0,0', replace='MQTT zu') | regex_replace(find='1,172,0,0,0', replace='MQTT auf') }}"
    name: "Letzter Haustürschloss Benutzer"
    icon: mdi:account-lock
    unique_id: sensor_letzter_hausturschloss_benutzer

@jakub just FYI

1 Like