Low Battery Alert Smart App

It only seems to work with “smartthings” devices and not with all devices that use battery.

the (configurable) is an alternate device type SmartThings has for it. It allows you to turn on or off the different sensors from within the app, or IDE.

Great app though btw, I feel like this should had been built in from the start.

Thanks Cory. I actually thought this WAS already built into SmartThings. It’s only because the battery is dead on one of my presence tags did I realize that’s not the case.

As for non-SmartThings devices, if anyone knows how to poll them for the battery level then adding it in should work. I simply poll the devices for their battery status and get an integer result in an array.

I think I have something. I’ll dig through my notes/code and get back to you.

Twack

1 Like

Something that will list out like this too?

battery list pic

1 Like

I’ll have some time this weekend to get something out.

@macstainless,

I thought I had something the grabbed all the devices so you don’t have to pick, but I didn’t. Here is battery checker that I hacked just to see if it would grab non-ST devices and it does. I then looked again at your code and it’s essentially the same. So why your not getting the non-ST device battery level while I am is a mystery to me.

Anyway, here is the code that I did to test. Run it and see what the diff’s are between it and your stuff. Let me know if there are diff’s and I’ll dig deeper.

Twack

/**
 *  Battery Tester
 *
 */
preferences {
	section("Battery Alarm Level") {
		input "alarmAt", "number", title: "Alert when below...", required: true
        input "batteryDevices", "capability.battery", title: "Which devices?", multiple: true
	}
}

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

	initialize()
}

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

	initialize()
}

def initialize() {
	
    //schedule the job
    schedule("0 0 10am 1,15 * ?", doBatteryCheck)
    
    //run at install too
    doBatteryCheck()
    
}

def doBatteryCheck() {

	def belowLevelCntr = 0
    
    def pushMsg = ""
    
	for (batteryDevice in batteryDevices) {
    
    	def batteryLevel = batteryDevice.currentValue("battery")

        if ( batteryLevel <= settings.alarmAt.toInteger() ) {
			
            pushMsg += "${batteryDevice.name} named ${batteryDevice.label} is at: ${batteryLevel}% \n"
            
            belowLevelCntr++
        }
    }
    
    if ( belowLevelCntr ){
    
    	pushMsg = "You have ${belowLevelCntr} devices below the set alarm level. \n" + pushMsg
    
    } else {
    	
        pushMsg = "Battery Check App executed with no devices below alarm level"
    }
    
    log.debug(pushMsg)
    
    sendPush(pushMsg)
}
1 Like

Hi guys,
Thanks for posting this code. I just tried it out in my system and it works great except it doesn’t seem to find all my non-ST devices. It discovers my Aeon Multisensor, but not my Aeon Recessed Door/Window Sensors. When I check my list of devices, battery status is not listed as one of the states for those. The Aeon documentation says that battery level is reported through the ZWave Battery Command Class. I’m new to this platform, so would appreciate any help on implementing that.

John

Detects all of my devices, although I only have 2 that are not SmartThings branded. Thanks for the code!

The door-window sensor device file does not appear to have the battery status reporting coded into it. In looking at the Aeon docs, the device does have the capability to do it. You should submit a support ticket to add the battery reporting status for the door/window contact sensor. Once ST implements that, the app will report it.

HTH,
Twack

@macstainless, I’m trying to use your Dark Weather app but don’t have a moisture sensor. Anyway you could make this work with SmartWeather tile as well? Thanks

HI @RichardH. Sorry I never saw this reply to me until just now! Were you able to get Dark Weather working? I haven’t updated the code at all but one simple workaround is to make the weather sensor input optional. The WU call will easily do the rest. I happen to have a virtual weather center tile (prior build to the SmartWeather tile) that I called things from. Let me know.

Hi I know it’s a while since you published this but what does def batteryDevices (evt) { } do?

@dreais Honestly, I probably put that there for my own reference in case I wanted to add to the app later on. Sloppy coding on my part. My guess is you can take it out and the app should run fine. Sorry!

Thanks a million @macstainless. No problem, I’m new to all this so just wanted to double-check!

Tried installing today. it recognized all of my devices which are mix of schlage, ecolink, aeon, smartthings, linear and others. I get the app up on my iphone but when I hit save, it says failed to save: default page. Any thoughts?

Same thing here…when trying to set it up I get ‘Failed to Save: Default Page’ in the red banner at the top. Any suggestions?

This is exactly what I am looking for… do you have this up on github?

Not sure why it’s giving that error, but the code is above at the top of this thread. Feel free to tinker.

Within initialize, delay the checkBattery using this line:
runIn(60, checkBattery)

instead of checkBattery()

sendPush works fine after the app is initialized.