Webhook senden, wenn es an der Tür klingelt?

Hallo,

ich bin vielleicht etwas von der Doorbird verwöhnt, aber kann man mit Niki keinen Webhook senden, wenn es an der Tür klingelt? Ich würde gerne einen Klingelton über meine Sonos Lautsprecher über Homeassistant ausgeben…

Grüße Tino

1 Like

This does work already, via the Bridge API.
Take a look at the docs: Nuki Developers (if the direct link doesn’t jump to the right section, go to: “5. Endpoints/callback”)

For the opener, the bridge will send the following data:

{
  "nukiId": 11,
  "deviceType": 2,
  "mode": 3,
  "state": 3,
  "stateName": "rto active",
  "batteryCritical": false,
  "ringactionTimestamp": "2020-04-27T16:13:00+00:00",
  "ringactionState": false
}

What you will want to use is the key ringactionState. Whenever that’s set to true, it’s indicating a doorbell ring. And cause I’m in a good mood, I’ll help you with the Home Assistant part too!

This automation will setup a webhook on home assistant and whenever a ringAction is triggered on the opener, the webhook will be called and hence this automation triggered. It then verifies, that it’s an actual doorbell ring (true state).

Then you can do whatever you like, I stop the media playback on my TVs and send a notification. :slight_smile:

alias: Nuki Opener Callback
trigger:
  - platform: webhook
    webhook_id: nuki_callback
condition:
  - condition: template
    value_template: '{{ trigger.json.ringactionState == True }}'
action:
  - service: notify.my_lg_tv
    data:
      message: Riiing riiing!
  - service: media_player.media_pause
    target:
      entity_id:
        - media_player.my_lg_tv
        - media_player.my_android_tv
mode: single

Last step is to register the webhook against the nuki bridge via the /callback/add endpoint.
I.e. call: http://your-bridge.local:8080/callback/add?url=http://homeassistant.local:8123/api/webhook/nuki_callback&token=123456

(Of course, adjust the values for your bridge and home assistant IP / DNS names as well as add the proper token for the /add call).

Hope this helps.

6 Likes

Thank you @bit !!

How could I activate this within the bridge? I tested this:

http://IP-Adress of the bridge:8080/auth and I get as response:

{“success”: false}

HTTP API is activated!

Did you provide the bridge api token via the query parameter ?token=?

I think you don’t need to call /auth anymore, as the api token is already listed in your Nuki app. Just grab the token and modify the callback add request I posted above. :slight_smile:

Thank You @bit ! But I struggle a little bit with the /callback/add. I added this URL:

http://192.168.178.xx:8080/callback/add?url=http://192.168.178.yy:8000/nuki&token=123456

I Checked it with callback/list:

{“callbacks”: [{“id”: 0, “url”: “http://192.168.178.yy:8000/nuki”}]}

But if I ring the bell, nothing happened

Please follow this format, to register the correct target for the home assistant incoming webhook part.
/api/webhook/nuki_callback is crucial for home assistant, so it can identify the incoming callback requests from the bridge.

So basically, just adjust this to the correct IP and port of your home assistant instance.


http://192.168.178.xx:8080/callback/add?url=http://192.168.178.yy:8123/api/webhook/nuki_callback&token=123456

Maybe this helps to understand the HA part: Automation Trigger - Home Assistant

1 Like

Thanks a lot! Now it’s working!

1 Like

Yay - cool! Happy to help. :slight_smile:

2 Likes

@bit thanks a lot for all the information to get this working.

It inspired me to create an automation with the Nuki Opener as a trigger to flash my LEDs and pause my TV.

Here is a Video how it looks like:

1 Like

Very cool, thanks for the credits! :grinning_face_with_smiling_eyes:

1 Like

Hallo zusammen,

kann mir vielleicht jemand weiterhelfen wieso bei mir nichts passiert wenn eigentlich 3 hue lampen blinken sollen wenn es klingelt?

alias: Nuki Hue blinken
description: ‘’
trigger:

  • platform: webhook
    webhook_id: nuki_callback
    condition:
  • condition: template
    value_template: ‘{{ trigger.json.ringactionState == True }}’
    action:
  • device_id: 72d1aee8de6d9b523215bce97aad8acf
    domain: light
    entity_id: light.vitrine
    type: flash
  • device_id: 704efe9b56347f824c77c825049f3940
    domain: light
    entity_id: light.nachttisch
    type: flash
  • device_id: 6d54cbec3cdc3ce54eeab5d274209508
    domain: light
    entity_id: light.balkon
    type: flash
    mode: single

@ronnys
This is very hard to read, could you please try again and use the “Prefomatted text” option, like this:

hello: I am some happy YAML
because:
  - I: was formatted correctly

(Basically just use three backticks ( ` ) at the beginning and end of your YAML.

Other than that, I can only ask some basic questions:

  • Are there any errors (e.g. validation errors) in Home Assistant?
  • Did you actually follow the steps and register the webhook correctly in the Nuki Bridge API?
    • You may want to check http://<your_bridge>:8080/callback/list?token=<your_token> and see if it is there
alias: Nuki Hue blinken
description: ''
trigger:
  - platform: webhook
    webhook_id: nuki_callback
condition:
  - condition: template
    value_template: '{{ trigger.json.ringactionState == True }}'
action:
  - device_id: 72d1aee8de6d9b523215bce97aad8acf
    domain: light
    entity_id: light.vitrine
    type: flash
  - device_id: 704efe9b56347f824c77c825049f3940
    domain: light
    entity_id: light.nachttisch
    type: flash
  - device_id: 6d54cbec3cdc3ce54eeab5d274209508
    domain: light
    entity_id: light.balkon
    type: flash
mode: single

i’m sorry i wasn’t aware of this option. I hope this helps?
the webhook was registered with

http://192.168.178.55:8080/callback/add?url=http://homeassistant.local:8123/api/webhook/nuki_callback&token=mytoken

and gave me this result:
“success true”

in homeassistant i can not find any errors so far

Thank you! Looks alright at first sight.

Is it actually triggering the automation in Home Assistant when the webhook is called?
You should be able to see that from the automation settings (there should be a „last triggered“ date and time).
Also, it would be interesting to dig into the tracing of your automation.

If you click on “debug automation” or “show trace”, you will see a nice graph of the flow of your automation. Would be interesting to see, what (if any) data the webhook received.

More details on this here: Troubleshooting Automations - Home Assistant

BTW, do you get the ring notifications through the Nuki App as expected?

thanks for your fast reply.

in die logs i can only find triggered actions that i’ve started from ha itself (under automations - run action)
none triggered by actually ringing my doorbell. Within the Nuki App everything works fine - i have several notifications that someone “unknown” has rang the bell. there seems no missing notification.

when i debug the automation and watch the first step i get “This node was not executed and so no further trace information is available.”

Ok, this is helpful information, we’re getting there! :smiley:

Could you maybe register an additional callback, but this time use either the IP address of home assistant or a different FQDN. I’ve heard that “homeassistant.local” might sometimes be a bit erroneous when resolving.
E.g. if you have a FRITZ!Box, you might be able to use „http://homeassistant.fritz.box:8123

Before you register this, of course please make sure that you can reach that address.

i did it and this time i used the ip adress of ha. message this time:

success false
message too many callbacks registered

You might want to remove some callbacks then? Not sure what the limit is there. Have a look at: Nuki Developers

Is your HA instance reachable through the URL you have registered the callback with? (i.e. http://homeassistant.local:8123)

so i’ve removed the old callback and added a new one (with die ip address of HA) - still nothing happens :frowning: and yes homeassistant.local is perfectly reachable in the network

but this time the logs tell me:
“Executed: 3. Juli 2022 um 18:54:00”

i recorded the lights with my smartphone while being down at the door ringing - no flashing or anything else

i just did it again after a hue bridge reset and now it works perfect! thank you very much i think the problem was indeed the homeassistant.local url instead of the ip adress