From 567bdca27647f434d4fe00120b1a4567b36a811e Mon Sep 17 00:00:00 2001 From: Diogo Gomes Date: Mon, 21 May 2018 12:21:18 +0100 Subject: [PATCH] Edp redy - Power Plug (#53) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fixed json * added mqtt commands * added endpoints * support battery status * added firmware for CC2531 USB Stick with maximum number of possible devices (48) * support aqara magnet * added support for wall switch * update regex * Update README.md * added automatic chip selection * fix reconnect * Update README.md * added missing dependency * fix magnets * fix topic * support for aqara button * yaml based configuration * restore project defaults * save bridgeID * default values Don’t change the configured bridgeID (backward compatible with bridgeID = “bridge”) * personal configuration * added EDP RE:DY * don't mess remote * don't mess remote * don't mess remote * fix * clean * lint * generic * lint * Update devices.js * Update zigbee2mqtt.js * lint * Refactor configure reports. * Fix lint. --- lib/controller.js | 23 ++++++++++++++++++++++- lib/converters/zigbee2mqtt.js | 15 +++++++++++++++ lib/devices.js | 16 ++++++++++++++++ lib/homeassistant.js | 1 + lib/zigbee.js | 17 +++++++++++++++++ 5 files changed, 71 insertions(+), 1 deletion(-) diff --git a/lib/controller.js b/lib/controller.js index 5f352f554..8edbfa3fa 100644 --- a/lib/controller.js +++ b/lib/controller.js @@ -21,6 +21,7 @@ class Controller { this.zigbee = new Zigbee(); this.mqtt = new MQTT(); this.stateCache = {}; + this.configuredReport = []; this.handleZigbeeMessage = this.handleZigbeeMessage.bind(this); this.handleMQTTMessage = this.handleMQTTMessage.bind(this); } @@ -33,7 +34,10 @@ class Controller { // Log zigbee clients on startup. const devices = this.zigbee.getAllClients(); logger.info(`Currently ${devices.length} devices are joined:`); - devices.forEach((device) => logger.info(this.getDeviceStartupLogMessage(device))); + devices.forEach((device) => { + logger.info(this.getDeviceStartupLogMessage(device)); + this.configureDevice(device); + }); // Connect to MQTT broker const subscriptions = [ @@ -123,6 +127,20 @@ class Controller { this.zigbee.stop(callback); } + configureDevice(device) { + // Configure reporting for this device. + const ieeeAddr = device.ieeeAddr; + if (ieeeAddr && device.modelId && !this.configuredReport.includes(ieeeAddr)) { + const mappedModel = deviceMapping[device.modelId]; + + if (mappedModel && mappedModel.report) { + this.zigbee.configureReport(ieeeAddr, mappedModel.report); + } + + this.configuredReport.push(ieeeAddr); + } + } + getDeviceStartupLogMessage(device) { let friendlyName = 'unknown'; let friendlyDevice = {model: 'unkown', description: 'unknown'}; @@ -184,6 +202,9 @@ class Controller { return; } + // Configure device. + this.configureDevice(device); + // Home Assistant MQTT discovery if (settings.get().homeassistant) { homeassistant.discover(device.ieeeAddr, mappedModel.model, this.mqtt); diff --git a/lib/converters/zigbee2mqtt.js b/lib/converters/zigbee2mqtt.js index 64ab51bb5..b0e8c899d 100644 --- a/lib/converters/zigbee2mqtt.js +++ b/lib/converters/zigbee2mqtt.js @@ -360,6 +360,14 @@ const parsers = [ return {smoke: msg.data.zoneStatus === 1}; }, }, + { + devices: ['PLUG EDP RE:DY'], + cid: 'seMetering', + type: 'attReport', + convert: (msg) => { + return {power: precisionRound(msg.data.data['instantaneousDemand'], 2)}; + }, + }, { devices: ['CC2530.ROUTER'], cid: 'genOnOff', @@ -387,6 +395,7 @@ const parsers = [ devices: [ 'WXKG11LM', 'MCCGQ11LM', 'MCCGQ01LM', 'WXKG01LM', 'LED1545G12', '7146060PH', 'LED1537R6', 'ZNCZ02LM', 'QBCZ11LM', 'QBKG04LM', 'QBKG03LM', 'LED1623G12', 'LED1650R5', 'LED1536G5', 'F7C033', 'LED1622G12', + 'PLUG EDP RE:DY', ], cid: 'genOnOff', type: 'devChange', @@ -449,6 +458,12 @@ const parsers = [ type: 'devChange', convert: () => null, }, + { + devices: ['PLUG EDP RE:DY'], + cid: 'seMetering', + type: 'devChange', + convert: () => null, + }, ]; module.exports = parsers; diff --git a/lib/devices.js b/lib/devices.js index 6604aaaca..553d33387 100644 --- a/lib/devices.js +++ b/lib/devices.js @@ -167,6 +167,22 @@ const devices = { supports: 'on/off, brightness', }, + // EDP + 'ZB-SmartPlug-1.0.0': { + model: 'PLUG EDP RE:DY', + vendor: 'EDP', + description: 'Plug EDP re:dy', + supports: 'on/off, power measurement', + report: [{ + 'cid': 'seMetering', + 'attr': 'instantaneousDemand', + 'ep': 85, + 'minInt': 10, + 'maxInt': 60, + 'repChange': 1, + }], + }, + // Texax Instruments 'lumi.router': { model: 'CC2530.ROUTER', diff --git a/lib/homeassistant.js b/lib/homeassistant.js index d3f42d78d..baf7175e0 100644 --- a/lib/homeassistant.js +++ b/lib/homeassistant.js @@ -222,6 +222,7 @@ const mapping = { '7146060PH': [configurations.light_brightness_colortemp_xy], 'F7C033': [configurations.light_brightness], 'JTYJ-GD-01LM/BW': [configurations.binary_sensor_smoke], + 'PLUG EDP RE:DY': [configurations.switch, configurations.sensor_power], 'CC2530.ROUTER': [configurations.binary_sensor_router], }; diff --git a/lib/zigbee.js b/lib/zigbee.js index 13dcd811e..59d94ebc4 100644 --- a/lib/zigbee.js +++ b/lib/zigbee.js @@ -109,6 +109,23 @@ class Zigbee { } } + configureReport(ieeeAddr, reports) { + reports.forEach((r) => { + const device = this.shepherd.find(ieeeAddr, r.ep); + if (device) { + device.report(r.cid, r.attr, r.minInt, r.maxInt, r.repChange, (error) => { + if (error) { + logger.warn(`Failed to configure reporting for ${ieeeAddr} ${r.cid} ${r.attr}`); + } else { + logger.info(`Configured reporting for ${ieeeAddr} ${r.cid} ${r.attr}`); + } + }); + } else { + logger.warn(`Failed to configure reporting for ${ieeeAddr} ${r.cid} ${r.attr} (device not found)`); + } + }); + } + getDevice(deviceID) { return this.shepherd.list().find((d) => d.ieeeAddr === deviceID); }