erikwihlborg76 / unofficial-danalock-web-api

9 stars 2 forks source link

Unofficial Danalock web API

This repo contains instructions for integrating the Danalock V3 Smart lock using web API requests.

Key use cases:

Table of contents:

Requirements:

Implementation option 1 - Simplified integration using a Node-RED flow

This option involves running a Node-RED flow that abstracts away the complexity of dealing with the Danalock web APIs.

IMPORTANT NOTE: The API operations exposed by the Node-RED flow are NOT secure:

  • Anyone with local network access can access the API operations exposed by the Node-RED flow (and indirectly the Danalock).
  • Data is not encrypted during transport. Instructions for securing data in transit can be found here How To Secure Nginx with Let's Encrypt on Ubuntu 22.04.

Step 1 - Set a lock name that meets the requirements

Set the lock name in the Danalock web UI.

Lock naming rules:

A good example is garden_storage.

Step 2- Install Node-RED

See Node-RED installation options.

In all subsequent examples, Node-RED is assumed to be installed in in a host named nodered, and the web UI and services are exposed from http://nodered:1880.

Step 3a - Create a file that contains your Danalock credentials

The Node-RED flow will look for Danalock credentials in a file named danalock.cfg located in the working directory of the Node-RED process. If you can´t create this file, please see option Step 3 - ALTERNATIVE below.

Examples:

Running Node-RED Path to danalock.cfg
As a user named nodered /home/nodered/danalock.cfg
As the root user in a LXC container (e.g. using Proxmox) /root/danalock.cfg
As an addon in Home-Assistant. Set up a Node-RED context store

Create a file in the working directory of your Node-RED installation named danalock.cfg that follows the structure below, and add your Danalock account credentials:

{
    "username": "username@somemail.com",
    "password": "yourpassword"
}

Step 3 - ALTERNATIVE, Set the Danalock credentials in the Node-RED flow

Set your Danalock account credentials in the node named "set credentials".

Step 4- Import and deploy the Node-RED flow

Import danalock.json to Node-RED. The flow logs events using Node-RED's standard logging capability. In some Node-RED installations the log can be viewed using the command node-red-log.

Step 5 - How to interact with the lock

In the below examples, the name of the lock is "storage_room".

Operation API request
List locks GET http://nodered:1880/danalock/locks
Get state GET http://nodered:1880/danalock/storage_room/get-state
Lock the lock GET http://nodered:1880/danalock/storage_room/lock
Unlock the lock GET http://nodered:1880/danalock/storage_room/unlock
Get battery level GET http://nodered:1880/danalock/storage_room/battery-level

Note: All operations above (except "List locks") result in a call being made to the lock. Such calls often take about 5-7 seconds to complete.

Implementation option 2 - Build from scratch

Another option is to build your Danalock API client using API calls directly to the Danalock APIs. See OpenAPI docs unofficial-danalock-web-api.yaml and unofficial-danabridge-web-api.yaml for more info.

Example: How to retrieve the lock's status

In this example, the server URLs are excluded.

First, retrieve the bridge's serial number. Requests are described in unofficial-danalock-web-api.yaml.

Second, ask the Danalock bridge for status. Requests are described in unofficial-danabridge-web-api.yaml.

Integrate Danalock with Home Assistant using standard components

Danalock can be integrated into Home Assistant using standard platform components. Instructions are provided in home-assistant\recipe-unlock-15-minutes.md.

Integrating Danalock to Home Assistant is discussed in the Unoffical danalock web API forum post.