Unoffical danalock web API

well that works perfectly - getting status, locking and unlocking!

(logs may or may not work; I may just have lost patience with waiting… the danalock backend is always painfully slow)

Not sure it’s the Danalock backend, I think the reason is that the Danalock bridge doesn’t maintain a permanent connection over Bluetooth to the lock. Having a permanent connection could have a significant impact on battery life in the lock. Anyhow, glad to hear that the latest fix seems to work.

I’m working on translating your brilliant work into python - will be easier for those (like me) with multiple locks on multiple danabridges.

I was also going to investigate whether the same access token/api can be used to access/change pin codes (i.e. set on danapads). I don’t suppose you ever looked at that at all?

Regarding multiple locks, it could be possible to extend the current solution with a simplified lock ID, eg:

GET /danalock/ < simplified lock ID eg “storage-room”> /lock

At startup, the current solution assumes it’s only one lock. It could be possible to retrieve the list of locks, and assign then an ID - could be as simple as a digit - and then map that digit to an ID that makes sense (eg “storage-room”) through configuration.

Anyone else uses multiple locks from Danalock?

the endpoints for PIN reading/changing are clearly exposed in on the danalock website, so easy to add. I’ve put some python functions together that implement your node-red flows and also can view/change/delete PINs.

1 Like

Great! work! :smiley:

Viewing your code I could easily include the PIN code stuff to the OpenAPI docs making it easier for other devs to quickly learn and understand how it works.

1 Like

excellent!

Forgot to add: I didn’t bother trying to implement the timed PIN code function, because it’s always seemed unreliable and buggy, and the API gives a better and more reliable way of achieving the same thing…

Works perfectly! Thank you so much for the work @gechu :+1:
Now I have full integration of the Danalock in Homeassistant
image

1 Like

The Node-RED implementation now supports multiple locks. A requirement is to use lock names (configured in the danalock web UI) that does not contain white spaces (" “) or hyphens (”-"). Good example is “storage_room”.

Endpoints has changed slightly - here’s the new ones:

http://node-red-host:1880/danalock/bridge/storage_room/execute/status
http://node-red-host:1880/danalock/bridge/storage_room/execute/lock
http://node-red-host:1880/danalock/bridge/storage_room/execute/unlock

http://node-red-host:1880/danalock/api/storage_room/log
http://node-red-host:1880/danalock/api/storage_room/locks

Also applied a naming conversion, and changed other stuff to make the implementation easier to understand. I might have broken something - please try it out :slight_smile:

2 Likes

For me it works perfectly with 2 locks integrated in OH3.
What I’m missing is the battery level - but that’s whining at a high level.
Thanks for your good work!

Glad to hear! :slight_smile:

BTW I’ve added support for checking battery level! Get the latest node-red flow from github and run:
GET http://node-red:1880/danalock/bridge/storage_room/execute/battery-level

EDIT: I broke the implementation during my last change. I’ve uploaded a new version that should work better

1 Like

Where can I get the Tokens?
I am trying to integrate the danalock with node red but on the credential node ask me for the acess token and the refresh token but I don´t know where I can get this.
Can anyone help me?
Thanks

Add your Danalock username and password in one of the nodes in the top left corner of the flow. These will be used to retrieve an access token, which in turn will be used in api commands against Danalock APIs

Sorry about my lack of knowledge, Eric.
I think the problem is the fact I don´t know what I need to do with the unofficial-danabridge-web-api.yaml.
To where I need to copy the yaml text that is inside this file to create the API?
I need a special node in node red to create this api?
Sorry again but if you can help me I would appreciate a lot.
I already made the HA integrations and automations.
I already have the danalock flow on the node red but I don´t know what I need to do with the API yaml text.
Thanks a lot

Hi, no worries!

That “yaml” is just a description of the API. You don’t need it to run the node-red flow.

The node-red flow listen to web requests (HTTP) and translates it to more complex requests, which it executes against Danalock APIs.

If you still can’t get it working, provide code samples of relevant home assistant configuration, automations etc

Hi Eric. Thanks for your help but I´m still stuck.
I don´t understant how to retrive the serial numbers that you explain on the instrutions.
I don´t know how and where can I get the serial number using the GET.
How I use the GET?
And where I must put this serial numbers?
Sorry to bother you.
Thanks

( How to retrieve lock status?

Calls to two different Danalock APIs, unofficial-danabridge-web-api.yaml & unofficial-danalock-web-api.yaml, are required to retrieve the lock’s status

First, retrieve bridge’s serial number using calls described in unofficial-danalock-web-api.yaml

  • Retrieve lock’s serial-number using GET /locks/v1
  • Use lock’s serial-number in GET /devices/v1/{lock-serial_number}/paired_devices to retrieve paired devices

Second, ask bridge for status using calls described in unofficial-danabridge-web-api.yaml

  • Use device’s serial_number + operation (i.e. afi.lock.get-state) in POST /bridge/v1/execute to ask the bridge to prepare a status message. This call will return an job id to be used in next request.
  • Wait about 8 seconds for the bridge to retrieve status from lock
  • Use job id from previous call to poll the bridge for the status message POST /bridge/v1/poll)

Aha! Those instructions are for building code that interact with the lock.

Try this instead:

  1. install node red.

  2. In node-red, import this flow https://raw.githubusercontent.com/gechu/unofficial-danalock-web-api/main/node-red/node-red-wrapper.json

  3. Configure the flow and start controlling the lock through HTTP requests, as described here; unofficial-danalock-web-api/node-red-wrapper.md at b30e7c79190c8e65e9f0370116ee7a32369faa7a · gechu/unofficial-danalock-web-api · GitHub

Thanks Eric, but still no sucess.
What information should I put in the credentials.
I´m sendind my configuration to you see what I have wrong.
Thanks



And this is my Home assistant configuration:

Captura de ecrã 2022-01-22, às 22.48.44

Thanks

You only need to to manually set username and password in the nodered flow. This is credentials for your Danalock account.

Login to Danalock “my pages”, and set a name for the lock according to the instructions linked in my previous post.

Last thing, change the urls to nodered to include the name of your lock.

Thank you very much Erik.
I cannot find the problem, no worries, thanks any way for all your support.
I get all the time this message em I use the HTTP Resquest ( Cannot GET /danalock/bridge/casa_peixoto/execute/status).
Cheers