Skip to content

Commit

Permalink
Add A9MEM1570 Schneider PowerTag (Koenkk#4082)
Browse files Browse the repository at this point in the history
* Support for Schneider PowerTag

* Update fromZigbee.js

* Update schneider_electric.js

Co-authored-by: Koen Kanters <[email protected]>
  • Loading branch information
filips and Koenkk authored Apr 6, 2022
1 parent 990c0ba commit 3f1e9fe
Showing 1 changed file with 71 additions and 0 deletions.
71 changes: 71 additions & 0 deletions devices/schneider_electric.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const tz = require('../converters/toZigbee');
const constants = require('../lib/constants');
const reporting = require('../lib/reporting');
const extend = require('../lib/extend');
const utils = require('../lib/utils');
const e = exposes.presets;
const ea = exposes.access;

Expand All @@ -17,6 +18,67 @@ const tzLocal = {
},
};

const fzLocal = {
schneider_powertag: {
cluster: 'greenPower',
type: ['commandNotification', 'commandCommisioningNotification'],
convert: async (model, msg, publish, options, meta) => {
if (msg.type !== 'commandNotification') {
return;
}

const commandID = msg.data.commandID;
if (utils.hasAlreadyProcessedMessage(msg, msg.data.frameCounter, `${msg.device.ieeeAddr}_${commandID}`)) return;

const rxAfterTx = (msg.data.options & (1<<11));
const ret = {};

switch (commandID) {
case 0xA1:
Object.entries(msg.data.commandFrame.attributes).forEach(([attr, val]) => {
switch (attr) {
case 'totalActivePower':
ret['power'] = val;
break;
case 'currentSummDelivered':
ret['energy'] = ((parseInt(val[0]) << 32) + parseInt(val[1])) / 1000.0;
break;
}
});

break;
case 0xA3:
// Should handle this cluster as well
break;
}

if (rxAfterTx) {
// Send Schneider specific ACK to make PowerTag happy
const networkParameters = await msg.device.zh.getNetworkParameters();
const payload = {
options: 0b000,
tempMaster: msg.data.gppNwkAddr,
tempMasterTx: networkParameters.channel - 11,
srcID: msg.data.srcID,
gpdCmd: 0xFE,
gpdPayload: {
commandID: 0xFE,
buffer: Buffer.alloc(1), // I hope it's zero initialised
},
};

await msg.endpoint.commandResponse('greenPower', 'response', payload,
{
srcEndpoint: 242,
disableDefaultResponse: true,
});
}

return ret;
},
},
};

module.exports = [
{
zigbeeModel: ['PUCK/SHUTTER/1'],
Expand Down Expand Up @@ -714,4 +776,13 @@ module.exports = [
await reporting.onOff(endpoint2);
},
},
{
fingerprint: [{modelID: 'GreenPower_254', ieeeAddr: /^0x00000000e.......$/}],
model: 'A9MEM1570',
vendor: 'Schneider Electric',
description: 'PowerTag power sensor',
fromZigbee: [fzLocal.schneider_powertag],
toZigbee: [],
exposes: [e.power(), e.energy()],
},
];

0 comments on commit 3f1e9fe

Please sign in to comment.