-
Notifications
You must be signed in to change notification settings - Fork 30
/
Copy path19-hue_onair.js
76 lines (61 loc) · 1.91 KB
/
19-hue_onair.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
//
// Copyright (c) 2020 Cisco Systems
// Licensed under the MIT License
//
/*
* Turns red a designated Hue bulb when a call is in progress,
* and keep green when out of call.
*
* pre-req:
* - configure the macro with your Hue Bridge info and you're good to go.
* - configure your device for HttpClient
*
*/
const xapi = require('xapi');
//
// Hue Library
//
// ACTION: Update for your Philips Hue deployment
const HUE_BRIDGE = '192.168.1.33';
const HUE_USERNAME = 'EM2Vg2GtNUqAASukv47wm1pWY0FayFe48D03f6Cb';
const HUE_LIGHT = 1; // number of the light in your deployment
console.info(`Hue Bridge with ip: ${HUE_BRIDGE}, bulb: ${HUE_LIGHT}`);
const hue_url = `http://${HUE_BRIDGE}/api/${HUE_USERNAME}/lights/${HUE_LIGHT}/state`;
const COLOR_RED = { on: true, hue: 65535, sat: 255};
const COLOR_BLUE = { on: true, hue: 46920, sat: 255};
const COLOR_GREEN = { on: true, hue: 25500, sat: 255};
const COLOR_WHITE = { on: true, hue: 0, sat: 0};
const COLOR_BLACK = { on: false};
function changeColor(color) {
// Post message
xapi.command('HttpClient Put', {
Header: ["Content-Type: application/json"],
Url: hue_url,
AllowInsecureHTTPS: "True"
},
JSON.stringify(color))
.catch((err) => {
console.error('could not contact the Hue Bridge');
});
}
//
// Macro
//
xapi.on('ready', init);
function init() {
// Green at launch
changeColor(COLOR_GREEN);
// Listen to active calls and update color accordingly
xapi.status.on("SystemUnit State NumberOfActiveCalls", (activeCalls) => {
console.debug(`NumberOfActiveCalls is: ${activeCalls}`)
// Turn red if call in progress
if (activeCalls > 0) {
console.info('call in progress');
changeColor(COLOR_RED);
return;
}
// Turn green if out of call
console.log('no active call');
changeColor(COLOR_GREEN);
});
}