[New device support]: ZNQBKG38LM Xiaomi Aqara Z1 1 gang smart wall switch
Link
https://www.aqara.com/cn/Canon_Smart_Wall_Switch_Z1_overview
Database entry
{"id":2,"type":"EndDevice","ieeeAddr":"0x54ef44100094d5ea","nwkAddr":36341,"manufId":4447,"manufName":"Aqara","powerSource":"DC Source","modelId":"lumi.switch.acn048","epList":[1,2,3,4,21],"endpoints":{"1":{"profId":260,"epId":1,"devId":0,"inClusterList":[2820,1794,18,5,4,6,3,0,64704],"outClusterList":[10,25],"clusters":{"genBasic":{"attributes":{"modelId":"lumi.switch.acn048","manufacturerName":"Aqara","powerSource":4,"zclVersion":3,"appVersion":31,"stackVersion":27,"hwVersion":1,"dateCode":"20231102"}},"aqaraOpple":{"attributes":{"4":4,"223":{"type":"Buffer","data":[3,35,92,0,0,0,4,33,5,0,5,33,0,0,41,35,82,162,50,0,42,35,71,179,0,8,40,35,64,0,0,0,43,33,0,0,44,41,160,255]},"247":{"type":"Buffer","data":[3,40,27,5,33,131,0,9,33,0,0,10,33,0,0,12,32,10,13,35,31,0,0,0,17,35,1,0,0,0,100,16,0,149,57,0,0,0,0,150,57,102,102,27,69,152,57,0,0,0,0,151,57,0,0,0,0,154,32,0]},"512":1,"617":1,"645":0,"646":1,"648":0,"651":1,"1303":1}},"genOnOff":{"attributes":{"245":42857728,"onOff":0}}},"binds":[],"configuredReportings":[],"meta":{}},"2":{"profId":260,"epId":2,"devId":0,"inClusterList":[64704],"outClusterList":[],"clusters":{"aqaraOpple":{"attributes":{"512":1,"617":1,"645":0}}},"binds":[],"configuredReportings":[],"meta":{}},"3":{"profId":260,"epId":3,"devId":0,"inClusterList":[64704],"outClusterList":[],"clusters":{"aqaraOpple":{"attributes":{"512":1,"617":1,"645":0}}},"binds":[],"configuredReportings":[],"meta":{}},"4":{"profId":260,"epId":4,"devId":0,"inClusterList":[64704],"outClusterList":[],"clusters":{"aqaraOpple":{"attributes":{"617":0}}},"binds":[],"configuredReportings":[],"meta":{}},"21":{"profId":260,"epId":21,"devId":0,"inClusterList":[12],"outClusterList":[],"clusters":{"genAnalogInput":{"attributes":{"presentValue":0}}},"binds":[],"configuredReportings":[],"meta":{}}},"appVersion":31,"stackVersion":27,"hwVersion":1,"dateCode":"20231102","zclVersion":3,"interviewCompleted":true,"meta":{"configured":1854471209},"lastSeen":1700850656590,"defaultSendRequestWhen":"immediate"}
Comments
requested from various z1 1 gang owners, including @maodun96 who dropped me a message and nice comment from @nickgoh. I tried to draft one for z1 1 gang.
As I did not own one, please comment
Original Thread for Aqara Z1 3-gang switch https://github.com/Koenkk/zigbee2mqtt/issues/18135
External converter
//. Changlog 20231124 - first ver for ZNQBKG38LM
//. Continue work from nickgoh - https://github.com/Koenkk/zigbee2mqtt/issues/18135#issuecomment-1778487502
//.
//. 1. still thinking this version of firmware only support
//. - action: single (no double, triple, hold)
//. - no multiple button pressed together (no both, all)
//. 2. as button arranged in "top to buttom" instead of "standard" left to right, I renamed as button_1 instead of left
//. 3. Need help on function to make these working
//. - flip_indicator_light, power_outage_memory and click mode
//. - Seems address got changed but I have no idea
const fz = require('zigbee-herdsman-converters/converters/fromZigbee');
const tz = require('zigbee-herdsman-converters/converters/toZigbee');
const exposes = require('zigbee-herdsman-converters/lib/exposes');
const reporting = require('zigbee-herdsman-converters/lib/reporting');
const extend = require('zigbee-herdsman-converters/lib/extend');
const ota = require('zigbee-herdsman-converters/lib/ota');
//. PLEASE READ: These are present from device/xiaomi.ts, only needed for external converter
const herdsman = require('zigbee-herdsman');
const e = exposes.presets;
const ea = exposes.access;
const manufacturerOptions = {
xiaomi: {manufacturerCode: herdsman.Zcl.ManufacturerCode.LUMI_UNITED_TECH, disableDefaultResponse: true},
};
const { hasAlreadyProcessedMessage } = require('zigbee-herdsman-converters/lib/utils');
const preventReset = async (type, data, device) => {
if (
// options.allow_reset ||
type !== 'message' ||
data.type !== 'attributeReport' ||
data.cluster !== 'genBasic' ||
!data.data[0xfff0] ||
// eg: [0xaa, 0x10, 0x05, 0x41, 0x87, 0x01, 0x01, 0x10, 0x00]
!data.data[0xFFF0].slice(0, 5).equals(Buffer.from([0xaa, 0x10, 0x05, 0x41, 0x87]))
) {
return;
}
const options = {manufacturerCode: 0x115f};
const payload = {[0xfff0]: {
value: [0xaa, 0x10, 0x05, 0x41, 0x47, 0x01, 0x01, 0x10, 0x01],
type: 0x41,
}};
await device.getEndpoint(1).write('genBasic', payload, options);
}; // PLEASE READ: THE END OF THE BLOCK THAT CAN BE DELELED after released
//. PLEASE READ: These should be update to FromZigbee.js
const fzLocal = {
xiaomi_multistate_action: {
cluster: 'genMultistateInput',
type: ['attributeReport'],
convert: (model, msg, publish, options, meta) => {
if (hasAlreadyProcessedMessage(msg, model)) return;
let actionLookup = {0: 'hold', 1: 'single', 2: 'double', 3: 'triple', 255: 'release'};
if (model.model === 'WXKG12LM') {
actionLookup = {...actionLookup, 16: 'hold', 17: 'release', 18: 'shake'};
}
if (['WXKG02LM_rev2', 'WXKG07LM', 'WXKG15LM', 'WXKG17LM'].includes(model.model)) {
buttonLookup = {1: 'left', 2: 'right', 3: 'both'};
}
if (['ZNQBKG38LM'].includes(model.model)) {
buttonLookup = {1: 'button_1'};
}
if (['ZNQBKG39LM'].includes(model.model)) {
buttonLookup = {1: 'button_1', 2: 'button_2'};
}
if (['ZNQBKG40LM'].includes(model.model)) {
buttonLookup = {1: 'button_1', 2: 'button_2', 3: 'button_3'};
}
if (['ZNQBKG41LM'].includes(model.model)) {
buttonLookup = {1: 'button_1', 2: 'button_2', 3: 'button_3', 4: 'button_4'};
}
if (['QBKG12LM', 'QBKG24LM'].includes(model.model)) buttonLookup = {5: 'left', 6: 'right', 7: 'both'};
if (['QBKG39LM', 'QBKG41LM', 'WS-EUK02', 'WS-EUK04', 'QBKG20LM', 'QBKG28LM', 'QBKG31LM'].includes(model.model)) {
buttonLookup = {41: 'left', 42: 'right', 51: 'both'};
}
if (['QBKG25LM', 'QBKG26LM', 'QBKG29LM', 'QBKG34LM', 'ZNQBKG31LM', 'ZNQBKG26LM'].includes(model.model)) {
buttonLookup = {
41: 'left', 42: 'center', 43: 'right',
51: 'left_center', 52: 'left_right', 53: 'center_right',
61: 'all',
};
}
if (['WS-USC02', 'WS-USC04'].includes(model.model)) {
buttonLookup = {41: 'top', 42: 'bottom', 51: 'both'};
}
const action = actionLookup[msg.data['presentValue']];
if (buttonLookup) {
const button = buttonLookup[msg.endpoint.ID];
if (button) {
return {action: `${action}_${button}`};
}
} else {
return {action};
}
},
},
}; // PLEASE READ: THE END OF THE BLOCK THAT CAN BE DELETE WHEN MERGING WITH FromZigbee.js
// PLEASE READ: These should be update to ToZigbee.js
const tzLocal = {
xiaomi_switch_power_outage_memory: {
key: ['power_outage_memory'],
convertSet: async (entity, key, value, meta) => {
if (['SP-EUC01', 'ZNCZ04LM', 'ZNCZ12LM', 'ZNCZ15LM', 'QBCZ14LM', 'QBCZ15LM', 'SSM-U01', 'SSM-U02', 'DLKZMK11LM', 'DLKZMK12LM',
'WS-EUK01', 'WS-EUK02', 'WS-EUK03', 'WS-EUK04', 'QBKG19LM', 'QBKG20LM', 'QBKG25LM', 'QBKG26LM', 'QBKG28LM', 'QBKG29LM',
'QBKG31LM', 'QBKG34LM', 'QBKG38LM', 'QBKG39LM', 'QBKG40LM', 'QBKG41LM', 'ZNDDMK11LM', 'ZNLDP13LM', 'ZNQBKG31LM',
'WS-USC02', 'WS-USC03', 'WS-USC04', 'ZNQBKG24LM', 'ZNQBKG24LM'
].includes(meta.mapped.model)) {
await entity.write('aqaraOpple', {0x0201: {value: value ? 1 : 0, type: 0x10}}, manufacturerOptions.xiaomi);
} else if (['ZNQBKG38LM','ZNQBKG39LM','ZNQBKG40LM','ZNQBKG41LM'].includes(meta.mapped.model)) {
// Support existing syntax of a nested object just for the state field. Though it's quite silly IMO.
const targetValue = value.hasOwnProperty('state') ? value.state : value;
const lookupState = {on: 0x01, electric_appliances_on: 0x00,electric_appliances_off: 0x02,Inverted: 0x03};
await entity.write('aqaraOpple', {0x0517: {value: lookupState[targetValue], type: 0x20}}, manufacturerOptions.xiaomi);
} else if (['ZNCZ02LM', 'QBCZ11LM', 'LLKZMK11LM'].includes(meta.mapped.model)) {
const payload = value ?
[[0xaa, 0x80, 0x05, 0xd1, 0x47, 0x07, 0x01, 0x10, 0x01], [0xaa, 0x80, 0x03, 0xd3, 0x07, 0x08, 0x01]] :
[[0xaa, 0x80, 0x05, 0xd1, 0x47, 0x09, 0x01, 0x10, 0x00], [0xaa, 0x80, 0x03, 0xd3, 0x07, 0x0a, 0x01]];
await entity.write('genBasic', {0xFFF0: {value: payload[0], type: 0x41}}, manufacturerOptions.xiaomi);
await entity.write('genBasic', {0xFFF0: {value: payload[1], type: 0x41}}, manufacturerOptions.xiaomi);
} else if (['ZNCZ11LM'].includes(meta.mapped.model)) {
const payload = value ?
[0xaa, 0x80, 0x05, 0xd1, 0x47, 0x00, 0x01, 0x10, 0x01] :
[0xaa, 0x80, 0x05, 0xd1, 0x47, 0x01, 0x01, 0x10, 0x00];
await entity.write('genBasic', {0xFFF0: {value: payload, type: 0x41}}, manufacturerOptions.xiaomi);
} else {
throw new Error('Not supported');
}
return {state: {power_outage_memory: value}};
},
convertGet: async (entity, key, meta) => {
if (['SP-EUC01', 'ZNCZ04LM', 'ZNCZ12LM', 'ZNCZ15LM', 'QBCZ14LM', 'QBCZ15LM', 'SSM-U01', 'SSM-U02', 'DLKZMK11LM', 'DLKZMK12LM',
'WS-EUK01', 'WS-EUK02', 'WS-EUK03', 'WS-EUK04', 'QBKG19LM', 'QBKG20LM', 'QBKG25LM', 'QBKG26LM', 'QBKG28LM', 'QBKG29LM',
'QBKG31LM', 'QBKG34LM', 'QBKG38LM', 'QBKG39LM', 'QBKG40LM', 'QBKG41LM', 'ZNDDMK11LM', 'ZNLDP13LM', 'ZNQBKG31LM',
'WS-USC02', 'WS-USC03', 'WS-USC04', 'ZNQBKG24LM',
].includes(meta.mapped.model)) {
await entity.read('aqaraOpple', [0x0201]);
} else if (['ZNQBKG38LM','ZNQBKG39LM','ZNQBKG40LM','ZNQBKG41LM'].includes(meta.mapped.model)) {
await entity.read('aqaraOpple', [0x0517]);
} else if (['ZNCZ02LM', 'QBCZ11LM', 'ZNCZ11LM'].includes(meta.mapped.model)) {
await entity.read('aqaraOpple', [0xFFF0]);
} else {
throw new Error('Not supported');
}
},
},
xiaomi_switch_lock_relay_opple: {
key: ['lock_relay'],
convertSet: async (entity, key, value, meta) => {
const lookup = {'OFF': 0x00, 'ON': 0x01};
await entity.write('aqaraOpple', {0x0285: {value: lookup[value], type: 0x20}}, manufacturerOptions.xiaomi);
return {state: {lock_relay: value}};
},
convertGet: async (entity, key, meta) => {
await entity.read('aqaraOpple', [0x0285], manufacturerOptions.xiaomi);
},
},
xiaomi_switch_click_mode: {
key: ['click_mode'],
convertSet: async (entity, key, value, meta) => {
if (['ZNQBKG38LM','ZNQBKG39LM','ZNQBKG40LM','ZNQBKG41LM'].includes(meta.mapped.model)) {
const lookupState = {'fast': 0x01, 'multi': 0x02};
await entity.write('aqaraOpple', {0x0286: {value: lookupState[value], type: 0x20}}, manufacturerOptions.xiaomi);
} else{
const lookupState = {'fast': 0x1, 'multi': 0x02};
await entity.write('aqaraOpple', {0x0125: {value: lookupState[value], type: 0x20}}, manufacturerOptions.xiaomi);
}
return {state: {click_mode: value}};
},
convertGet: async (entity, key, meta) => {
await entity.read('aqaraOpple', [0x125], manufacturerOptions.xiaomi);
},
},
}; // PLEASE READ: THE END OF THE BLOCK THAT CAN BE DELETE WHEN MERGING WITH ToZigbee.js
const definition = {
zigbeeModel: ['lumi.switch.acn048'], // The model ID from: Device with modelID 'lumi.sens' is not supported.
model: 'ZNQBKG38LM', // Vendor model number, look on the device for a model number
vendor: 'Xiaomi', // Vendor of the device (only used for documentation and startup logging)
description: 'Aqara Z1 1 gang smart wall switch', // Description of the device, copy from vendor site. (only used for documentation and startup logging)
fromZigbee: [fz.on_off, fzLocal.xiaomi_multistate_action, fz.aqara_opple, fz.xiaomi_power],
toZigbee: [tz.on_off, tz.xiaomi_switch_operation_mode_opple, tzLocal.xiaomi_switch_power_outage_memory,tzLocal.xiaomi_switch_lock_relay_opple,tzLocal.xiaomi_switch_click_mode],
endpoint: (device) => {
return {'button_1': 1};
},
meta: {multiEndpoint: true},
exposes: [
e.power(), e.voltage(), e.device_temperature(),
e.switch().withEndpoint('button_1'),
exposes.enum('power_outage_memory', ea.ALL, ['on', 'electric_appliances_on', 'electric_appliances_off', 'Inverted'])
.withDescription('Power Outage Memory'),
exposes.enum('operation_mode', ea.ALL, ['control_relay', 'decoupled'])
.withDescription('Decoupled mode for button 1 button')
.withEndpoint('button_1'),
exposes.enum('lock_relay', ea.ALL, ['On', 'Off'])
.withDescription('Lock Relay mode for button 1 button')
.withEndpoint('button_1'),
exposes.enum('click_mode', ea.ALL, ['fast', 'multi'])
.withDescription('Click mode, fast: only supports single click which will be send immediately after clicking.' +
'multi: supports more events like double and hold'),
e.action(['button_1_single', 'button_1_double']),
],
onEvent: preventReset,
configure: async (device, coordinatorEndpoint, logger) => {
await device.getEndpoint(1).write('aqaraOpple', {'mode': 1}, {manufacturerCode: 0x115f, disableResponse: true});
// await device.getEndpoint(1).write('aqaraOpple', {0x0125: {value: 0x02, type: 0x20}}, {manufacturerCode: 0x115f});
},
};
module.exports = definition;
Supported color modes
No response
Color temperature range
No response
Dear @maodun96 , Would you provide me the Database entry after your put these code into your device?
If the code works I will submit changes to source.
Dear @maodun96 , Would you provide me the Database entry after your put these code into your device?
If the code works I will submit changes to source.
I would be happy to serve you. This is my Database entry. My Aqara Z1 1 gang has been successfully driven.
Database entry: {"id":2,"type":"EndDevice","ieeeAddr":"0x54ef44100094d5ea","nwkAddr":36341,"manufId":4447,"manufName":"Aqara","powerSource":"DC Source","modelId":"lumi.switch.acn048","epList":[1,2,3,4,21],"endpoints":{"1":{"profId":260,"epId":1,"devId":0,"inClusterList":[2820,1794,18,5,4,6,3,0,64704],"outClusterList":[10,25],"clusters":{"genBasic":{"attributes":{"modelId":"lumi.switch.acn048","manufacturerName":"Aqara","powerSource":4,"zclVersion":3,"appVersion":31,"stackVersion":27,"hwVersion":1,"dateCode":"20231102"}},"aqaraOpple":{"attributes":{"4":4,"223":{"type":"Buffer","data":[3,35,92,0,0,0,4,33,5,0,5,33,0,0,41,35,82,162,50,0,42,35,71,179,0,8,40,35,64,0,0,0,43,33,0,0,44,41,160,255]},"247":{"type":"Buffer","data":[3,40,27,5,33,131,0,9,33,0,0,10,33,0,0,12,32,10,13,35,31,0,0,0,17,35,1,0,0,0,100,16,0,149,57,0,0,0,0,150,57,102,102,27,69,152,57,0,0,0,0,151,57,0,0,0,0,154,32,0]},"512":1,"617":1,"645":0,"646":1,"648":0,"651":1,"1303":1}},"genOnOff":{"attributes":{"245":42857728,"onOff":0}}},"binds":[],"configuredReportings":[],"meta":{}},"2":{"profId":260,"epId":2,"devId":0,"inClusterList":[64704],"outClusterList":[],"clusters":{"aqaraOpple":{"attributes":{"512":1,"617":1,"645":0}}},"binds":[],"configuredReportings":[],"meta":{}},"3":{"profId":260,"epId":3,"devId":0,"inClusterList":[64704],"outClusterList":[],"clusters":{"aqaraOpple":{"attributes":{"512":1,"617":1,"645":0}}},"binds":[],"configuredReportings":[],"meta":{}},"4":{"profId":260,"epId":4,"devId":0,"inClusterList":[64704],"outClusterList":[],"clusters":{"aqaraOpple":{"attributes":{"617":0}}},"binds":[],"configuredReportings":[],"meta":{}},"21":{"profId":260,"epId":21,"devId":0,"inClusterList":[12],"outClusterList":[],"clusters":{"genAnalogInput":{"attributes":{"presentValue":0}}},"binds":[],"configuredReportings":[],"meta":{}}},"appVersion":31,"stackVersion":27,"hwVersion":1,"dateCode":"20231102","zclVersion":3,"interviewCompleted":true,"meta":{"configured":1854471209},"lastSeen":1700850656590,"defaultSendRequestWhen":"immediate"}
@maodun96 ι£ε€ͺε₯½δΊ. ε¦ζε¨ζ«ζζιζδΉθ©¦θ©¦ 2 /3 gang ζΉεδΈδΈ, ζ²ε€§ει‘ε°± submit ζιη check, ι£ε°±δΈειθ¦η¨ converter δΊ. :-)