Low Battery Alert Smart App

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.

Error when I was attempting to add this app to my IDE. Meta Data not found.

They have tightened the IDE since these have been written. If you add definitions to the beginning of the app you’ll be able to publish it. Something like this would do it:

definition(
name: “Low Battery Alert”,
namespace: “macstainless”,
author: “Aaron”,
description: “this app will poll chosen devices that use a battery and send an alert when it’s low”,
category: “My Apps”,
iconUrl: “https://s3.amazonaws.com/smartapp-icons/Convenience/Cat-Convenience.png”,
iconX2Url: “https://s3.amazonaws.com/smartapp-icons/Convenience/Cat-Convenience@2x.png”,
iconX3Url: “https://s3.amazonaws.com/smartapp-icons/Convenience/Cat-Convenience@2x.png”)

1 Like

Here is the updated code for everyone. Since this is from the old archived forums, I can’t edit my original post. Hope this helps!

/**

  • Battery Level Alert
  • Author: Aaron Crocco
  • Date: 2016-01-21
  • This app will poll chosen devices that use a battery and send an alert when it’s low.
  • As written, this will:
  •  Poll on the 1st & 15th every month at 10AM
    
  •  Alert when the batteries are lower than 13%.
    

*/

// Automatically generated. Make future change here.
definition(
name: “Battery Level Alert”,
namespace: “macstainless”,
author: "aaron@aaroncrocco.com",
description: “Check the battery level for all things and send an alert. Check happens on 1st and 15th each month at 10 AM.”,
category: “My Apps”,
iconUrl: “https://s3.amazonaws.com/smartapp-icons/Convenience/Cat-Convenience.png”,
iconX2Url: “https://s3.amazonaws.com/smartapp-icons/Convenience/Cat-Convenience%402x.png”,
iconX3Url: “https://s3.amazonaws.com/smartapp-icons/Convenience/Cat-Convenience%402x.png”)

preferences {
section(“Moniter battery level on…”) {
input “batteryDevices”, “capability.battery”, title: “Which?”, multiple: true
}
}

def installed() {
log.debug "Installed with settings: ${settings}"
subscribe (batteryDevices, “battDevs”, batteryThings)
initialize()
}

def updated() {
log.debug "Updated with settings: ${settings}"
unsubscribe()
subscribe (batteryDevices, “battDevs”, batteryThings)
initialize()
}

def initialize() {

//Schedule a check of the battery at 10am on the 1st and 15th days of the month
schedule("0 0 10am 1,15 * ?", runIn(60, checkBattery))

}

def checkBattery() {

//Gets the current battry level

log.debug "checking batteries"
def battery = batteryDevices.currentValue("battery")      
def whichDevice
def x=0

while (x < 50) {
	if (battery[x] < 13) {
    	whichDevice = batteryDevices[x]
        if (whichDevice != null) {
        	log.debug "The $whichDevice battery is low"
            sendPush("The $whichDevice battery is low.")
		}
    }   
    x=x+1
} 

}

def batteryDevices (evt) { }

2 Likes

@macstainless

I tried this, but it doesn’t like the time/date format that is being used for schedule()

Never mind. If you get rid of the AM it works.