Low battery notifications?


(Brian Smith) #8

Yeah, this really needs to happen. With the amount of battery powered devices today, we need a more proactive approach.


(Michael) #9

There were a few sample SmartApps that alert you based upon a set threshold. I have one by Steve Meyers installed. Though these were removed from the sample list. Happy to share the code if you need it.


(Dan) #10

do you think something formal will be developed?


(Michael) #11

No clue but this app certainly meets my needs.


(Dan) #12

thanks! I am down, can you set the % at which you get notified? So I am new to ST and haven't done anything custom yet. Do i need to log into IDE and cut/paste code somewhere?


(Michael) #13

Yes you can set the percentage and it even has groups where you can set different thresholds for different devices. Again I didn't write it, Steve Meyers did and I just happen to have it installed.

Login to the online IDE, click My SmartApps, New SmartApp, click from Code and paste in the following:

/**
 *  Low Battery Alert
 *
 *  Author: Steve Meyers
 *  Date: 2015-02-06
 *    This app will poll selected devices that use a battery and send an alert when the level reaches a specified threshold.
 *    As written, this will:
 *        Poll on the 1st & 15th every month at 10AM
 *        Alert when the batteries are lower than 13%.
 */
definition(
    name: "Low Battery Alert",
    namespace: "",
    author: "Steve Meyers",
    description: "Alert if low battery",
    category: "Convenience",
    iconUrl: "http://www.stevemeyers.net/wp-content/uploads/2015/02/battery-60px.png",
    iconX2Url: "http://www.stevemeyers.net/wp-content/uploads/2015/02/battery-120px.png",
)

preferences {
    section("About") {
        paragraph "This app will poll selected devices that use a battery and send an alert when the level reaches a specified threshold."
        paragraph "You may configure up to four groups with different thresholds."
    }
    for (int i = 1; i <= 4; i++) {
        section("Monitoring group ${i}") {
            input "group_${i}", "capability.battery", title: "Select devices to monitor", multiple: true, required: false
            input "threshold_${i}", "number", title: "Notify if battery is below", defaultValue: 25
        }
    }
}

def installed() {
    log.debug "Installed with settings: ${settings}"
    initialize()
}

def updated() {
    log.debug "Updated with settings: ${settings}"
    unschedule()
    initialize()
}

def initialize() {
    //Second Minute Hour DayOfMonth Month DayOfWeek Year
    schedule("0 0 10am 1-31 * ?", check_batteries)
    check_batteries()
}

def check_batteries() {
    def size, batteries, device, threshold, value;

    for (int i = 1; i <= 4; i++) {
        size = settings["group_${i}"]?.size() ?: 0
        if (size > 0) {
            threshold = settings."threshold_${i}".toInteger()
            log.debug "Checking batteries for group ${i} (threshold ${threshold})"
            
            batteries = settings."group_${i}".currentValue("battery")
            for (int j = 0; j < size; j++) {
                  device = settings["group_${i}"][j]
                if (device != null) {
                    value = batteries[j]
                    if (value < threshold) {
                        log.debug "The $device battery is at ${value}, below threshold (${threshold})"
                        sendPush("The $device battery is at ${value}, below threshold (${threshold})")
                    } else {
                        log.debug "The $device battery is at ${value}"
                    }
                }
            }
        } else {
            log.debug "Group ${i} has no devices (${size})"
        }
    } 
}

(Dan) #14

Thank you!! Will this then show up as an app in my ST app? Will I be able to adjust the thresholds via the ST app or do I have to log into IDE and change it for each device?


(Greg) #15

This definitely feels like it should be out of the box functionality from ST. Or at the very least a fully published, available from the marketplace SmartApp. The above app looks like it does the trick. Perhaps this is the one.

As others have stated before, so many devices are battery powered now.


(Michael) #16

Yes one of the options is to set the thresholds when you setup the app. You have to install it into your account via online IDE and then once you install it on your mobile then you set the parameters like threshold.


(Michael) #17

Out of the box you do get a notification, at least I have gotten them at 25% (maybe). But some devices don't run through batteries that quickly so this additional app helps with a reminder at say 5% or whatever threshold you want.


(Dan) #18

How often does the app poll the device?


(Greg) #19

Looks like twice a month. "The 1st and 15th every month at 10am."


(Dan) #20

PS - thank you for this app!! This is perfect!


(Darren) #21

I'm not a coder/developer but I followed the instructions and was able to successfully copy the code above into my IDE and have it show up in my iOS app. The code comments say it is scheduled to check battery status on the 1st and 15th of every month. How to I tweak the code to change the schedule? Let's say to the 5th and 20th?


(Adam) #22

This is set in the initialize section with a cron format scheduling as shown in bold.

def initialize() {
//Second Minute Hour DayOfMonth Month DayOfWeek Year
schedule("0 0 10am 1-31 * ?", check_batteries)
check_batteries()
}

You can read about the cron format here and a helpful scheduling tool to generate the crontab can be found here.

I think the description of the code (runs on the 1st and 15th of every month) is incorrect for the actual schedule (run every day at 10 am).


#23

You need to remove the "am" from that line for the app to successfully work now.

schedule("0 0 10 1-31 * ?", check_batteries)

(Võ Thanh Minh) #24

Level 89% battery, However
-Montion Sensor is not active in long time.
-The system does not have any notifications

I think the system must know the problem.
Bad problem for ST


(Phil Pugh) #25

I have just tried to set this up to I get an unexpected error occured - where can i start to troubleshoot this?


(www.rboyapps.com - Make your home your butler!) #26

It could be a copy paste error or a temporary platform issue. If it’s the latter try after a few minutes. Did you see the modification from Adam/drshaw above regarding the am/PM correction?

If you have access to the RBoy Apps server you may want to check out this SmartApp:


(Phil Pugh) #27

It was exactly that, thanks RBoy. Removing the am from the code worked a treat