Text to a friend when the battery is low

Send a SMS to your (girl, boy) friend for saying 'I have no more battery...' for example

Inspired by :
Text my wife "I'm on my way" when I leave work
created by the on{X} team

To use this on{X} Recipe, simply copy the code below and modify if needed.

    // Initializing variables
    
    var message = "I have no more battery, see you !";
    var friend = { name: "michael", phoneNumber: "XXXXXXX" } ;
    
    // End of variables initializing
    
    // Console log writting
    console.log('Started script: Text ' + friend.name + ' \"' + message +  '\" when the battery reaches ' + '10%'); 
    
    // Triggers the function when the battery is low
    device.battery.on('low', function (signal){
        // Sending message
        console.log('Sending a text message \"' + message + '\" to ' + friend.name);
        device.messaging.sendSms({
            to: friend.phoneNumber,
            body: message
        },
            
        function (err) {
            if (err) {
                // Console error writting
                console.error('Error sending text messages: ' + JSON.stringify(err));
                device.notifications.createNotification('Battery at ' + currentPercent + '%. Could not text ' + friend.name + '.').show();
            }
        });
    });
    
    // Console log writting
    console.log('Completed script: Text ' + friend.name + ' \"' + message + '\" when the battery reaches ' + '10%');

Recipe Wall

1,195

Views