Script turns on bluetooth when incoming or outgoing call is detected. Also keeps it on for 60 seconds.
To use this on{X} Recipe, simply copy the code below and modify if needed.
console.log('Started Script:' + device.currentSource);
if (!(device.version && device.version.isSupported(0, 54))) {
var notification = device.notifications.createNotification('on{X} is out of date');
notification.content = "the recipe '" + device.currentSource + "' requires an up to date on{X} application.";
notification.show();
}
else {
device.telephony.on('outgoingCall', function (signal)
{
device.scheduler.removeTimer("turnOffBluetooth");
device.bluetooth.enabled = (state == 'true');
}
);
device.telephony.on('incomingCall', function (signal)
{
device.scheduler.removeTimer("turnOffBluetooth");
device.bluetooth.enabled = (state == 'true');
}
);
device.telephony.on('idle', function (signal)
{
var now = new Date();
device.scheduler.setTimer({
name: "turnOffBluetooth",
time: now.getTime() + 60000,
exact: false },
function () {
device.bluetooth.enabled = (state == 'false');
});
}
);
}
console.log('Completed Script:' + device.currentSource);
Views