Skip to content

Commit

Permalink
Support ZNCZ02LM. Koenkk#4
Browse files Browse the repository at this point in the history
  • Loading branch information
Koenkk committed Apr 23, 2018
1 parent 54ca2dd commit c69f464
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 7 deletions.
26 changes: 25 additions & 1 deletion lib/converters/zigbee2mqtt.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@ const toPercentage = (value, min, max) => {
return (normalised * 100).toFixed(2);
}

const precisionRound = (number, precision) => {
const factor = Math.pow(10, precision);
return Math.round(number * factor) / factor;
}


// Global variable store that can be used by devices.
const store = {}

Expand Down Expand Up @@ -185,10 +191,22 @@ const parsers = [
};
}
},
{
devices: ['ZNCZ02LM'],
cid: 'genOnOff',
type: 'attReport',
convert: (msg) => {return {state: msg.data.data['onOff'] === 1 ? '{"state": "ON"}': '{"state": "OFF"}'}}
},
{
devices: ['ZNCZ02LM'],
cid: 'genAnalogInput',
type: 'attReport',
convert: (msg) => {return {power: precisionRound(msg.data.data['presentValue'], 2)}}
},

// Ignore parsers (these message dont need parsing).
{
devices: ['WXKG11LM', 'MCCGQ11LM', 'MCCGQ01LM', 'WXKG01LM', 'LED1545G12', '7146060PH', 'LED1537R6'],
devices: ['WXKG11LM', 'MCCGQ11LM', 'MCCGQ01LM', 'WXKG01LM', 'LED1545G12', '7146060PH', 'LED1537R6', 'ZNCZ02LM'],
cid: 'genOnOff',
type: 'devChange',
convert: () => null
Expand Down Expand Up @@ -229,6 +247,12 @@ const parsers = [
type: 'devChange',
convert: () => null
},
{
devices: ['ZNCZ02LM'],
cid: 'genAnalogInput',
type: 'devChange',
convert: () => null
},
];

module.exports = parsers;
7 changes: 7 additions & 0 deletions lib/devices.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,13 @@ const devices = {
supports: 'water leak true/false',
homeassistant: [homeassistant.binary_sensor_water_leak]
},
'lumi.plug': {
model: 'ZNCZ02LM',
description: 'Mi power plug ZigBee',
supports: 'on/off, power measurement',
vendor: 'Xiaomi',
homeassistant: [homeassistant.switch, homeassistant.sensor_power]
},

// IKEA
'TRADFRI bulb E27 WS opal 980lm': {
Expand Down
21 changes: 21 additions & 0 deletions lib/homeassistant.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,15 @@ const homeassistant = {
json_attributes: ['battery'],
}
},
'sensor_power': {
type: 'sensor',
object_id: 'power',
discovery_payload: {
unit_of_measurement: 'Watt',
icon: 'mdi:flash',
value_template: '{{ value_json.power }}',
}
},

// Light
'light_brightness_colortemp_xy': {
Expand All @@ -107,6 +116,18 @@ const homeassistant = {
command_topic: true
}
},

// Switch
'switch': {
type: 'switch',
object_id: 'switch',
discovery_payload: {
payload_off: '{"state": "OFF"}',
payload_on: '{"state": "ON"}',
value_template: '{{ value_json.state }}',
command_topic: true
}
},
};

module.exports = homeassistant;
6 changes: 0 additions & 6 deletions support/docgen.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,6 @@ const plannedToSupport = [
supports: '-',
vendor: 'Xiaomi',
},
{
model: 'ZNCZ02LM',
description: 'Mi power plug ZigBee',
supports: '-',
vendor: 'Xiaomi',
},
{
model: 'QBCZ11LM',
description: 'Aqara wall socket',
Expand Down

0 comments on commit c69f464

Please sign in to comment.