-
Notifications
You must be signed in to change notification settings - Fork 1
/
sms_notify_battery.js
42 lines (34 loc) · 1.04 KB
/
sms_notify_battery.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
// Used example from onx.ms message wife when leaving work.
// Author: Kelly Mahan
// Description: Message my wife when my bettery gets low.
// Not fully tested but i think this will work
// Initializing variables
var friend = { name : "my wife", number: "01234567890"} ;
var messageText = "My battery is about to die.";
var message_sent = false;
var plugged_in = false;
var low_bat = 10;
// End of variables initializing
function send_message(){
device.messaging.sendSms({
to: friend.number,
body: messageText
},
function (err) {
console.log(err || 'sms was sent successfully');
}
);
}
device.battery.on("startedCharging", function (signal){
plugged_in = true;
message_sent = false;
});
device.battery.on("stoppedCharging", function (signal){
plugged_in = false;
});
device.battery.on('updated', function (signal){
if(signal.percentage < low_bat && !message_sent && !plugged_in){
send_message();
message_sent = true;
}
});