Low battery notifications?

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


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.

do you think something formal will be developed?

No clue but this app certainly meets my needs.

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?

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%.
    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}"

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

def initialize() {
    //Second Minute Hour DayOfMonth Month DayOfWeek Year
    schedule("0 0 10am 1-31 * ?", 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})"

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?

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.

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.

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.

How often does the app poll the device?

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

1 Like

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

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?

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)

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).

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

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

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

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

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:

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

1 Like