Skip to content

Commit

Permalink
Update STS_PRS_251. Koenkk/zigbee2mqtt#459
Browse files Browse the repository at this point in the history
  • Loading branch information
Koenkk committed Oct 25, 2018
1 parent 11f367e commit e34299e
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 6 deletions.
22 changes: 19 additions & 3 deletions converters/fromZigbee.js
Original file line number Diff line number Diff line change
Expand Up @@ -785,8 +785,8 @@ const converters = {
cid: 'genBinaryInput',
type: 'attReport',
convert: (model, msg, publish, options) => {
// After 100 seconds of no report, publish presence: false
const timeout = 100 * 10000;
const useOptionsTimeout = options && options.hasOwnProperty('presence_timeout');
const timeout = useOptionsTimeout ? options.presence_timeout : 100; // 100 seconds by default
const deviceID = msg.endpoints[0].device.ieeeAddr;

// Stop existing timer because presence is detected and set a new one.
Expand All @@ -798,11 +798,27 @@ const converters = {
store[deviceID] = setTimeout(() => {
publish({presence: false});
store[deviceID] = null;
}, timeout);
}, timeout * 1000);

return {presence: true};
},
},
STS_PRS_251_battery: {
cid: 'genPowerCfg',
type: 'attReport',
convert: (model, msg, publish, options) => {
const voltage = msg.data.data['batteryVoltage'] * 100;

for (let i = 0; i < voltageMap.length; i++) {
if (voltageMap[i][0] > voltage) {
return {
battery: voltageMap[i][1].toFixed(2),
voltage: voltage,
};
}
}
},
},
_324131092621_on: {
cid: 'genOnOff',
type: 'cmdOn',
Expand Down
18 changes: 18 additions & 0 deletions converters/toZigbee.js
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,24 @@ const converters = {
};
},
},
STS_PRS_251_beep: {
key: 'beep',
attr: ['identifyTime'],
convert: (value, message) => {
return {
cid: 'genIdentify',
cmd: 'identify',
type: 'functional',
zclData: {
identifytime: value,
},
cfg: {
manufSpec: 0,
disDefaultRsp: 0,
},
};
},
},
// Ignore converters
ignore_transition: {
key: 'transition',
Expand Down
6 changes: 3 additions & 3 deletions devices.js
Original file line number Diff line number Diff line change
Expand Up @@ -1271,13 +1271,13 @@ const devices = [
vendor: 'SmartThings',
description: 'SmartThings arrival sensor',
supports: 'presence',
fromZigbee: [fz.STS_PRS_251_presence],
toZigbee: [],
fromZigbee: [fz.STS_PRS_251_presence, fz.STS_PRS_251_battery],
toZigbee: [tz.STS_PRS_251_beep],
configure: (ieeeAddr, shepherd, coordinator, callback) => {
const device = shepherd.find(ieeeAddr, 1);
const actions = [
(cb) => device.report('genBinaryInput', 'presentValue', 10, 30, 1, cb),
(cb) => device.report('genPowerCfg', 'batteryVoltage', 10, 3600),
(cb) => device.report('genPowerCfg', 'batteryVoltage', 1800, 3600),
];

execute(device, actions, callback);
Expand Down

0 comments on commit e34299e

Please sign in to comment.