-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlutron-status.js
55 lines (54 loc) · 1.66 KB
/
lutron-status.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
module.exports = function (RED) {
function LutronStatusNode(status) {
RED.nodes.createNode(this, status);
var configNode = RED.nodes.getNode(status.confignode);
this.devName = status.name;
this.devId = parseInt(configNode.deviceMap[this.devName]);
// register a callback on config node so that it can call this
// node
// then it will call the this.send(msg), msg = {payload: "hi"}
configNode.lutronEvent.on('data', (function (node, d) {
if (node.devId && node.devId !== 0) {
if (d.cmd === '~' && (d.type === 'DEVICE' || d.type === 'OUTPUT') &&
parseInt(d.deviceId) === node.devId) {
var value = parseInt(d.param);
var action = parseInt(d.action);
/*
for dimmer action is always 1
for pico action.param
FullOn => a=2, p=4
up => a=5, p=4
down => a=6 p=4
off => a=4, p=4
for on off switch
action =1 p=0 or 100
*/
if (action == '1') {
// either dimmre of switch
node.send({
payload: value
});
} else if (value === 4) {
var m = '';
if (action === 2)
m = 'on';
else if (action === 5)
m = 'up';
else if (action === 6)
m = 'down';
else if (action === 4)
m = 'off';
node.send({
payload: m
});
}
}
} else {
node.send({
payload: d
});
}
}).bind(null, this));
}
RED.nodes.registerType('lutron-status', LutronStatusNode);
}