Skip to content

Commit

Permalink
Decoupled mode for Xiaomi wired wall switches (#287)
Browse files Browse the repository at this point in the history
  • Loading branch information
KapJI authored and Koenkk committed Feb 18, 2019
1 parent 2e1cecf commit cd8b293
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 4 deletions.
6 changes: 6 additions & 0 deletions converters/fromZigbee.js
Original file line number Diff line number Diff line change
Expand Up @@ -802,6 +802,8 @@ const converters = {
convert: (model, msg, publish, options) => {
if (msg.data.data['61440']) {
return {state: msg.data.data['onOff'] === 1 ? 'ON' : 'OFF'};
} else {
return {click: 'single'};
}
},
},
Expand All @@ -815,6 +817,10 @@ const converters = {
const payload = {};
payload[key] = msg.data.data['onOff'] === 1 ? 'ON' : 'OFF';
return payload;
} else {
const mapping = {4: 'left', 5: 'right', 6: 'both'};
const button = mapping[msg.endpoints[0].epId];
return {click: button};
}
},
},
Expand Down
46 changes: 46 additions & 0 deletions converters/toZigbee.js
Original file line number Diff line number Diff line change
Expand Up @@ -856,6 +856,52 @@ const converters = {
}
},
},
xiaomi_decoupled_mode: {
key: ['decoupled_mode'],
convert: (key, value, message, type, postfix) => {
const cid = 'genBasic';
const lookupAttrId = {
'single': 0xFF22,
'left': 0xFF22,
'right': 0xFF23,
};
const lookupState = {
'decoupled': 0xFE,
'toggle_left': 0x12,
'toggle_right': 0x22,
};
let button;
if (value.hasOwnProperty('button')) {
button = value.button;
} else {
button = 'single';
}
if (type === 'set') {
return {
cid: cid,
cmd: 'write',
cmdType: 'foundation',
zclData: [{
attrId: lookupAttrId[button],
dataType: 0x20,
attrData: lookupState[value.state],
}],
cfg: cfg.xiaomi,
};
} else if (type === 'get') {
return {
cid: cid,
cmd: 'read',
cmdType: 'foundation',
zclData: [{
attrId: lookupAttrId[button],
dataType: 0x20,
}],
cfg: cfg.xiaomi,
};
}
},
},
STS_PRS_251_beep: {
key: ['beep'],
convert: (key, value, message, type, postfix) => {
Expand Down
8 changes: 4 additions & 4 deletions devices.js
Original file line number Diff line number Diff line change
Expand Up @@ -212,9 +212,9 @@ const devices = [
fromZigbee: [
fz.QBKG04LM_QBKG11LM_state, fz.ignore_onoff_change, fz.ignore_basic_change, fz.ignore_basic_report,
],
toZigbee: [tz.on_off],
toZigbee: [tz.on_off, tz.xiaomi_decoupled_mode],
ep: (device) => {
return {'': 2};
return {'system': 1, 'default': 2};
},
},
{
Expand All @@ -238,9 +238,9 @@ const devices = [
fromZigbee: [
fz.QBKG03LM_QBKG12LM_state, fz.QBKG03LM_buttons, fz.ignore_basic_change, fz.ignore_basic_report,
],
toZigbee: [tz.on_off],
toZigbee: [tz.on_off, tz.xiaomi_decoupled_mode],
ep: (device) => {
return {'left': 2, 'right': 3};
return {'system': 1, 'left': 2, 'right': 3};
},
},
{
Expand Down

0 comments on commit cd8b293

Please sign in to comment.