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

Aqara relay LLKZMK11LM - Interlock mode #544

Closed
Fabiancrg opened this issue Jul 28, 2019 · 21 comments
Closed

Aqara relay LLKZMK11LM - Interlock mode #544

Fabiancrg opened this issue Jul 28, 2019 · 21 comments

Comments

@Fabiancrg
Copy link
Contributor

Hi,

Does anyone knows what is the interlock mode for the Aqara relay ?
I can see this in the App but I can't activate it, did someone manage to do it with the official Xiaomi App? What is it used for ?

Also, is there away to have the same 'decoupled' functionality with the relay, like the wall switch ?

Thank you,
Fabian

@Fabiancrg
Copy link
Contributor Author

After some tests, I was able to decouple the switch from the relays, it works the same way as the double key switch. Unfortunalety there is no endpoint for S1 and S2 so they are useless when decoupled from the relay as the status is not sent when S1 or S2 is pressed.

@zen2
Copy link
Contributor

zen2 commented Oct 2, 2019

Does anyone knows what is the interlock mode for the Aqara relay ?
I can see this in the App but I can't activate it, did someone manage to do it with the official Xiaomi App? What is it used for ?

Interlock should be an option to force to have only one relay swtched on: if one relay is switched on, the second one is switched off.
If it's really the case so it could be used to controll roller shutter :)

@zen2
Copy link
Contributor

zen2 commented Oct 2, 2019

Interlock should be an option to force to have only one relay swtched on: if one relay is switched on, the second one is switched off.

It's confirmed in this russian video (you can activate subtitle and use option/translate):
https://www.youtube.com/watch?v=omGVI5nFK04

Is this interlock function supported actually ?

@Fabiancrg
Copy link
Contributor Author

I don't think it's supported in Z2M yet, if it is it's not documented.
My goal was to activate it in the Xiaomi app and sniff the traffic to get more info.
But when I tried end of July I never succeeded to enable this intelock feature, I will retry, maybe there was a FW or SW update that fixed it.

@zen2
Copy link
Contributor

zen2 commented Oct 3, 2019

I've checked quickly shepherd code and I have found nothing about this option.
I've buy one module as a test to be used to automate a roller shutter.
This option is really important for this usage because it can avoid to switch on both switch in the same time. If both switch is on in the same time that will destroy the roller shutter motor with big risk of fire.
I thought that in last resort, this option can be implemented at software level avoiding to create a risky automation to do it.

@Fabiancrg
Copy link
Contributor Author

Yes, I know, my goal was also to use this for a roller shutter.
In my case, it won't destroy the motor but will reset; it so it will loose the top and bottom stop... not nice either.
For an unknown reason, I cannot use correctly the relay when I connect it to the Xiomi gateway, I get time outs all the time, when connected to Z2M it works without any issue.

@Koenkk
Copy link
Owner

Koenkk commented Oct 3, 2019

If somebody manages to sniff the packets send when configuring this option via the Xiaomi gateway we could support this. (https://www.zigbee2mqtt.io/how_tos/how_to_sniff_zigbee_traffic.html)

@Fabiancrg
Copy link
Contributor Author

Fabiancrg commented Nov 17, 2019

@Koenkk After fixing the issue with my Xiomi GW, I was able to get the trace when enabling and disabling the interlock mode, here is the result:
Enabling it gives:

No.     Time           Source                Destination           Protocol Length Info
    108 134.067464     0x0000                0xed08                ZigBee HA 54     ZCL: Write Attributes, Seq: 75

Frame 108: 54 bytes on wire (432 bits), 54 bytes captured (432 bits) on interface 0
IEEE 802.15.4 Data, Dst: 0xed08, Src: 0x0000
ZigBee Network Layer Data, Dst: 0xed08, Src: 0x0000
ZigBee Application Support Layer Data, Dst Endpt: 1, Src Endpt: 1
ZigBee Cluster Library Frame, Mfr: Unknown (0x115f), Command: Write Attributes, Seq: 75
    Frame Control Field: Profile-wide (0x14)
        .... ..00 = Frame Type: Profile-wide (0x0)
        .... .1.. = Manufacturer Specific: True
        .... 0... = Direction: Client to Server
        ...1 .... = Disable Default Response: True
    Manufacturer Code: Unknown (0x115f)
    Sequence Number: 75
    Command: Write Attributes (0x02)
    Attribute Field, Boolean: 0x01
        Attribute: 0xff06
        Data Type: Boolean (0x10)
        0000 0001 = Boolean: True

when disabling it I get this:

No.     Time           Source                Destination           Protocol Length Info
    154 179.949980     0x0000                0xed08                ZigBee HA 54     ZCL: Write Attributes, Seq: 82

Frame 154: 54 bytes on wire (432 bits), 54 bytes captured (432 bits) on interface 0
IEEE 802.15.4 Data, Dst: 0xed08, Src: 0x0000
ZigBee Network Layer Data, Dst: 0xed08, Src: 0x0000
ZigBee Application Support Layer Data, Dst Endpt: 1, Src Endpt: 1
ZigBee Cluster Library Frame, Mfr: Unknown (0x115f), Command: Write Attributes, Seq: 82
    Frame Control Field: Profile-wide (0x14)
        .... ..00 = Frame Type: Profile-wide (0x0)
        .... .1.. = Manufacturer Specific: True
        .... 0... = Direction: Client to Server
        ...1 .... = Disable Default Response: True
    Manufacturer Code: Unknown (0x115f)
    Sequence Number: 82
    Command: Write Attributes (0x02)
    Attribute Field, Boolean: 0x00
        Attribute: 0xff06
        Data Type: Boolean (0x10)
        0000 0000 = Boolean: False

I tried to add the missing piece in toZigbee.js but I do not really understand how this works. Do you have some docs on how to add things like the interlock mode, I tried this (inspired from other piece of code but did not work)

    LLKZMK11LM_interlock: {
        key: ['interlock'],
        convertSet: async (entity, key, value, meta) => {
            const lookup = {
                'on': 0x01,
                'off': 0x00,
            };

            if (lookup.hasOwnProperty(value)) {
                await entity.write('genBasic', {0xff06: {value: lookup[value], type: 0x10}}, options.xiaomi);
            }

            return {state: {interlock: value}};
        },
    },

with

    {
        zigbeeModel: ['lumi.relay.c2acn01'],
        model: 'LLKZMK11LM',
        vendor: 'Xiaomi',
        description: 'Aqara wireless relay controller',
        supports: 'on/off, power measurement',
        fromZigbee: [
            fz.QBKG03LM_QBKG12LM_LLKZMK11LM_state, fz.QBKG12LM_LLKZMK11LM_power, fz.xiaomi_power,
            fz.ignore_multistate_report,
        ],
        toZigbee: [tz.on_off,tz.LLKZMK11LM_interlock],
        endpoint: (device) => {
            return {'l1': 1, 'l2': 2};
        },
    },

@Koenkk
Copy link
Owner

Koenkk commented Nov 18, 2019

The code you provided looks good to me, however one thing I cannot check if the cluster is correct. That is shown under ZigBee Application Support Layer Data, Dst Endpt: 1, Src Endpt: 1 but this is hidden in your post.

@Fabiancrg
Copy link
Contributor Author

@Koenkk I pasted the full frame here https://pastebin.com/8uPq9Y65
Based on this I updated the toZigbee.js with this:

    LLKZMK11LM_interlock: {
        key: ['interlock'],
        convertSet: async (entity, key, value, meta) => {
            const lookup = {
                'on': 0x01,
                'off': 0x00,
            };

            if (lookup.hasOwnProperty(value)) {
                await entity.write('genBasic', {0x0010: {value: lookup[value], type: 0x10}}, options.xiaomi);
            }

            return {state: {interlock: value}};
        },
    },

I restarted Z2M after this change but it's not working; I ran the sniffer, I suppose I should see the same frame but nothing.

I there something else to update ? I changed only devices.js and toZigbee.js.

@Koenkk
Copy link
Owner

Koenkk commented Nov 19, 2019

After adding the code, did you send to zigbee2mqtt/[FRIENDLY_NAME]/set payload: {"interlock": "on"}? That should trigger the message.

@Fabiancrg
Copy link
Contributor Author

@Koenkk Yes, I used this MQTT message.
I've just retried and was able to capture the trace and two differences in ZigBee Application Support Layer Data between packet capture when using the Xiaomi GW and the Z2M GW:

On Xiaomi I have this:

ZigBee Application Support Layer Data, Dst Endpt: 1, Src Endpt: 1
    Frame Control Field: Data (0x40)
        .... ..00 = Frame Type: Data (0x0)
        .... 00.. = Delivery Mode: Unicast (0x0)
        ..0. .... = Security: False
        .1.. .... = Acknowledgement Request: True
        0... .... = Extended Header: False
    Destination Endpoint: 1
    Cluster: Binary Output (Basic) (0x0010)
    Profile: Home Automation (0x0104)
    Source Endpoint: 1
    Counter: 115

on Z2M packet I have this

ZigBee Application Support Layer Data, Dst Endpt: 1, Src Endpt: 1
    Frame Control Field: Data (0x00)
        .... ..00 = Frame Type: Data (0x0)
        .... 00.. = Delivery Mode: Unicast (0x0)
        ..0. .... = Security: False
        .0.. .... = Acknowledgement Request: False
        0... .... = Extended Header: False
    Destination Endpoint: 1
    Cluster: Basic (0x0000)
    Profile: Home Automation (0x0104)
    Source Endpoint: 1
    Counter: 214

So I suppose this is coming from this part of the code but I don't know what to change:

await entity.write('genBasic', {0x0010: {value: lookup[value], type: 0x10}}, options.xiaomi);

@Koenkk
Copy link
Owner

Koenkk commented Nov 19, 2019

The used cluster is wrong, you should use genBinaryOutput instead of genBasic in the write.

@Fabiancrg
Copy link
Contributor Author

Fabiancrg commented Nov 19, 2019

@Koenkk It's working now but I had to change the first number in bracket as it was not the correct attribute

so now, I have this code I tested and it's working as expected:

    LLKZMK11LM_interlock: {
        key: ['interlock'],
        convertSet: async (entity, key, value, meta) => {
            const lookup = {
                'on': 0x01,
                'off': 0x00,
            };

            if (lookup.hasOwnProperty(value)) {
                await entity.write('genBinaryOutput', {0xff06: {value: lookup[value], type: 0x10}}, options.xiaomi);
            }

            return {state: {interlock: value}};
        },
    },

So now, with Interlock = ON, if we start with L1=ON and L2=OFF and set L2=ON, L1 is automatically set to OFF and status of each relay is updated in Z2M.

In the log I have this:

Nov 19 10:48:58 NUC npm[25976]: zigbee2mqtt:info  2019-11-19T09:48:58: MQTT publish: topic 'zigbee2mqtt/Aqara_Relay', payload '{"state_l1":"ON","linkquality":94,"state_l2":"OFF","power":4.1,"consumption":0,"temperature":0,"interlock":"on"}'
Nov 19 10:49:38 NUC npm[25976]: zigbee2mqtt:info  2019-11-19T09:49:38: MQTT publish: topic 'zigbee2mqtt/Aqara_Relay', payload '{"state_l1":"ON","linkquality":94,"state_l2":"ON","power":4.1,"consumption":0,"temperature":0,"interlock":"on"}'
Nov 19 10:49:38 NUC npm[25976]: zigbee2mqtt:info  2019-11-19T09:49:38: MQTT publish: topic 'zigbee2mqtt/Aqara_Relay', payload '{"state_l1":"OFF","linkquality":70,"state_l2":"ON","power":4.1,"consumption":0,"temperature":0,"interlock":"on"}'

If this is OK for you I will introduce a PR to update device.js, toZigbee.js and the doc too.
Thank you for your help

@Koenkk
Copy link
Owner

Koenkk commented Nov 19, 2019

Yes please make a pr for the docs and converters. One thing I propose to change that instead of on off use true false, then you could publish {"interlock": true}, code:

LLKZMK11LM_interlock: {
	key: ['interlock'],
	convertSet: async (entity, key, value, meta) => {
		await entity.write('genBinaryOutput', {0xff06: {value: value ? 0x01 : 0x00, type: 0x10}}, options.xiaomi);
		return {state: {interlock: value}};
	},
},

@Fabiancrg
Copy link
Contributor Author

I updated the code with this and tested it again, everything is woking fine so will introduce the PR.

Thank you !

@Fabiancrg
Copy link
Contributor Author

@Koenkk I don't see where I can update the device page for the LLKZM11LM relay.
What do I have to do for this ?

Koenkk added a commit to Koenkk/zigbee2mqtt.io that referenced this issue Nov 19, 2019
@Koenkk
Copy link
Owner

Koenkk commented Nov 19, 2019

I've added the documentation, thanks!

@deiger
Copy link
Contributor

deiger commented Dec 23, 2020

Hey @Fabiancrg,
Do you know if there is a similar attribute for changing the relay from toggle to momentary (push button)? According to this it seems to be possible.
Thanks!

@bstaeheli
Copy link
Contributor

Hey @Fabiancrg,
Do you know if there is a similar attribute for changing the relay from toggle to momentary (push button)? According to this it seems to be possible.
Thanks!

that would be great for me also

@dj9p
Copy link

dj9p commented Mar 26, 2021

Hello, sorry I am new to home assistant and I am looking to set up this interlock function on ZHA for my aqara relay. Can you please detail me the setting up of this function? Thanks in advance!

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

No branches or pull requests

6 participants