zigbee2mqtt icon indicating copy to clipboard operation
zigbee2mqtt copied to clipboard

[New device support]: ZNQBKG40LM Xiaomi Aqara Z1 3 gang smart wall switch

Open jomud9 opened this issue 3 years ago • 47 comments

Link

https://www.aqara.com/cn/Canon_Smart_Wall_Switch_Z1_overview

Database entry

{"id":15,"type":"EndDevice","ieeeAddr":"0x54ef4410008f6086","nwkAddr":22320,"manufId":4447,"manufName":"LUMI","powerSource":"Battery","modelId":"lumi.switch.acn054","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.acn054","appVersion":21}},"aqaraOpple":{"attributes":{"4":4,"247":{"type":"Buffer","data":[154,32,0]},"512":0,"617":1,"645":0,"646":1,"648":0,"1303":1}},"genOnOff":{"attributes":{"245":117440526,"onOff":1}},"genMultistateInput":{"attributes":{"presentValue":1}}},"binds":[],"configuredReportings":[],"meta":{}},"2":{"profId":260,"epId":2,"devId":0,"inClusterList":[18,5,4,6,64704],"outClusterList":[],"clusters":{"genOnOff":{"attributes":{"245":117440563,"onOff":0}},"aqaraOpple":{"attributes":{"512":0,"617":1,"645":0}},"genMultistateInput":{"attributes":{"presentValue":1}}},"binds":[],"configuredReportings":[],"meta":{}},"3":{"profId":260,"epId":3,"devId":0,"inClusterList":[18,5,4,6,64704],"outClusterList":[],"clusters":{"genOnOff":{"attributes":{"245":117440564,"onOff":0}},"aqaraOpple":{"attributes":{"512":0,"617":1,"645":0}},"genMultistateInput":{"attributes":{"presentValue":1}}},"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":2.059999942779541}}},"binds":[],"configuredReportings":[],"meta":{}}},"appVersion":21,"stackVersion":27,"hwVersion":1,"dateCode":"20230526","zclVersion":3,"interviewCompleted":true,"meta":{"configured":1854471209},"lastSeen":1687935847391,"defaultSendRequestWhen":"immediate"}

Comments

New Z1 3 gang after setup https://github.com/Koenkk/zigbee2mqtt/issues/18082

Currently it works for basic function

  • Docoupled control
  • voltage and power display

Following item still need to be addressed

  • action: ONLY single are supported after decoupled (no double, triple, hold)
  • no multiple button pressed together (no both, all)
  • flip_indicator_light(), power_outage_memory() and click mode() not working. ?? New Hardware New address??

External converter

//. Changlog 20230702
//. 1. Fix typo on fromZigbee and toZigbee section
//. 2. flip_indicator_light, power_outage_memory and click mode still not working
//. 
//. 
//. Changlog 20230628 - first ver for ZNQBKG40LM
//. Starting from ZNQBKG39LM - https://github.com/Koenkk/zigbee2mqtt/issues/18082 
//. 
//. 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 (['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 (['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', 'ZNQBKG39LM', 'ZNQBKG40LM'
            ].includes(meta.mapped.model)) {
                await entity.write('aqaraOpple', {0x0201: {value: value ? 1 : 0, type: 0x10}}, 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', 'ZNQBKG39LM', 'ZNQBKG40LM'
            ].includes(meta.mapped.model)) {
                await entity.read('aqaraOpple', [0x0201]);
            } else if (['ZNCZ02LM', 'QBCZ11LM', 'ZNCZ11LM'].includes(meta.mapped.model)) {
                await entity.read('aqaraOpple', [0xFFF0]);
            } else {
                throw new Error('Not supported');
            }
        },
    },
    xiaomi_led_disabled_night: {
        key: ['led_disabled_night'],
        convertSet: async (entity, key, value, meta) => {
            if (['ZNCZ04LM', 'ZNCZ12LM', 'ZNCZ15LM', 'QBCZ14LM', 'QBCZ15LM', 'QBKG19LM', 'QBKG20LM', 'QBKG25LM', 'QBKG26LM',
                'QBKG28LM', 'QBKG29LM', 'QBKG31LM', 'QBKG34LM', 'DLKZMK11LM', 'SSM-U01', 'WS-EUK01', 'WS-EUK02',
                'WS-EUK03', 'WS-EUK04', 'SP-EUC01', 'ZNQBKG24LM', 'ZNQBKG39LM', 'ZNQBKG40LM'].includes(meta.mapped.model)) {
                await entity.write('aqaraOpple', {0x0203: {value: value ? 1 : 0, type: 0x10}}, manufacturerOptions.xiaomi);
            } else if (['ZNCZ11LM'].includes(meta.mapped.model)) {
                const payload = value ?
                    [0xaa, 0x80, 0x05, 0xd1, 0x47, 0x00, 0x03, 0x10, 0x00] :
                    [0xaa, 0x80, 0x05, 0xd1, 0x47, 0x01, 0x03, 0x10, 0x01];

                await entity.write('genBasic', {0xFFF0: {value: payload, type: 0x41}}, manufacturerOptions.xiaomi);
            } else {
                throw new Error('Not supported');
            }
            return {state: {led_disabled_night: value}};
        },
        convertGet: async (entity, key, meta) => {
            if (['ZNCZ04LM', 'ZNCZ12LM', 'ZNCZ15LM', 'QBCZ15LM', 'QBCZ14LM', 'QBKG19LM', 'QBKG20LM', 'QBKG25LM', 'QBKG26LM',
                'QBKG28LM', 'QBKG29LM', 'QBKG31LM', 'QBKG34LM', 'DLKZMK11LM', 'SSM-U01', 'WS-EUK01', 'WS-EUK02',
                'WS-EUK03', 'WS-EUK04', 'SP-EUC01', 'ZNQBKG24LM', 'ZNQBKG39LM', 'ZNQBKG40LM'].includes(meta.mapped.model)) {
                await entity.read('aqaraOpple', [0x0203], manufacturerOptions.xiaomi);
            } else {
                throw new Error('Not supported');
            }
        },
    },
    
}; // PLEASE READ: THE END OF THE BLOCK THAT CAN BE DELETE WHEN MERGING WITH ToZigbee.js



const definition = {
    zigbeeModel: ['lumi.switch.acn054'], // The model ID from: Device with modelID 'lumi.sens' is not supported.
    model: 'ZNQBKG40LM', // 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 3 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, tz.xiaomi_flip_indicator_light, tzLocal.xiaomi_switch_power_outage_memory, tzLocal.xiaomi_led_disabled_night],
    endpoint: (device) => {
        return {'button_1': 1, 'button_2': 2, 'button_3': 3};
    },
    meta: {multiEndpoint: true},
    exposes: [
        e.power(), e.voltage(), e.device_temperature(), e.flip_indicator_light(), e.power_outage_memory(),
        e.switch().withEndpoint('button_1'), e.switch().withEndpoint('button_2'), e.switch().withEndpoint('button_3'),
        exposes.enum('operation_mode', ea.ALL, ['control_relay', 'decoupled'])
                .withDescription('Decoupled mode for button1 (Top) button')
                .withEndpoint('button_1'),
        exposes.enum('operation_mode', ea.ALL, ['control_relay', 'decoupled'])
                .withDescription('Decoupled mode for button 2 (Middle) button')
                .withEndpoint('button_2'),
        exposes.enum('operation_mode', ea.ALL, ['control_relay', 'decoupled'])
                .withDescription('Decoupled mode for button 3 (Buttom) button')
                .withEndpoint('button_3'),
        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', 'button_2_single', 'button_2_double', 'button_3_single', 'button_3_double',
                    'button_1_button_2_single', 'button_1_button_2_double', 'button_1_button_3_single', 'button_1_button_3_double',
                    'button_2_button_3_single', 'button_2_button_3_double', 'all_single', 'all_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

jomud9 avatar Jun 28 '23 07:06 jomud9

Got stuck with same issue reported in https://github.com/Koenkk/zigbee2mqtt/issues/18082#issuecomment-1620483816

@Koenkk not sure if Zigbee sniffing could help or not.

jomud9 avatar Jul 07 '23 17:07 jomud9

No feedback still. Might try to update related files to make it workable, then fix the remaining later

jomud9 avatar Jul 12 '23 17:07 jomud9

please also support ZNQBKG41LM which is 4 gang switch thank u very much~

Helloookimi avatar Jul 13 '23 09:07 Helloookimi

please also support ZNQBKG41LM which is 4 gang switch thank u very much~

If you could help, please try this?

//. Changlog 20230717 - first ver for ZNQBKG41LM
//. Starting from ZNQBKG39LM - https://github.com/Koenkk/zigbee2mqtt/issues/18082 
//. 
//. 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 (['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', 'ZNQBKG39LM', 'ZNQBKG40LM', 'ZNQBKG41LM', 
            ].includes(meta.mapped.model)) {
                await entity.write('aqaraOpple', {0x0201: {value: value ? 1 : 0, type: 0x10}}, 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', 'ZNQBKG39LM', 'ZNQBKG40LM', 'ZNQBKG41LM',
            ].includes(meta.mapped.model)) {
                await entity.read('aqaraOpple', [0x0201]);
            } else if (['ZNCZ02LM', 'QBCZ11LM', 'ZNCZ11LM'].includes(meta.mapped.model)) {
                await entity.read('aqaraOpple', [0xFFF0]);
            } else {
                throw new Error('Not supported');
            }
        },
    },
    xiaomi_led_disabled_night: {
        key: ['led_disabled_night'],
        convertSet: async (entity, key, value, meta) => {
            if (['ZNCZ04LM', 'ZNCZ12LM', 'ZNCZ15LM', 'QBCZ14LM', 'QBCZ15LM', 'QBKG19LM', 'QBKG20LM', 'QBKG25LM', 'QBKG26LM',
                'QBKG28LM', 'QBKG29LM', 'QBKG31LM', 'QBKG34LM', 'DLKZMK11LM', 'SSM-U01', 'WS-EUK01', 'WS-EUK02',
                'WS-EUK03', 'WS-EUK04', 'SP-EUC01', 'ZNQBKG24LM', 'ZNQBKG39LM', 'ZNQBKG40LM', 'ZNQBKG41LM'].includes(meta.mapped.model)) {
                await entity.write('aqaraOpple', {0x0203: {value: value ? 1 : 0, type: 0x10}}, manufacturerOptions.xiaomi);
            } else if (['ZNCZ11LM'].includes(meta.mapped.model)) {
                const payload = value ?
                    [0xaa, 0x80, 0x05, 0xd1, 0x47, 0x00, 0x03, 0x10, 0x00] :
                    [0xaa, 0x80, 0x05, 0xd1, 0x47, 0x01, 0x03, 0x10, 0x01];

                await entity.write('genBasic', {0xFFF0: {value: payload, type: 0x41}}, manufacturerOptions.xiaomi);
            } else {
                throw new Error('Not supported');
            }
            return {state: {led_disabled_night: value}};
        },
        convertGet: async (entity, key, meta) => {
            if (['ZNCZ04LM', 'ZNCZ12LM', 'ZNCZ15LM', 'QBCZ15LM', 'QBCZ14LM', 'QBKG19LM', 'QBKG20LM', 'QBKG25LM', 'QBKG26LM',
                'QBKG28LM', 'QBKG29LM', 'QBKG31LM', 'QBKG34LM', 'DLKZMK11LM', 'SSM-U01', 'WS-EUK01', 'WS-EUK02',
                'WS-EUK03', 'WS-EUK04', 'SP-EUC01', 'ZNQBKG24LM', 'ZNQBKG39LM', 'ZNQBKG40LM', 'ZNQBKG41LM'].includes(meta.mapped.model)) {
                await entity.read('aqaraOpple', [0x0203], manufacturerOptions.xiaomi);
            } else {
                throw new Error('Not supported');
            }
        },
    },
    
}; // PLEASE READ: THE END OF THE BLOCK THAT CAN BE DELETE WHEN MERGING WITH ToZigbee.js



const definition = {
    zigbeeModel: ['lumi.switch.acn054'], // The model ID from: Device with modelID 'lumi.sens' is not supported.
    model: 'ZNQBKG41LM', // 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 4 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, tz.xiaomi_flip_indicator_light, tzLocal.xiaomi_switch_power_outage_memory, tzLocal.xiaomi_led_disabled_night],
    endpoint: (device) => {
        return {'button_1': 1, 'button_2': 2, 'button_3': 3,  'button_4': 4};
    },
    meta: {multiEndpoint: true},
    exposes: [
        e.power(), e.voltage(), e.device_temperature(), e.flip_indicator_light(), e.power_outage_memory(),
        e.switch().withEndpoint('button_1'), e.switch().withEndpoint('button_2'), e.switch().withEndpoint('button_3'), e.switch().withEndpoint('button_4'),
        exposes.enum('operation_mode', ea.ALL, ['control_relay', 'decoupled'])
                .withDescription('Decoupled mode for button1 (Top) button')
                .withEndpoint('button_1'),
        exposes.enum('operation_mode', ea.ALL, ['control_relay', 'decoupled'])
                .withDescription('Decoupled mode for button 2 (Middle) button')
                .withEndpoint('button_2'),
        exposes.enum('operation_mode', ea.ALL, ['control_relay', 'decoupled'])
                .withDescription('Decoupled mode for button 3 (Buttom) button')
                .withEndpoint('button_3'),
                exposes.enum('operation_mode', ea.ALL, ['control_relay', 'decoupled'])
                .withDescription('Decoupled mode for button 4 (Buttom) button')
                .withEndpoint('button_4'),        
        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', 'button_2_single', 'button_2_double', 'button_3_single', 'button_3_double',
        			'button_4_single', 'button_4_double',
                    'button_1_button_2_single', 'button_1_button_2_double', 'button_1_button_3_single', 'button_1_button_3_double',
                    'button_2_button_3_single', 'button_2_button_3_double', 'all_single', 'all_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;

jomud9 avatar Jul 17 '23 13:07 jomud9

Hi can I check if support for this device is done?

djante17 avatar Aug 06 '23 05:08 djante17

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 7 days

github-actions[bot] avatar Sep 06 '23 00:09 github-actions[bot]

Hi, I just got this 3gang switch and it is unsupported in my Z2m. This topic is to add it to z2m?

wildchai avatar Sep 10 '23 07:09 wildchai

@jomud9 what issues are you still facing with the current ext converter? Regarding the missing actions, check if you see any "Recieved zigbee message" in the z2m debug log when triggering the action. If you don't see anything, this device doesn't support this action.

See https://www.zigbee2mqtt.io/guide/usage/debug.html on how to enable debug logging.

Koenkk avatar Sep 10 '23 07:09 Koenkk

Managed to get this loaded into Z2M and HA but there's a noticeable delay if using HA to activate the buttons. Physically pressing the buttons are quite responsive. This normal?

wildchai avatar Sep 11 '23 13:09 wildchai

please also support ZNQBKG41LM which is 4 gang switch thank u very much~

Is it working for your 4 gang?

wildchai avatar Sep 22 '23 08:09 wildchai

ZNQBKG41LM

zigbeeModel lumi.switch.acn055 instead of lumi.switch.acn054 For ZNQBKG41LM

Not Working Flip indicator light Power outage memory Click mode

Button 4 Operation mode - Not Working Single Click : OK Double Click - show single_button_4 Hold - show single_button_4

nickgoh avatar Oct 19 '23 05:10 nickgoh

Hi, I am not sure wether this is correct way to sniff the data btw the gateway & the switch. if this is the correct way i will sniff the other data as well .

power_outage_memory In aqara app there is 4 options

  1. Power-off memory ( After powering on, the device keep the previous state)
  2. Electric Appliance is power on after xxx ?? (not sure what it actually do, cant find any manual explaining)
  3. Electric Appliance is power off after xxx ??(not sure what it actually do,cant find any manual explaining)
  4. The on-off status is reverse. ( reverse power of the previous state )

1) Power-off memory ( After powering on, the device keep the previous state) Write Frame 2: 54 bytes on wire (432 bits), 54 bytes captured (432 bits) IEEE 802.15.4 Data, Dst: 0xeacb, Src: 0x0000 ZigBee Network Layer Data, Dst: 0xeacb, Src: 0x0000 ZigBee Application Support Layer Data, Dst Endpt: 1, Src Endpt: 1 Frame Control Field: Data (0x00) Destination Endpoint: 1 Cluster: Manufacturer Specific (0xfcc0) Profile: Home Automation (0x0104) Source Endpoint: 1 Counter: 166 ZigBee Cluster Library Frame, Mfr: Lumi United Techology, Ltd Shenzhen (0x115f), Command: Write Attributes, Seq: 111 Frame Control Field: Profile-wide (0x04) Manufacturer Code: Lumi United Techology, Ltd Shenzhen (0x115f) Sequence Number: 111 Command: Write Attributes (0x02) Attribute Field, Uint8: 1 Attribute: 0x0517 Data Type: 8-Bit Unsigned Integer (0x20) Uint8: 1 (0x01) Respond Frame 4: 51 bytes on wire (408 bits), 51 bytes captured (408 bits) IEEE 802.15.4 Data, Dst: 0x0000, Src: 0xeacb ZigBee Network Layer Data, Dst: 0x0000, Src: 0xeacb ZigBee Application Support Layer Data, Dst Endpt: 1, Src Endpt: 1 Frame Control Field: Data (0x00) Destination Endpoint: 1 Cluster: Manufacturer Specific (0xfcc0) Profile: Home Automation (0x0104) Source Endpoint: 1 Counter: 129 ZigBee Cluster Library Frame, Mfr: Lumi United Techology, Ltd Shenzhen (0x115f), Command: Write Attributes Response, Seq: 111 Frame Control Field: Profile-wide (0x1c) Manufacturer Code: Lumi United Techology, Ltd Shenzhen (0x115f) Sequence Number: 111 Command: Write Attributes Response (0x04) Status Record Status: Success (0x00)

2) Electric Appliance is power on after xxx ?? (not sure what it actually do) write Frame 14: 54 bytes on wire (432 bits), 54 bytes captured (432 bits) IEEE 802.15.4 Data, Dst: 0xeacb, Src: 0x0000 ZigBee Network Layer Data, Dst: 0xeacb, Src: 0x0000 ZigBee Application Support Layer Data, Dst Endpt: 1, Src Endpt: 1 Frame Control Field: Data (0x00) Destination Endpoint: 1 Cluster: Manufacturer Specific (0xfcc0) Profile: Home Automation (0x0104) Source Endpoint: 1 Counter: 167 ZigBee Cluster Library Frame, Mfr: Lumi United Techology, Ltd Shenzhen (0x115f), Command: Write Attributes, Seq: 112 Frame Control Field: Profile-wide (0x04) Manufacturer Code: Lumi United Techology, Ltd Shenzhen (0x115f) Sequence Number: 112 Command: Write Attributes (0x02) Attribute Field, Uint8: 0 Attribute: 0x0517 Data Type: 8-Bit Unsigned Integer (0x20) Uint8: 0 (0x00) respond Frame 16: 51 bytes on wire (408 bits), 51 bytes captured (408 bits) IEEE 802.15.4 Data, Dst: 0x0000, Src: 0xeacb ZigBee Network Layer Data, Dst: 0x0000, Src: 0xeacb ZigBee Application Support Layer Data, Dst Endpt: 1, Src Endpt: 1 Frame Control Field: Data (0x00) Destination Endpoint: 1 Cluster: Manufacturer Specific (0xfcc0) Profile: Home Automation (0x0104) Source Endpoint: 1 Counter: 131 ZigBee Cluster Library Frame, Mfr: Lumi United Techology, Ltd Shenzhen (0x115f), Command: Write Attributes Response, Seq: 112 Frame Control Field: Profile-wide (0x1c) Manufacturer Code: Lumi United Techology, Ltd Shenzhen (0x115f) Sequence Number: 112 Command: Write Attributes Response (0x04) Status Record Status: Success (0x00)

3) Electric Appliance is power off after xxx ??(not sure what it actually do) Frame 22: 54 bytes on wire (432 bits), 54 bytes captured (432 bits) IEEE 802.15.4 Data, Dst: 0xeacb, Src: 0x0000 ZigBee Network Layer Data, Dst: 0xeacb, Src: 0x0000 ZigBee Application Support Layer Data, Dst Endpt: 1, Src Endpt: 1 Frame Control Field: Data (0x00) Destination Endpoint: 1 Cluster: Manufacturer Specific (0xfcc0) Profile: Home Automation (0x0104) Source Endpoint: 1 Counter: 168 ZigBee Cluster Library Frame, Mfr: Lumi United Techology, Ltd Shenzhen (0x115f), Command: Write Attributes, Seq: 113 Frame Control Field: Profile-wide (0x04) Manufacturer Code: Lumi United Techology, Ltd Shenzhen (0x115f) Sequence Number: 113 Command: Write Attributes (0x02) Attribute Field, Uint8: 2 Attribute: 0x0517 Data Type: 8-Bit Unsigned Integer (0x20) Uint8: 2 (0x02) respond Frame 24: 51 bytes on wire (408 bits), 51 bytes captured (408 bits) IEEE 802.15.4 Data, Dst: 0x0000, Src: 0xeacb ZigBee Network Layer Data, Dst: 0x0000, Src: 0xeacb ZigBee Application Support Layer Data, Dst Endpt: 1, Src Endpt: 1 Frame Control Field: Data (0x00) Destination Endpoint: 1 Cluster: Manufacturer Specific (0xfcc0) Profile: Home Automation (0x0104) Source Endpoint: 1 Counter: 133 ZigBee Cluster Library Frame, Mfr: Lumi United Techology, Ltd Shenzhen (0x115f), Command: Write Attributes Response, Seq: 113 Frame Control Field: Profile-wide (0x1c) Manufacturer Code: Lumi United Techology, Ltd Shenzhen (0x115f) Sequence Number: 113 Command: Write Attributes Response (0x04) Status Record Status: Success (0x00)

4) The on-off status is reverse. ( reverse power of the previous state ) write Frame 33: 54 bytes on wire (432 bits), 54 bytes captured (432 bits) IEEE 802.15.4 Data, Dst: 0xeacb, Src: 0x0000 ZigBee Network Layer Data, Dst: 0xeacb, Src: 0x0000 ZigBee Application Support Layer Data, Dst Endpt: 1, Src Endpt: 1 Frame Control Field: Data (0x00) Destination Endpoint: 1 Cluster: Manufacturer Specific (0xfcc0) Profile: Home Automation (0x0104) Source Endpoint: 1 Counter: 169 ZigBee Cluster Library Frame, Mfr: Lumi United Techology, Ltd Shenzhen (0x115f), Command: Write Attributes, Seq: 114 Frame Control Field: Profile-wide (0x04) Manufacturer Code: Lumi United Techology, Ltd Shenzhen (0x115f) Sequence Number: 114 Command: Write Attributes (0x02) Attribute Field, Uint8: 3 Attribute: 0x0517 Data Type: 8-Bit Unsigned Integer (0x20) Uint8: 3 (0x03) respond Frame 35: 51 bytes on wire (408 bits), 51 bytes captured (408 bits) IEEE 802.15.4 Data, Dst: 0x0000, Src: 0xeacb ZigBee Network Layer Data, Dst: 0x0000, Src: 0xeacb ZigBee Application Support Layer Data, Dst Endpt: 1, Src Endpt: 1 Frame Control Field: Data (0x00) Destination Endpoint: 1 Cluster: Manufacturer Specific (0xfcc0) Profile: Home Automation (0x0104) Source Endpoint: 1 Counter: 135 ZigBee Cluster Library Frame, Mfr: Lumi United Techology, Ltd Shenzhen (0x115f), Command: Write Attributes Response, Seq: 114 Frame Control Field: Profile-wide (0x1c) Manufacturer Code: Lumi United Techology, Ltd Shenzhen (0x115f) Sequence Number: 114 Command: Write Attributes Response (0x04) Status Record Status: Success (0x00)

nickgoh avatar Oct 22 '23 09:10 nickgoh

Model ZNQBKG41LM

Tested on ZNQBKG41LM i only have a 4 button switch

power_outage_memory

  • on - Tested working (last power outage memory)
  • Inverted - Tested working (last power outage memory (inverted))
  • electric_appliances_on - not sure what it does
  • electric_appliances_off - not sure what it does

Click mode(Tested working) - only for button 4 ( Multi : 'button_4_single', 'button_4_double','button_4_hold', 'button_4_release') flip_indicator_light (removed) - as i cant find any settings in aqara app Decoupled mode for button 4 (removed) - button 4 is only a wireless switch without relay

issue : Lock Relay - (not working) in aqara app it will lock up physical button & app control button

External converter

//. Changlog 20230717 - first ver for ZNQBKG41LM
//. Starting from ZNQBKG39LM - https://github.com/Koenkk/zigbee2mqtt/issues/18082 
//. 
//. 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 (['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.acn055'], // The model ID from: Device with modelID 'lumi.sens' is not supported.
    model: 'ZNQBKG41LM', // 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 4 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, 'button_2': 2, 'button_3': 3,  'button_4': 4};
    },
    meta: {multiEndpoint: true},
    exposes: [
        e.power(), e.voltage(), e.device_temperature(),
        e.switch().withEndpoint('button_1'), e.switch().withEndpoint('button_2'), e.switch().withEndpoint('button_3'),
        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 button1 (Top) button')
                .withEndpoint('button_1'),
        exposes.enum('operation_mode', ea.ALL, ['control_relay', 'decoupled'])
                .withDescription('Decoupled mode for button 2 (Middle) button')
                .withEndpoint('button_2'),
        exposes.enum('operation_mode', ea.ALL, ['control_relay', 'decoupled'])
                .withDescription('Decoupled mode for button 3 (Buttom) button')
                .withEndpoint('button_3'),
        
        exposes.enum('lock_relay', ea.ALL, ['On', 'Off'])
                .withDescription('Lock Relay mode for button1 (Top) button')
                .withEndpoint('button_1'),
        exposes.enum('lock_relay', ea.ALL, ['On', 'Off'])
                .withDescription('Lock Relay for button 2 (Middle) button')
                .withEndpoint('button_2'),
        exposes.enum('lock_relay', ea.ALL, ['On', 'Off'])
                .withDescription('Lock Relay for button 3 (Buttom) button')
                .withEndpoint('button_3'),

                
                

        exposes.enum('click_mode', ea.ALL, ['fast', 'multi'])
                .withDescription('Click mode (Button 4 Only), fast: only supports single click which will be send immediately after clicking.' +
                    'multi: supports more events like double and hold'),

        e.action([
        			'button_4_single', 'button_4_double','button_4_hold', 'button_4_release',
                    ]),
    ],
    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;

nickgoh avatar Oct 25 '23 04:10 nickgoh

Hi, I am not sure wether this is correct way to sniff the data btw the gateway & the switch. if this is the correct way i will sniff the other data as well .

power_outage_memory In aqara app there is 4 options

  1. Power-off memory ( After powering on, the device keep the previous state)
  2. Electric Appliance is power on after xxx ?? (not sure what it actually do, cant find any manual explaining)
  3. Electric Appliance is power off after xxx ??(not sure what it actually do,cant find any manual explaining)
  4. The on-off status is reverse. ( reverse power of the previous state )

1) Power-off memory ( After powering on, the device keep the previous state) Write Frame 2: 54 bytes on wire (432 bits), 54 bytes captured (432 bits) IEEE 802.15.4 Data, Dst: 0xeacb, Src: 0x0000 ZigBee Network Layer Data, Dst: 0xeacb, Src: 0x0000 ZigBee Application Support Layer Data, Dst Endpt: 1, Src Endpt: 1 Frame Control Field: Data (0x00) Destination Endpoint: 1 Cluster: Manufacturer Specific (0xfcc0) Profile: Home Automation (0x0104) Source Endpoint: 1 Counter: 166 ZigBee Cluster Library Frame, Mfr: Lumi United Techology, Ltd Shenzhen (0x115f), Command: Write Attributes, Seq: 111 Frame Control Field: Profile-wide (0x04) Manufacturer Code: Lumi United Techology, Ltd Shenzhen (0x115f) Sequence Number: 111 Command: Write Attributes (0x02) Attribute Field, Uint8: 1 Attribute: 0x0517 Data Type: 8-Bit Unsigned Integer (0x20) Uint8: 1 (0x01) Respond Frame 4: 51 bytes on wire (408 bits), 51 bytes captured (408 bits) IEEE 802.15.4 Data, Dst: 0x0000, Src: 0xeacb ZigBee Network Layer Data, Dst: 0x0000, Src: 0xeacb ZigBee Application Support Layer Data, Dst Endpt: 1, Src Endpt: 1 Frame Control Field: Data (0x00) Destination Endpoint: 1 Cluster: Manufacturer Specific (0xfcc0) Profile: Home Automation (0x0104) Source Endpoint: 1 Counter: 129 ZigBee Cluster Library Frame, Mfr: Lumi United Techology, Ltd Shenzhen (0x115f), Command: Write Attributes Response, Seq: 111 Frame Control Field: Profile-wide (0x1c) Manufacturer Code: Lumi United Techology, Ltd Shenzhen (0x115f) Sequence Number: 111 Command: Write Attributes Response (0x04) Status Record Status: Success (0x00)

2) Electric Appliance is power on after xxx ?? (not sure what it actually do) write Frame 14: 54 bytes on wire (432 bits), 54 bytes captured (432 bits) IEEE 802.15.4 Data, Dst: 0xeacb, Src: 0x0000 ZigBee Network Layer Data, Dst: 0xeacb, Src: 0x0000 ZigBee Application Support Layer Data, Dst Endpt: 1, Src Endpt: 1 Frame Control Field: Data (0x00) Destination Endpoint: 1 Cluster: Manufacturer Specific (0xfcc0) Profile: Home Automation (0x0104) Source Endpoint: 1 Counter: 167 ZigBee Cluster Library Frame, Mfr: Lumi United Techology, Ltd Shenzhen (0x115f), Command: Write Attributes, Seq: 112 Frame Control Field: Profile-wide (0x04) Manufacturer Code: Lumi United Techology, Ltd Shenzhen (0x115f) Sequence Number: 112 Command: Write Attributes (0x02) Attribute Field, Uint8: 0 Attribute: 0x0517 Data Type: 8-Bit Unsigned Integer (0x20) Uint8: 0 (0x00) respond Frame 16: 51 bytes on wire (408 bits), 51 bytes captured (408 bits) IEEE 802.15.4 Data, Dst: 0x0000, Src: 0xeacb ZigBee Network Layer Data, Dst: 0x0000, Src: 0xeacb ZigBee Application Support Layer Data, Dst Endpt: 1, Src Endpt: 1 Frame Control Field: Data (0x00) Destination Endpoint: 1 Cluster: Manufacturer Specific (0xfcc0) Profile: Home Automation (0x0104) Source Endpoint: 1 Counter: 131 ZigBee Cluster Library Frame, Mfr: Lumi United Techology, Ltd Shenzhen (0x115f), Command: Write Attributes Response, Seq: 112 Frame Control Field: Profile-wide (0x1c) Manufacturer Code: Lumi United Techology, Ltd Shenzhen (0x115f) Sequence Number: 112 Command: Write Attributes Response (0x04) Status Record Status: Success (0x00)

3) Electric Appliance is power off after xxx ??(not sure what it actually do) Frame 22: 54 bytes on wire (432 bits), 54 bytes captured (432 bits) IEEE 802.15.4 Data, Dst: 0xeacb, Src: 0x0000 ZigBee Network Layer Data, Dst: 0xeacb, Src: 0x0000 ZigBee Application Support Layer Data, Dst Endpt: 1, Src Endpt: 1 Frame Control Field: Data (0x00) Destination Endpoint: 1 Cluster: Manufacturer Specific (0xfcc0) Profile: Home Automation (0x0104) Source Endpoint: 1 Counter: 168 ZigBee Cluster Library Frame, Mfr: Lumi United Techology, Ltd Shenzhen (0x115f), Command: Write Attributes, Seq: 113 Frame Control Field: Profile-wide (0x04) Manufacturer Code: Lumi United Techology, Ltd Shenzhen (0x115f) Sequence Number: 113 Command: Write Attributes (0x02) Attribute Field, Uint8: 2 Attribute: 0x0517 Data Type: 8-Bit Unsigned Integer (0x20) Uint8: 2 (0x02) respond Frame 24: 51 bytes on wire (408 bits), 51 bytes captured (408 bits) IEEE 802.15.4 Data, Dst: 0x0000, Src: 0xeacb ZigBee Network Layer Data, Dst: 0x0000, Src: 0xeacb ZigBee Application Support Layer Data, Dst Endpt: 1, Src Endpt: 1 Frame Control Field: Data (0x00) Destination Endpoint: 1 Cluster: Manufacturer Specific (0xfcc0) Profile: Home Automation (0x0104) Source Endpoint: 1 Counter: 133 ZigBee Cluster Library Frame, Mfr: Lumi United Techology, Ltd Shenzhen (0x115f), Command: Write Attributes Response, Seq: 113 Frame Control Field: Profile-wide (0x1c) Manufacturer Code: Lumi United Techology, Ltd Shenzhen (0x115f) Sequence Number: 113 Command: Write Attributes Response (0x04) Status Record Status: Success (0x00)

4) The on-off status is reverse. ( reverse power of the previous state ) write Frame 33: 54 bytes on wire (432 bits), 54 bytes captured (432 bits) IEEE 802.15.4 Data, Dst: 0xeacb, Src: 0x0000 ZigBee Network Layer Data, Dst: 0xeacb, Src: 0x0000 ZigBee Application Support Layer Data, Dst Endpt: 1, Src Endpt: 1 Frame Control Field: Data (0x00) Destination Endpoint: 1 Cluster: Manufacturer Specific (0xfcc0) Profile: Home Automation (0x0104) Source Endpoint: 1 Counter: 169 ZigBee Cluster Library Frame, Mfr: Lumi United Techology, Ltd Shenzhen (0x115f), Command: Write Attributes, Seq: 114 Frame Control Field: Profile-wide (0x04) Manufacturer Code: Lumi United Techology, Ltd Shenzhen (0x115f) Sequence Number: 114 Command: Write Attributes (0x02) Attribute Field, Uint8: 3 Attribute: 0x0517 Data Type: 8-Bit Unsigned Integer (0x20) Uint8: 3 (0x03) respond Frame 35: 51 bytes on wire (408 bits), 51 bytes captured (408 bits) IEEE 802.15.4 Data, Dst: 0x0000, Src: 0xeacb ZigBee Network Layer Data, Dst: 0x0000, Src: 0xeacb ZigBee Application Support Layer Data, Dst Endpt: 1, Src Endpt: 1 Frame Control Field: Data (0x00) Destination Endpoint: 1 Cluster: Manufacturer Specific (0xfcc0) Profile: Home Automation (0x0104) Source Endpoint: 1 Counter: 135 ZigBee Cluster Library Frame, Mfr: Lumi United Techology, Ltd Shenzhen (0x115f), Command: Write Attributes Response, Seq: 114 Frame Control Field: Profile-wide (0x1c) Manufacturer Code: Lumi United Techology, Ltd Shenzhen (0x115f) Sequence Number: 114 Command: Write Attributes Response (0x04) Status Record Status: Success (0x00)

Would you share your setup to inspire me to do a sniff on my side too?

jomud9 avatar Nov 24 '23 08:11 jomud9

Seems like an error with the converter recently, anybody else getting this error?

TypeError: Cannot read properties of undefined (reading 'options')

djante17 avatar Dec 02 '23 15:12 djante17

Model ZNQBKG41LM

Tested on ZNQBKG41LM i only have a 4 button switch

power_outage_memory

  • on - Tested working (last power outage memory)
  • Inverted - Tested working (last power outage memory (inverted))
  • electric_appliances_on - not sure what it does
  • electric_appliances_off - not sure what it does

Click mode(Tested working) - only for button 4 ( Multi : 'button_4_single', 'button_4_double','button_4_hold', 'button_4_release') flip_indicator_light (removed) - as i cant find any settings in aqara app Decoupled mode for button 4 (removed) - button 4 is only a wireless switch without relay

issue : Lock Relay - (not working) in aqara app it will lock up physical button & app control button

External converter

//. Changlog 20230717 - first ver for ZNQBKG41LM
//. Starting from ZNQBKG39LM - https://github.com/Koenkk/zigbee2mqtt/issues/18082 
//. 
//. 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 (['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.acn055'], // The model ID from: Device with modelID 'lumi.sens' is not supported.
    model: 'ZNQBKG41LM', // 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 4 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, 'button_2': 2, 'button_3': 3,  'button_4': 4};
    },
    meta: {multiEndpoint: true},
    exposes: [
        e.power(), e.voltage(), e.device_temperature(),
        e.switch().withEndpoint('button_1'), e.switch().withEndpoint('button_2'), e.switch().withEndpoint('button_3'),
        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 button1 (Top) button')
                .withEndpoint('button_1'),
        exposes.enum('operation_mode', ea.ALL, ['control_relay', 'decoupled'])
                .withDescription('Decoupled mode for button 2 (Middle) button')
                .withEndpoint('button_2'),
        exposes.enum('operation_mode', ea.ALL, ['control_relay', 'decoupled'])
                .withDescription('Decoupled mode for button 3 (Buttom) button')
                .withEndpoint('button_3'),
        
        exposes.enum('lock_relay', ea.ALL, ['On', 'Off'])
                .withDescription('Lock Relay mode for button1 (Top) button')
                .withEndpoint('button_1'),
        exposes.enum('lock_relay', ea.ALL, ['On', 'Off'])
                .withDescription('Lock Relay for button 2 (Middle) button')
                .withEndpoint('button_2'),
        exposes.enum('lock_relay', ea.ALL, ['On', 'Off'])
                .withDescription('Lock Relay for button 3 (Buttom) button')
                .withEndpoint('button_3'),

                
                

        exposes.enum('click_mode', ea.ALL, ['fast', 'multi'])
                .withDescription('Click mode (Button 4 Only), fast: only supports single click which will be send immediately after clicking.' +
                    'multi: supports more events like double and hold'),

        e.action([
        			'button_4_single', 'button_4_double','button_4_hold', 'button_4_release',
                    ]),
    ],
    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;

There is no button 4 exposed on my side when I use this as an external converter, is that right or I need to do something to fix it?

leeaash avatar Dec 04 '23 06:12 leeaash

Hi, I am not sure wether this is correct way to sniff the data btw the gateway & the switch. if this is the correct way i will sniff the other data as well . power_outage_memory In aqara app there is 4 options

  1. Power-off memory ( After powering on, the device keep the previous state)
  2. Electric Appliance is power on after xxx ?? (not sure what it actually do, cant find any manual explaining)
  3. Electric Appliance is power off after xxx ??(not sure what it actually do,cant find any manual explaining)
  4. The on-off status is reverse. ( reverse power of the previous state )

1) Power-off memory ( After powering on, the device keep the previous state) Write Frame 2: 54 bytes on wire (432 bits), 54 bytes captured (432 bits) IEEE 802.15.4 Data, Dst: 0xeacb, Src: 0x0000 ZigBee Network Layer Data, Dst: 0xeacb, Src: 0x0000 ZigBee Application Support Layer Data, Dst Endpt: 1, Src Endpt: 1 Frame Control Field: Data (0x00) Destination Endpoint: 1 Cluster: Manufacturer Specific (0xfcc0) Profile: Home Automation (0x0104) Source Endpoint: 1 Counter: 166 ZigBee Cluster Library Frame, Mfr: Lumi United Techology, Ltd Shenzhen (0x115f), Command: Write Attributes, Seq: 111 Frame Control Field: Profile-wide (0x04) Manufacturer Code: Lumi United Techology, Ltd Shenzhen (0x115f) Sequence Number: 111 Command: Write Attributes (0x02) Attribute Field, Uint8: 1 Attribute: 0x0517 Data Type: 8-Bit Unsigned Integer (0x20) Uint8: 1 (0x01) Respond Frame 4: 51 bytes on wire (408 bits), 51 bytes captured (408 bits) IEEE 802.15.4 Data, Dst: 0x0000, Src: 0xeacb ZigBee Network Layer Data, Dst: 0x0000, Src: 0xeacb ZigBee Application Support Layer Data, Dst Endpt: 1, Src Endpt: 1 Frame Control Field: Data (0x00) Destination Endpoint: 1 Cluster: Manufacturer Specific (0xfcc0) Profile: Home Automation (0x0104) Source Endpoint: 1 Counter: 129 ZigBee Cluster Library Frame, Mfr: Lumi United Techology, Ltd Shenzhen (0x115f), Command: Write Attributes Response, Seq: 111 Frame Control Field: Profile-wide (0x1c) Manufacturer Code: Lumi United Techology, Ltd Shenzhen (0x115f) Sequence Number: 111 Command: Write Attributes Response (0x04) Status Record Status: Success (0x00) 2) Electric Appliance is power on after xxx ?? (not sure what it actually do) write Frame 14: 54 bytes on wire (432 bits), 54 bytes captured (432 bits) IEEE 802.15.4 Data, Dst: 0xeacb, Src: 0x0000 ZigBee Network Layer Data, Dst: 0xeacb, Src: 0x0000 ZigBee Application Support Layer Data, Dst Endpt: 1, Src Endpt: 1 Frame Control Field: Data (0x00) Destination Endpoint: 1 Cluster: Manufacturer Specific (0xfcc0) Profile: Home Automation (0x0104) Source Endpoint: 1 Counter: 167 ZigBee Cluster Library Frame, Mfr: Lumi United Techology, Ltd Shenzhen (0x115f), Command: Write Attributes, Seq: 112 Frame Control Field: Profile-wide (0x04) Manufacturer Code: Lumi United Techology, Ltd Shenzhen (0x115f) Sequence Number: 112 Command: Write Attributes (0x02) Attribute Field, Uint8: 0 Attribute: 0x0517 Data Type: 8-Bit Unsigned Integer (0x20) Uint8: 0 (0x00) respond Frame 16: 51 bytes on wire (408 bits), 51 bytes captured (408 bits) IEEE 802.15.4 Data, Dst: 0x0000, Src: 0xeacb ZigBee Network Layer Data, Dst: 0x0000, Src: 0xeacb ZigBee Application Support Layer Data, Dst Endpt: 1, Src Endpt: 1 Frame Control Field: Data (0x00) Destination Endpoint: 1 Cluster: Manufacturer Specific (0xfcc0) Profile: Home Automation (0x0104) Source Endpoint: 1 Counter: 131 ZigBee Cluster Library Frame, Mfr: Lumi United Techology, Ltd Shenzhen (0x115f), Command: Write Attributes Response, Seq: 112 Frame Control Field: Profile-wide (0x1c) Manufacturer Code: Lumi United Techology, Ltd Shenzhen (0x115f) Sequence Number: 112 Command: Write Attributes Response (0x04) Status Record Status: Success (0x00) 3) Electric Appliance is power off after xxx ??(not sure what it actually do) Frame 22: 54 bytes on wire (432 bits), 54 bytes captured (432 bits) IEEE 802.15.4 Data, Dst: 0xeacb, Src: 0x0000 ZigBee Network Layer Data, Dst: 0xeacb, Src: 0x0000 ZigBee Application Support Layer Data, Dst Endpt: 1, Src Endpt: 1 Frame Control Field: Data (0x00) Destination Endpoint: 1 Cluster: Manufacturer Specific (0xfcc0) Profile: Home Automation (0x0104) Source Endpoint: 1 Counter: 168 ZigBee Cluster Library Frame, Mfr: Lumi United Techology, Ltd Shenzhen (0x115f), Command: Write Attributes, Seq: 113 Frame Control Field: Profile-wide (0x04) Manufacturer Code: Lumi United Techology, Ltd Shenzhen (0x115f) Sequence Number: 113 Command: Write Attributes (0x02) Attribute Field, Uint8: 2 Attribute: 0x0517 Data Type: 8-Bit Unsigned Integer (0x20) Uint8: 2 (0x02) respond Frame 24: 51 bytes on wire (408 bits), 51 bytes captured (408 bits) IEEE 802.15.4 Data, Dst: 0x0000, Src: 0xeacb ZigBee Network Layer Data, Dst: 0x0000, Src: 0xeacb ZigBee Application Support Layer Data, Dst Endpt: 1, Src Endpt: 1 Frame Control Field: Data (0x00) Destination Endpoint: 1 Cluster: Manufacturer Specific (0xfcc0) Profile: Home Automation (0x0104) Source Endpoint: 1 Counter: 133 ZigBee Cluster Library Frame, Mfr: Lumi United Techology, Ltd Shenzhen (0x115f), Command: Write Attributes Response, Seq: 113 Frame Control Field: Profile-wide (0x1c) Manufacturer Code: Lumi United Techology, Ltd Shenzhen (0x115f) Sequence Number: 113 Command: Write Attributes Response (0x04) Status Record Status: Success (0x00) 4) The on-off status is reverse. ( reverse power of the previous state ) write Frame 33: 54 bytes on wire (432 bits), 54 bytes captured (432 bits) IEEE 802.15.4 Data, Dst: 0xeacb, Src: 0x0000 ZigBee Network Layer Data, Dst: 0xeacb, Src: 0x0000 ZigBee Application Support Layer Data, Dst Endpt: 1, Src Endpt: 1 Frame Control Field: Data (0x00) Destination Endpoint: 1 Cluster: Manufacturer Specific (0xfcc0) Profile: Home Automation (0x0104) Source Endpoint: 1 Counter: 169 ZigBee Cluster Library Frame, Mfr: Lumi United Techology, Ltd Shenzhen (0x115f), Command: Write Attributes, Seq: 114 Frame Control Field: Profile-wide (0x04) Manufacturer Code: Lumi United Techology, Ltd Shenzhen (0x115f) Sequence Number: 114 Command: Write Attributes (0x02) Attribute Field, Uint8: 3 Attribute: 0x0517 Data Type: 8-Bit Unsigned Integer (0x20) Uint8: 3 (0x03) respond Frame 35: 51 bytes on wire (408 bits), 51 bytes captured (408 bits) IEEE 802.15.4 Data, Dst: 0x0000, Src: 0xeacb ZigBee Network Layer Data, Dst: 0x0000, Src: 0xeacb ZigBee Application Support Layer Data, Dst Endpt: 1, Src Endpt: 1 Frame Control Field: Data (0x00) Destination Endpoint: 1 Cluster: Manufacturer Specific (0xfcc0) Profile: Home Automation (0x0104) Source Endpoint: 1 Counter: 135 ZigBee Cluster Library Frame, Mfr: Lumi United Techology, Ltd Shenzhen (0x115f), Command: Write Attributes Response, Seq: 114 Frame Control Field: Profile-wide (0x1c) Manufacturer Code: Lumi United Techology, Ltd Shenzhen (0x115f) Sequence Number: 114 Command: Write Attributes Response (0x04) Status Record Status: Success (0x00)

Would you share your setup to inspire me to do a sniff on my side too?

Hi @jomud9 , i am following this guide for setting up

https://www.zigbee2mqtt.io/advanced/zigbee/04_sniff_zigbee_traffic.html#_3-sniffing-traffic https://www.zigbee2mqtt.io/guide/adapters/flashing/flashing_the_cc2531.html

nickgoh avatar Dec 04 '23 06:12 nickgoh

Seems like an error with the converter recently, anybody else getting this error?

TypeError: Cannot read properties of undefined (reading 'options')

Not sure very well, but my z2m unable to start after upgraded to 1.34-01, I rollback to 1.33 and it works

jomud9 avatar Dec 06 '23 04:12 jomud9

Seems like an error with the converter recently, anybody else getting this error? TypeError: Cannot read properties of undefined (reading 'options')

Not sure very well, but my z2m unable to start after upgraded to 1.34-01, I rollback to 1.33 and it works

I've investigated this and realize that the exception is thrown because 'fz.aqara_opple' is no longer supported in the zgbee herdsman converter package. I changed it to 'fz.aqara_opple_multistate' and they are all able to start now in 1.34. Im not exactly sure what aqara_opple_multistate or aqara_opple initially does though but it seems to work same as before now.

djante17 avatar Dec 06 '23 05:12 djante17

fz.aqara_opple -> xiaomi.fromZigbee.aqara_opple and make sure your converter has const xioami = require('zigbee-herdsman-converters/lib/xioami'); at the top

Koenkk avatar Dec 06 '23 18:12 Koenkk