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 Xiaomi Aqara D1 switch QBKG26LM decoupled mode #1986

Closed
chankalson opened this issue Dec 28, 2020 · 81 comments
Closed

Add Xiaomi Aqara D1 switch QBKG26LM decoupled mode #1986

chankalson opened this issue Dec 28, 2020 · 81 comments

Comments

@chankalson
Copy link

The Aqara D1 switch QBKG26LM is a 3-gang switch (with Neutral wire), however decoupled mode is not available even though the same 3-gang QBKG25LM (no neutral) has it.

ERROR: No converter available for 'operation_mode' ([object Object])

@Koenkk
Copy link
Owner

Koenkk commented Dec 28, 2020

First step would be to sniff the traffic with the original xiaomi gateway to figure out what to send. https://www.zigbee2mqtt.io/how_tos/how_to_sniff_zigbee_traffic.html .

Next add tz.xiaomi_switch_operation_mode to the toZigbee array of the QBKG26LM in devices.js and modify

} else if (meta.mapped.model === 'QBKG25LM') {
accordingly (to what you sniffed)

@chankalson
Copy link
Author

Thanks for the response.

I'm using the Zigbee2mqtt add-on in Home Assistant. May I know where is the toZigbee.js file located?

Thanks again.

@Koenkk
Copy link
Owner

Koenkk commented Dec 28, 2020

For the addon it's a bit more complicated. SSH into the machine, figure out the container ID with docker ps -a, ssh into with docker exec -it [CONTAINER_ID] sh. The toZigbee.js should be under node_modules/zigbee-herdsman-converters/converters/toZigbee.js.

@chankalson
Copy link
Author

chankalson commented Jan 5, 2021

Hi @Koenkk , Happy New Year to you!

I've captured the traffic from the QBKG26LM to Xiaomi Gateway.
QBKG26LM.zip

I pressed each button on the QBKG26LM twice, thus turning it ON->OFF starting from left to right. After that I turned on the Wireless Switch function for all 3 buttons from the Mi Home app, and pressed each button once, from left to right.

May I know what do I need to modify in devices.js and toZigbee.js?

Thanks a lot for your help.

@Koenkk
Copy link
Owner

Koenkk commented Jan 5, 2021

@chankalson I need a sniff off setting the decoupled mode from the Xiaomi gateway (keep the sniff as short as possible, so start sniffing right before you change the decoupled mode). Also share your network key

@chankalson
Copy link
Author

chankalson commented Jan 5, 2021

@Koenkk, here's the new sniff file
QBKG26LM Decoupled.zip

I've set decoupled mode for the 3 buttons. My network encryption key is 404546133c11a2bff89dbe2b74e99a57.

Thanks again! Let me know if you need anything else. Appreciate all the help.

@Koenkk
Copy link
Owner

Koenkk commented Jan 5, 2021

Added. docs: https://www.zigbee2mqtt.io/devices/QBKG25LM.html#decoupled-mode (use the one of QBKG25LM).

Changes will be available in the latest dev branch in a few hours (https://www.zigbee2mqtt.io/how_tos/how-to-switch-to-dev-branch.html)

@chankalson
Copy link
Author

chankalson commented Jan 6, 2021

Hi @Koenkk, the decoupled mode works (the button does not control the relay). However, there isn’t any action value/property for the switch. I tried adding the exposes for e.action in devices.js (following QBKG25LM) and the action property shows up, but when i press the button nothing is received by zigbee2mqtt. Is there anything else i need to modify?

@Koenkk
Copy link
Owner

Koenkk commented Jan 6, 2021

Did some more fixes, try again with latest dev.

@chankalson
Copy link
Author

@Koenkk I'm on the latest dev commit: 4c95265, but still seems the same, nothing is transmitted when i press the decoupled button.

Koenkk added a commit that referenced this issue Jan 7, 2021
@Koenkk
Copy link
Owner

Koenkk commented Jan 7, 2021

Ah, action was indeed not added yet. Added now.

Changes will be available in the latest dev branch in a few hours (https://www.zigbee2mqtt.io/how_tos/how-to-switch-to-dev-branch.html)

@chankalson
Copy link
Author

@Koenkk There's a typo of the switch model under 'xiaomi_multistate_action' in fromZigbee.js. Should be QBKG26LM, not QKBG26LM. No wonder it's still not working. 🤣

@Koenkk
Copy link
Owner

Koenkk commented Jan 9, 2021

ah fixed now

Koenkk added a commit that referenced this issue Jan 9, 2021
@chankalson
Copy link
Author

@Koenkk Still no actions being sent from the switch on latest dev, any idea why?

@Koenkk
Copy link
Owner

Koenkk commented Jan 10, 2021

Can you provide the debug log when clicking the bug?

To enable debug logging set in configuration.yaml:

advanced:
  log_level: debug

@chankalson
Copy link
Author

chankalson commented Jan 10, 2021

This is the debug log when decoupled mode is not enabled for the button:
Zigbee2MQTT:debug 2021-01-10 22:53:55: Received Zigbee message from 'Room 3 Switch', type 'attributeReport', cluster 'genOnOff', data '{"onOff":1}' from endpoint 2 with groupID 0

There is nothing logged when the decoupled button is clicked.

@Koenkk
Copy link
Owner

Koenkk commented Jan 10, 2021

  • Are you sure the QBKG26ML is in decoupled mode? The message looks entirely different than what the QBKG26LM uses.
  • If yes, can you provide me the debug logs when doing a, click, release and hold in both decoupled and non-decoupled mode. In the log add comments before each Received Zigbee message with what actions it was triggered (click,release,hold)

@chankalson
Copy link
Author

chankalson commented Jan 10, 2021

Yes, i'm sure the button is in decoupled mode because when i click it does not turn on/off the relay.

In decoupled mode, there is no Received Zigbee message, no matter click, release or hold, nothing happens in the log, which is what i find strange. I've tried re-pairing the switch, and also tried with another switch of same model.

In non-decoupled mode, this is the only Received Zigbee message, same for click, release or hold:
Received Zigbee message from 'Room 3 Switch', type 'attributeReport', cluster 'genOnOff', data '{"onOff":1}' from endpoint 2 with groupID 0 (Turn on relay)
Received Zigbee message from 'Room 3 Switch', type 'attributeReport', cluster 'genOnOff', data '{"onOff":0}' from endpoint 2 with groupID 0 (Turn off relay)

I'm guessing the switch is not sending any actions?

@Koenkk
Copy link
Owner

Koenkk commented Jan 10, 2021

In decoupled mode, there is no Received Zigbee message, no matter click, release or hold, nothing happens in the log, which is what i find strange. I've tried re-pairing the switch, and also tried with another switch of same model.

That explains a lot. Can you sniff the traffic when clicking the button in decoupled mode, do you see any messages being send directly after pressing the button? If not, can you try sniffing the same but then with the Xiaomi gateway?

@chankalson
Copy link
Author

chankalson commented Jan 10, 2021

image

This was sniffed from zigbee2mqtt, after clicking the decoupled button.

Edit: I don’t think this is related to the action, cause if i click the button again then nothing is sent.

@chankalson
Copy link
Author

chankalson commented Jan 10, 2021

image

This is sniffed from the Xiaomi Gateway with a left button click in decoupled mode.

Any reason why the switch sends the action message to Xiaomi Gateway but not to zigbee2mqtt? 🤷🏻

@Koenkk
Copy link
Owner

Koenkk commented Jan 10, 2021

That's indeed exactly what I would expect: #1986 (comment)

Did you enable the decoupled mode for each endpoint (left,center,right)? In your Xiaomi gateway sniff I see the gateway does this.

@chankalson
Copy link
Author

chankalson commented Jan 10, 2021

Yes I tried enabling decoupled mode for all 3 endpoints, still the same.

This is the debug log when i enable the decoupled mode:
Received MQTT message on 'zigbee2mqtt/Living Room Switch 1/right/set' with data '{ "operation_mode": { "state": "decoupled" } }'
Publishing 'set' 'operation_mode' to 'Living Room Switch 1'
Received Zigbee message from 'Living Room Switch 1', type 'attributeReport', cluster 'aqaraOpple', data '{"512":0}' from endpoint 3 with groupID 0

However in theory, even in non-decoupled mode, the button should also send the action when it is clicked right?
I see that's what happens in the Xiaomi gateway sniff when i click the button in non-decoupled mode: First the On/Off is sent, followed by the Multistate Input.

But with zigbee2mqtt, the switch only sends the On/Off.

@Koenkk
Copy link
Owner

Koenkk commented Jan 10, 2021

Can you provide the log when pairing the QBKG26LM with the xiaomi gateway? Once it's paired click the button once so I can see the click message.

@chankalson
Copy link
Author

chankalson commented Jan 10, 2021

Here's the sniff of pairing the switch and left button click:
QBKG26LM SNIFF.zip

The button click On/Off is on Frame 70, Multistate Input on Frame 72.

@Koenkk
Copy link
Owner

Koenkk commented Jan 10, 2021

Looks it does nothing special. Can you try removing line

configure: async (device, coordinatorEndpoint, logger) => {
till and pair with z2m again. Does it work after this?

@chankalson
Copy link
Author

chankalson commented Jan 11, 2021

Still doesn't work unfortunately. Also, the relay state is not updated after removing those lines.

Could it be that we have to poll the switch for the Multistate Input?

Could it be related to zStack version? (I'm on 1.2)
Or is it possible that the QBKG26LM is able to recognise the Xiaomi gateway and only send certain messages there? (Seems unlikely right?)

@github-actions github-actions bot added the stale label Jun 12, 2021
@sunsamzhen
Copy link

sunsamzhen commented Jun 14, 2021

It may be the QBKG26LM 02-24-2020 firmware issue, the actions run normally in 09-27-2019 build date version, but not in 2020, something changed in this version.
I try to add await device.getEndpoint(1).write('aqaraOpple', {'mode': 1}, {manufacturerCode: 0x115f}); in

 configure: async (device, coordinatorEndpoint, logger) => {
            await device.getEndpoint(1).write('aqaraOpple', {'mode': 1}, {manufacturerCode: 0x115f});
            await reporting.bind(device.getEndpoint(1), coordinatorEndpoint, ['genOnOff']);
            await reporting.bind(device.getEndpoint(2), coordinatorEndpoint, ['genOnOff']);
            await reporting.bind(device.getEndpoint(3), coordinatorEndpoint, ['genOnOff']);
            await reporting.onOff(device.getEndpoint(1));
            await reporting.onOff(device.getEndpoint(2));
            await reporting.onOff(device.getEndpoint(3));
        }

the default mode is {'mode': 0}, in this mode the switch wouldn't sent any message when button click.
then re-pairing the switch and do some actions, the action info would come out.

截屏2021-06-14 下午6 51 07

It work!!!

@github-actions github-actions bot removed the stale label Jun 15, 2021
@satedone
Copy link

Please tell me in simple terms, what should I do to make my actions work on this switch? I did QBKG26LM decoupled mode but can't see actions.

@redesigndavid
Copy link

I tried to do this last night too. This is what I did:

  1. Fresh image of raspberry pi
  2. Installed zigbee2mqtt
  3. Ran it first, updated the configuration, exited the process
  4. Open "node_modules/zigbee-herdsman-converters/devices/xiaomi.js" and added that "await device.getEndpoint(1).write('aqaraOpple', {'mode': 1}, {manufacturerCode: 0x115f});" on line 429.
  5. Started the process. Repaired the QBKG26LM. Sent the decoupled command. I do this via:
    mosquitto_pub -t 'zigbee2mqtt/0x54ef4410000177c0/set' -m '{"operation_mode_right": "decoupled"}'
  6. I see logs saying my switch is decoupled, and it's definitely decoupled. But nothing in the logs when I press the right button like yours.

@sunsamzhen how do you activate your 'decoupled' mode? Looking at the steps I followed outlined above, do you think I'm missing anything? Thank you!

@redesigndavid
Copy link

Scratch that. I got it to work. I looked at my switches initialization and turns out I have a QBKG25LM. I added that same line for that device it worked as well! BRAVO!

@redesigndavid
Copy link

@Koenkk is it possible to include this update?

@Koenkk
Copy link
Owner

Koenkk commented Jun 20, 2021

@redesigndavid when adding await device.getEndpoint(1).write('aqaraOpple', {'mode': 1}, {manufacturerCode: 0x115f}); does it still report state changes when not in decoupled mode?

@lovelylain
Copy link

@Koenkk mode 1 will make QBKG26LM behave like QBKG24LM and other old models, it report state changes whether it's decoupled mode or not, fz.xiaomi_power can be added for power measure. It is suggested that replace fz.xiaomi_multistate_action with fz.aqara_opple_multistate, because the code of the fz.xiaomi_multistate_action is ugly and cannot cover all combinations, the fz.aqara_opple_multistate is more general.

button_41: left
button_42: center
button_43: right
button_51: left&center
button_52: left&right
button_53: center&right
button_61: left&center&right
every button has single and double event.

@Koenkk
Copy link
Owner

Koenkk commented Jun 21, 2021

@lovelylain could you make a pull request with these changes?

because the code of the fz.xiaomi_multistate_action is ugly and cannot cover all combinations, the fz.aqara_opple_multistate is more general.

But does this change the published values for action? If yes, this is a breaking change and I propose to update fz.xiaomi_multistate_action instead to cover the missing combinations.

@balonchiks
Copy link

balonchiks commented Jun 23, 2021

@redesigndavid when adding await device.getEndpoint(1).write('aqaraOpple', {'mode': 1}, {manufacturerCode: 0x115f}); does it still report state changes when not in decoupled mode?

came here from here, and I can confirm that adding this line (i am using QBKG25LM) - the state changes are also reported when the switch is not in the decoupled mode.

as with other people in this thread - without this line in xiaomi.js (and firmware from this post) - QBKG25LM does not report anything when in decoupled mode

@Koenkk
Copy link
Owner

Koenkk commented Jun 26, 2021

@redesigndavid @balonchiks thanks for confirming, added the fix.

Changes will be available in the dev branch in a few hours from now. (https://www.zigbee2mqtt.io/how_tos/how-to-switch-to-dev-branch.html)

@skyksandr
Copy link

skyksandr commented Jun 27, 2021

First of all, Thank you @Koenkk for your work!
Came here from google as I have exact same issue. Switched to dev branch, re-paired device, but no luck, not getting an event.

Am I correct that I need re-flash my coordinator?

Let me know if I can help somehow.

@ruifung
Copy link
Contributor

ruifung commented Jun 28, 2021

As stated by @sunsamzhen above, I needed to add
await device.getEndpoint(1).write('aqaraOpple', {'mode': 1}, {manufacturerCode: 0x115f, disableResponse: true});
for my QBKG26LM (lumi.switch.n3acn3) to make it report actions when in decoupled mode. It does also report when not in decoupled mode though.

I'm not using the manufacturer code firmware given above as I'm using a raspBee II as my adapter.

Also, I note that the documentation page for the QBKG26LM seems to have incorrect information regarding the setting of the decoupled mode in MQTT. Probably should note that the alternate instructions for QBKG25LM also applies to QBKG26LM .

@balonchiks
Copy link

Am I correct that I need re-flash my coordinator?

if you are using stick v3 from modkam.ru then yes, you need to flash it with this firmware

@skyksandr
Copy link

@balonchiks I'm using cc2531 stick flashed with coordinator firmware.

@ruifung do you mean:

zigbee2mqtt/<device_id>/set
{"operation_mode_right": "decoupled"}

or

zigbee2mqtt/<device_id>/right/set
{
  "operation_mode": {
    "state": "decoupled"
  }
}

If that makes any difference.

@lovelylain
Copy link

lovelylain commented Jun 28, 2021

@skyksandr No need to re-flash your coordinator. Koenkk only fixed for QBKG25LM, if your device is QBKG26LM, please wait or modify by yourself.
https://github.com/Koenkk/zigbee-herdsman-converters/blob/master/devices/xiaomi.js#L403

ruifung added a commit to ruifung/zigbee-herdsman-converters that referenced this issue Jun 28, 2021
Apparently the genAnalogInput cluster isn't present to be interviewed. Though it's sending attribute reports for it and attempting to GET the attribute just gives a no response error. Hence the ea.STATE and no tz.xiaomi_power here.

Also the decoupled mode changes from Koenkk#1986 (comment)

This has been tested on my local installation and power reporting works, as does decoupled mode actions. Though it will always send actions even when not decoupled.
@Koenkk
Copy link
Owner

Koenkk commented Jun 28, 2021

Merged #2734 assuming this can be closed now.

Changes will be available in the dev branch in a few hours from now. (https://www.zigbee2mqtt.io/how_tos/how-to-switch-to-dev-branch.html)

@Koenkk Koenkk closed this as completed Jun 28, 2021
Koenkk added a commit that referenced this issue Jun 28, 2021
* Power reporting and decoupled mode for Aqara QBKG26LM

Apparently the genAnalogInput cluster isn't present to be interviewed. Though it's sending attribute reports for it and attempting to GET the attribute just gives a no response error. Hence the ea.STATE and no tz.xiaomi_power here.

Also the decoupled mode changes from #1986 (comment)

This has been tested on my local installation and power reporting works, as does decoupled mode actions. Though it will always send actions even when not decoupled.

* Update xiaomi.js

Co-authored-by: Koen Kanters <koenkanters94@gmail.com>
@ruifung
Copy link
Contributor

ruifung commented Jun 28, 2021

Just because it's somewhat related to this, #2735 should also fix the wierdness in the operation_mode states (and outright not being able to /get them). Now I can check if the switch is decoupled before doing anything for the action.

@skyksandr
Copy link

@Koenkk, @ruifung Thank you guys! It is now working! Owe you guys a 🍻

@redesigndavid
Copy link

Just want to say huge thanks @Koenkk

@Koenkk
Copy link
Owner

Koenkk commented Jul 7, 2021

@redesigndavid all credits go to @ruifung 😄

@slydiman
Copy link

slydiman commented Jul 7, 2021

Appreciate your efforts but since I already put too much time into this issue and I don't see anything different in your sniffs I don't want to continue further on it.

reopened this on 9 Feb

reopened this on 5 May

😄

@kondrikserg
Copy link

Energy is not displayed on the qbkg26lm device. Zigbee2mqtt version 1.32.1-1.
image

@ruifung
Copy link
Contributor

ruifung commented Jul 13, 2023

Energy is not displayed on the qbkg26lm device. Zigbee2mqtt version 1.32.1-1.

@kondrikserg Please open a new issue instead of adding a comment here. This issue is closed and ancient, and completely unrelated to your issue.

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