Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for Danalock v3 #520

Closed
hazcod opened this issue Apr 4, 2018 · 168 comments
Closed

Add support for Danalock v3 #520

hazcod opened this issue Apr 4, 2018 · 168 comments

Comments

@hazcod
Copy link

hazcod commented Apr 4, 2018

Smart locks are the future, so let's support the Zigbee version of the Danalock v3.

https://danalock.com/danalock-v3.html

@tomac01
Copy link

tomac01 commented Jun 1, 2018

I agree!

@pascal1337
Copy link

pascal1337 commented Aug 2, 2018

Hey,

i tried to integrate my Danalock V3-Zigbee.

But the problem is, that the cluster for changing the lock state is shown as "unknown cluster". Attached you can see the information I can see.

Also I have attached to official zigbee documentation for the danalock.

Additional info: Danalock uses new ZHA V3 and is currently supported only by amazon echo plus (with zigbee)

May someone help?

Best regards
TD003 Zigbee manual.pdf

danalock_1
danalock_2

@ebaauw
Copy link
Collaborator

ebaauw commented Aug 3, 2018

You’ll need to add the 0x0101 cluster (attributes and commands) to general.xml for it to show in the deCONZ GUI. Typically this involves manually translating the text from the ZCL or ZHA specification into XML.

Next step would be figuring out how the lock responds to the various commands, how its state is reflected in the attributes, and whether it supports attribute reporting.

Then, we need to figure out what /lights and/or /sensors resources to create for the lock. This will be ugly: we cannot PUT a /sensors state, so controlling the lock will likely be through a /lights resource (cf. what we did for the siren, window covering, and vent). Additionally, there’s no config.battery for a /lights resource, so we’d need an additional /sensors resource to expose the battery level.

@pascal1337
Copy link

I'm very new to zigbee "coding". May someone is willing to help me :) I guess it would also help others AND! i think when the raspbee supports smartlocks in general it will be a great advantage for the product.

@pascal1337
Copy link

So I now added the following cluster:

<cluster id="0x0101" name="Door Lock">
	<description>Provides a mechanism for the controlling a Smart Lock.</description>
	<client>
	</client>
	<server>
		<attribute id="0x00" name="Lock state" type="u32" access="rw" required="o"></attribute>
		<attribute id="0x01" name="Lock type" type="u32" default="0x00" access="rw" required="o"></attribute>
		<attribute id="0x02" name="Actuator enabled" type="u32" default="0x00" access="rw" required="o"></attribute>
		<attribute id="0x10" name="Num lock records supported" type="u32" default="17918" access="rw" required="o"></attribute>
		<attribute id="0x11" name="Num total users Supported" type="u32" default="0" access="rw" required="o"></attribute>
		<attribute id="0x12" name="Num PIN users supported" type="u32" default="0" access="rw" required="o"></attribute>
		<attribute id="0x13" name="Num FRID users supported" type="u32" default="0" access="rw" required="o"></attribute>
		<attribute id="0x14" name="Num weekday schedules supported" type="u32" default="0" access="rw" required="o"></attribute>
		<attribute id="0x15" name="Num yearday schedules supported" type="u32" default="0" access="rw" required="o"></attribute>
		<attribute id="0x16" name="Num holiday schedules supported" type="u32" default="0" access="rw" required="o"></attribute>
		<attribute id="0x20" name="Enable logging" type="u32" default="1" access="rw" required="o"></attribute>
		<attribute id="0x34" name="Zigbee security level" type="u32" default="0" access="rw" required="o"></attribute>
		<attribute id="0x40" name="Alarm mask" type="u32" default="0xFFFF" access="rw" required="o"></attribute>
		<attribute id="0x42" name="RF operation event mask" type="u32" default="0xFFFF" access="rw" required="o"></attribute>
		<attribute id="0x43" name="Manual operation event mask" type="u32" default="0xFFFF" access="rw" required="o"></attribute>
		<attribute id="0xFFFD" name="Cluster revision" type="u32" default="0x01" access="rw" required="o"></attribute>
		<command id="0x00" dir="send" name="LockDoorResponse" required="o">
			<description></description>
			<payload></payload>
		</command>
		<command id="0x01" dir="send" name="UnlockDoorResponse" required="o">
			<description></description>
			<payload></payload>
		</command>
		<command id="0x00" dir="recv" name="LockDoor" required="o">
			<description></description>
			<payload></payload>
		</command>
		<command id="0x00" dir="recv" name="UnlockDoor" required="o">
			<description></description>
			<payload></payload>
		</command>
		<command id="0x01" dir="recv" name="GetLogRecord" required="o">
			<description></description>
			<payload></payload>
		</command>
		<command id="0x04" dir="send" name="GetLogRecordResponse" required="o">
			<description></description>
			<payload></payload>
		</command>
		<command id="0x20" dir="send" name="Operationg Event Notification" required="o">
			<description></description>
			<payload></payload>
		</command>
	</server>
</cluster>

Its adopted from danalocks zigbee documentation (mentioned above).

But with this code, every cluster in deconz is now showing as "unknown". I cannot see any syntax errors.

May someone has more know how then me? :)

Best regards

@ebaauw
Copy link
Collaborator

ebaauw commented Aug 5, 2018

If all the clusters show unknown, there’s something wrong with the general.xml. Typically a syntax error, but maybe also a logical error. The command IDs seem to have duplicates. Did you put this in the Closures domain, just before the Windows covering cluster? If you could attach the zipped general.xml, I’ll have a look.

EDIT The Danalock Zigbee manual is very brief. Looking at the ZCL spec, the attributes aren’t all uint32 nor read/write. Also, the response commands have a mandatory payload, and the set commands take the PIN as optional payload. Not sure if the Danalock supports a PIN though.

@pascal1337
Copy link

More information is not submitted by danalock ...

Attached you can find the requested zip file containing general.xml

deconz.zip

Best regards

@pascal1337
Copy link

pascal1337 commented Aug 10, 2018

Anyone already reviewed my case?

Thank you very much 😘

@pascal1337
Copy link

Okay. I just had some tries...
As I see, even if I remove my smart lock cluster from general.xml the unknown of every cluster remains.

I compared my general.xml with the "original" one, here from github.

The problem still appears. Every cluster is now unknown. Thefuck is wrong?

@ebaauw
Copy link
Collaborator

ebaauw commented Aug 10, 2018

Looks like you placed the new entries in the wrong domain.

Did you put this in the Closures domain, just before the Windows covering cluster?

@pascal1337
Copy link

Hi

Yes i did. but as i mentioned, i additionaly removed the cluster and compared it with the original. And still everything is unknown. I also let deconz reread the config

@ebaauw
Copy link
Collaborator

ebaauw commented Aug 10, 2018

I also let deconz reread the config

I never got that to work. Best quit and restart deCONZ to reload general.xml.

Could you try the general.xml from my commit mentioned above?

@pascal1337
Copy link

Dang! This works out of the box!

Now let's just make looks "apiable".

Why we don't disguise it as a switch? Like 1 is locked and 0 is unlocked.

@ebaauw
Copy link
Collaborator

ebaauw commented Aug 10, 2018

Could you please post a screenshot of the Door Lock cluster (after reading all the attributes)?

Could you check if you can setup attribute reporting for the Lock State attribute? I would hope/expect that this attribute will reflect the current lock state automatically when you issue a Lock Door or Unlock Door command, and when you control the lock manually.

@pascal1337
Copy link

pascal1337 commented Aug 10, 2018

bildschirmfoto von 2018-08-10 20-09-05
bildschirmfoto von 2018-08-10 20-09-12
Attached the screenshots.

I dont have to setup anything. The state updates out of the box, after updating.

I currently try to modify the rest api plugin source, by just "copying" the window-covering parts.

EDIT: Hmm, lock won't appear. :/

@ebaauw
Copy link
Collaborator

ebaauw commented Aug 10, 2018

I currently try to modify the rest api plugin source, by just "copying" the window-covering parts.

Indeed, best expose it as a light, with state.on mapped to the lock state. However, there's a little more to it. Change addLightNode() in de_web_plugin.cpp:

  • The vendor ID (0x115c) needs to defined and whitelisted, as it's battery operated (if (node->nodeDescriptor().manufacturerCode() == VENDOR_...)`;
  • The cluster needs to be defined and whitelisted by setting hasServerOnOff (if (i->inClusters()[c].id() == DOOR_LOCK_CLUSTER_ID);
  • The device id (0x000a) needs to be defined and whitelisted (case DEV_ID_DOOR_LOCK under case DEV_ID_HA_WINDOW_COVERING_DEVICE).

In light_node.cpp:

  • Add the vendor to setManufacturerCode();
  • Add the device id to setHAEndPoint() to set the type to "Door lock".

That should be enough for the resource to be created (I hope). Best search for DEV_ID_HA_WINDOW_COVERING_DEVICE and WINDOW_COVERING_CLUSTER_ID to make sure they're not whitelisted elsewhere.

Note to self: the device id 0x000a for Door Lock is still missing from general.xml.

Next, you need to map state.on to the Lock State attribute (so that changes to the lock state get reflected in state.on). In nodeEvent() in de_web_plugin.cpp, whitelist DOOR_LOCK_CLUSTER_ID to call updateLightNode(). In updateLightNode(), whitelist the same cluster and add a handler for ic->id() == DOOR_LOCK_CLUSTER_ID, similar to ONOFF_CLUSTER_ID, but obviously checking for attribute 0x0101/0x0000.

To control the lock from the REST API, you need to create a new routine addTaskDoorLock() in zcl_tasks.cpp, cf. the addTaskWarning() I created to control the Siren. Based on a lock state parameter, add a task with a Lock Door or Unlock Door command. In rest_lights.cpp, you need to call this routine from setLightState() under if (hasOn). You need to check for taskRef.lightNode->type() == QLatin1String("Door lock"), similar to what I've done under hasAlert for the Siren.

@tomac01
Copy link

tomac01 commented Aug 12, 2018

I currently try to modify the rest api plugin source, by just "copying" the window-covering parts.

How does it work? Where can I do this?

@ebaauw
Copy link
Collaborator

ebaauw commented Aug 12, 2018

Follow the steps in the README to get a local copy of the source of the REST API plugin and compile and install it. Then edit your local source and recompile the plugin.

@tomac01
Copy link

tomac01 commented Aug 12, 2018

Then edit your local source

I am a beginner in these things. Is it possible that you upload the changed files?
Your instructions above are certainly good, but unfortunately I can not do it without help.

Thanks in advance!!!

@pascal1337
Copy link

pascal1337 commented Aug 13, 2018

So guys. I published my plugin changes here: https://github.com/pascal1337/deconz-rest-plugin/

I did many modifications according window_covering and Warnings.

I am now at a point, where I'm not able to get further. Compilation still shows a "undeclared"-error and the API won't bring up my lock.

Maybe someone can have a closer lo(o/c)k :P

@ebaauw
Copy link
Collaborator

ebaauw commented Aug 13, 2018

VENDOR_DANALOCK should be the Manufacturer code from the Node info panel.

What is the compile error?

@tomac01
Copy link

tomac01 commented Aug 14, 2018

The following error appears:

g++ -c -pipe -Wno-attributes -Wall -Wno-attributes -O2 -std=gnu++11 -Wall -W -D_REENTRANT -fPIC -DDECONZ_DLLSPEC=Q_DECL_IMPORT -DARCH_ARM -DARCH_ARMV7 -DUSE_WEBSOCKETS -DHAS_SQLITE3 -DGW_SW_VERSION=\"2.05.34\" -DGW_API_VERSION=\"1.0.9\" -DGIT_COMMMIT=\"0e7156dc2109aabd38d10146d6e0d3393b48574a\" -DGW_AUTO_UPDATE_FW_VERSION=0x260b0500 -DGW_MIN_RPI_FW_VERSION=0x261f0500 -DGW_MIN_DERFUSB23E0X_FW_VERSION=0x22030300 -DGW_DEFAULT_NAME=\"Phoscon-GW\" -DQT_NO_DEBUG -DQT_PLUGIN -DQT_WIDGETS_LIB -DQT_GUI_LIB -DQT_SERIALPORT_LIB -DQT_WEBSOCKETS_LIB -DQT_NETWORK_LIB -DQT_CORE_LIB -I. -I../.. -I../../common -isystem /usr/include/arm-linux-gnueabihf/qt5 -isystem /usr/include/arm-linux-gnueabihf/qt5/QtWidgets -isystem /usr/include/arm-linux-gnueabihf/qt5/QtGui -isystem /usr/include/arm-linux-gnueabihf/qt5/QtSerialPort -isystem /usr/include/arm-linux-gnueabihf/qt5/QtWebSockets -isystem /usr/include/arm-linux-gnueabihf/qt5/QtNetwork -isystem /usr/include/arm-linux-gnueabihf/qt5/QtCore -Irelease -I. -I/usr/lib/arm-linux-gnueabihf/qt5/mkspecs/linux-g++ -o release/websocket_server.o websocket_server.cpp zcl_tasks.cpp: In member function ‘bool DeRestPluginPrivate::addTaskDoorLock(TaskItem&)’: zcl_tasks.cpp:922:21: error: ‘TaskDoorLock’ was not declared in this scope task.taskType = TaskDoorLock; ^~~~~~~~~~~~ zcl_tasks.cpp: In member function ‘bool DeRestPluginPrivate::addTaskDoorUnlock(TaskItem&)’: zcl_tasks.cpp:957:21: error: ‘TaskDoorUnlock’ was not declared in this scope task.taskType = TaskDoorUnlock; ^~~~~~~~~~~~~~ Makefile.Release:1037: recipe for target 'release/zcl_tasks.o' failed make[1]: *** [release/zcl_tasks.o] Error 1 make[1]: *** Waiting for unfinished jobs.... make[1]: Leaving directory '/home/pi/deconz/test/deconz-rest-plugin' Makefile:38: recipe for target 'release' failed make: *** [release] Error 2

@pascal1337
Copy link

Yes. This is the point where I currently stand.

@ebaauw
Copy link
Collaborator

ebaauw commented Aug 14, 2018

Did you declare the lock and unlock functions in de_web_plugin_private.h?

@pascal1337
Copy link

Yes I did. Row 1072, 1073

@ebaauw
Copy link
Collaborator

ebaauw commented Aug 14, 2018

You also need to declare the new tasks in

@pascal1337
Copy link

So I did some changes and compiled the plugin, copied it to /usr/share/deCONZ/plugins, rebooted and:
img_2049

When I am at home, I will test the functionality.

@pascal1337
Copy link

pascal1337 commented Aug 14, 2018

Sooo guys. When I make an API request

It shows the light correctly with all its details:

{
 "etag": "010881e2e4974327caa7b3eb871a1e34",
 "hascolor": false,
 "manufacturername": "Danalock",
 "modelid": "V3-BTZB",
 "name": "Danalock",
  "state": {
   "alert": "none",
   "on": true,
   "reachable": true
  },
"swversion": "0000000E",
"type": "Door Lock",
"uniqueid": "00:0b:57:ff:fe:59:e0:4b-01"
}

When I try to change steht state

PUT http://192.168.178.100/api/CD5466EA30/lights/7/state
{"on":true}

The response is

{
"error":{
 "address":"/lights/7",
 "description":"resource, /lights/7, not available",
 "type":3
 }
}

@J05HI
Copy link

J05HI commented Jul 18, 2020

Do we have three options?

  • Lock
  • Unlock
  • Pulling the latch

My use cases would be:

  • Locking the door if nobody is at home.
  • Unlocking the door if someone is near home.
  • Pulling the latch if I'm connecting to the WiFi.

@smulle48
Copy link
Contributor

Do we have three options?

  • Lock
  • Unlock
  • Pulling the latch

My use cases would be:

  • Locking the door if nobody is at home.
  • Unlocking the door if someone is near home.
  • Pulling the latch if I'm connecting to the WiFi.

As it's treated as a light bulb, you got on/off (lock/unlock).

That Auto Unlock, you already got in the Danalock app, including the "hold on unlock".

@J05HI
Copy link

J05HI commented Jul 18, 2020

As it's treated as a light bulb, you got on/off (lock/unlock).

That Auto Unlock, you already got in the Danalock app, including the "hold on unlock".

@smulle48
That means if you unlock through zigbee it uses the configured option set on the app?
So it's not possible to have unlock and hold on unlock separately?

@smulle48
Copy link
Contributor

As it's treated as a light bulb, you got on/off (lock/unlock).

That Auto Unlock, you already got in the Danalock app, including the "hold on unlock".

@smulle48
That means if you unlock through zigbee it uses the configured option set on the app?
So it's not possible to have unlock and hold on unlock separately?

So far, it's only possible to lock and unlock through zigbee. The rest you can do from the official Danalock app

@J05HI
Copy link

J05HI commented Jul 24, 2020

As it's treated as a light bulb, you got on/off (lock/unlock).

That Auto Unlock, you already got in the Danalock app, including the "hold on unlock".

@smulle48
That means if you unlock through zigbee it uses the configured option set on the app?
So it's not possible to have unlock and hold on unlock separately?

So far, it's only possible to lock and unlock through zigbee. The rest you can do from the official Danalock app

Okay, thank you very much!

@SwoopX
Copy link
Collaborator

SwoopX commented Jul 27, 2020

Closing this one as support has been provided with version .79.

@InToSSH
Copy link

InToSSH commented Dec 5, 2020

I just bought a Danalock V3, it came with FW v.0.16.0.
It connected to ConBee II trough Phoscon app just fine, I could control the lock from Home Assistant, but the state was not updating, I had to manually press "Read" button in Attributes for 0101 cluster to update it. Spent half a day figuring out what the problem was.. so..

If your lock state doesn't update automatically

  1. Download Danalock Toolbox app
  2. Put the lock into DFU mode (according to the manual in the app)
  3. Reflash the firmware of the lock (even if it's the same version - it was for me)
  4. Recalibrate your lock

Just like that the status began to update automatically - even when manually turned.

@smulle48
Copy link
Contributor

smulle48 commented Dec 5, 2020

I just bought a Danalock V3, it came with FW v.0.16.0.

It connected to ConBee II trough Phoscon app just fine, I could control the lock from Home Assistant, but the state was not updating, I had to manually press "Read" button in Attributes for 0101 cluster to update it. Spent half a day figuring out what the problem was.. so..

If your lock state doesn't update automatically

  1. Download Danalock Toolbox app

  2. Put the lock into DFU mode (according to the manual in the app)

  3. Reflash the firmware of the lock (even if it's the same version - it was for me)

  4. Recalibrate your lock

Just like that the status began to update automatically - even when manually turned.

You could achieve the exact same by just removing the batteries and insert them again.

That's exactly what you achieve by updating the firmware, you are rebooting the lock (it's completely cutting the power for a few seconds) after successful update

@InToSSH
Copy link

InToSSH commented Dec 6, 2020

@smulle48 oh ok, so you are saying that the bug with the state not being updated in deconz could have just been resolved by restarting the lock? I suspected it was something wrong with the FW or some zigbee params were set incorrectly.

@smulle48
Copy link
Contributor

smulle48 commented Dec 6, 2020

@smulle48 oh ok, so you are saying that the bug with the state not being updated in deconz could have just been resolved by restarting the lock? I suspected it was something wrong with the FW or some zigbee params were set incorrectly.

I suspect it's a design flaw in the hardware itself.

I've had both the zwave and now the zigbee version and they both have the same bug. And with both, after inclusion, there was no status before removing the batteries a few seconds from the lock.

@Michaelnorge
Copy link

That´s a fantastic idea. Will buy me new batteries tomorrow and try it that way, @InToSSH :-)
Maybe that makes my danalock smart as well - finally !!!!

Don´t think there will be an update from Danalock like they promissed. I saw simular locks in the web with another brand, so i guess they sold it ?!

@Michaelnorge
Copy link

I bought batteries allready today and tried to connect my Danalock, but without success :-(

@InToSSH
Copy link

InToSSH commented Dec 6, 2020

@Michaelnorge you cannot connect at all? My solution was specific to the state not being updated, otherwise I was connected and able to control the lock.

What is your procedure to connect the lock to gateway?
If no other solution works, have you tried factory resetting your lock by pressing the button on the top 10 times?

I simply paired the lock with Danalock app on my phone via bluetooth. Opened Phoscon app, add click "Add new light", they I went into the settings in Danalock app, chose Smart home, Z-wave (yes it's call Z-wave even if you have Zigbee version), and clicked Connect, then it got connected to my Conbee and appeared as new light in Phoscon app.

@smulle48
Copy link
Contributor

smulle48 commented Dec 6, 2020

I bought batteries allready today and tried to connect my Danalock, but without success :-(

Still no success getting it to work?

@Michaelnorge
Copy link

@InToSSH I tried to connect Danalock a lot of time and in a lot of different ways without any success. Even @smulle48 tried to figure out why my Danalock is not connecting to Phoscon.
The last chance is that something is wrong with my phoscon or ioBroker, but it´s a huge work to reset everything and build it up again!

I think It´s time now to give up. Will buy me a shovel and make a nice hole in my garden :-)

@Smanar
Copy link
Collaborator

Smanar commented Dec 7, 2020

Have you tried the procedure using the GUI ? with reading the basic attributes ?

@TTP1106
Copy link

TTP1106 commented Dec 7, 2020

@InToSSH I tried to connect Danalock a lot of time and in a lot of different ways without any success. Even @smulle48 tried to figure out why my Danalock is not connecting to Phoscon.
The last chance is that something is wrong with my phoscon or ioBroker, but it´s a huge work to reset everything and build it up again!

I think It´s time now to give up. Will buy me a shovel and make a nice hole in my garden :-)

Did you also try Zigbee2MQTT instead of Phoscon? :) I´m sorry but my experience showed that I can better work with that instead of phoscon

@InToSSH
Copy link

InToSSH commented Dec 7, 2020

@TTP1106 no I haven't tried that, Zigbee2MQTT docs say that support for Conbee is still experimental, so I don't know if everything is supported.
But other than that I read that in ZHA it should be working just fine.
I was thinking about trying Zigbee2MQTT after having some trouble with deconz and phoscon, but after some trial and error I learned quite a good workflow how to pair, rename and add devices to HA, so I am happy with it now and don't want to set everything up again using different software.

EDIT: sorry, just realized you weren't asking me, it just showed up with me being tagged in the message so I replied :)

@K-RAD
Copy link

K-RAD commented Dec 23, 2020

So I have no issues to lock/unlock in Home Assistant, that works great.

Is it possible to get battery status?
Also some option to disable the status when "End to end operation" is on.

@smulle48
Copy link
Contributor

So I have no issues to lock/unlock in Home Assistant, that works great.

Is it possible to get battery status?

Also some option to disable the status when "End to end operation" is on.

As it's treated as an light bulb, that's currently not possible

@K-RAD
Copy link

K-RAD commented Dec 23, 2020

So I have no issues to lock/unlock in Home Assistant, that works great.
Is it possible to get battery status?
Also some option to disable the status when "End to end operation" is on.

As it's treated as an light bulb, that's currently not possible

Unrelated question, if it's treated as a ligh bulb, why don't i get any deconz_event for it in home assistant?

@Smanar
Copy link
Collaborator

Smanar commented Dec 23, 2020

There is a sensor ZHAbattery just for it nope ?

@Michaelnorge
Copy link

@Smanar
Copy link
Collaborator

Smanar commented Mar 14, 2021

I m reading the link.
The device stop working with the API but still working using deconz ?

@Nazarbayevv
Copy link

Hello. And what about battery status? Can i check battery charge?

@Smanar
Copy link
Collaborator

Smanar commented Jun 5, 2022

On DDF version it have the state/battery #6057

@Nazarbayevv
Copy link

On DDF version it have the state/battery #6057

Thanks a lot. Do you use it? Does it stable?

@Smanar
Copy link
Collaborator

Smanar commented Jun 6, 2022

I don't use it on my side but yes, there is improvement for the device disconnection https://forum.phoscon.de/t/danalock-v3-new-fw-0-20-0-losing-connection/1838 (need firmware update)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests