# Smart Battery Monitor

**URL:** <https://community.smartthings.com/t/smart-battery-monitor/104667>\
**Category:** Community Created SmartApps\
**Tags:** wellness\_check\
**Created:** [November 9, 2017, 10:37pm UTC](https://community.smartthings.com/t/smart-battery-monitor/104667 "2017-11-09T22:37:57Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![themightypope](https://avatars.discourse-cdn.com/v4/letter/t/b77776/32.png) [@themightypope](https://community.smartthings.com/u/themightypope)\
**Post date:** [November 9, 2017, 10:37pm UTC](https://community.smartthings.com/t/smart-battery-monitor/104667/1 "2017-11-09T22:37:57Z")

</div>

My own version of a battery monitor that can warn a bit ahead of time.

> /\*\*
> 
> - Battery Monitor
> - 
> - Copyright 2014 Anders Heie
> - 
> - Licensed under the Apache License, Version 2.0 (the “License”); you may not use this file except
> - in compliance with the License. You may obtain a copy of the License at:
> - 
> - 
> 
> ```
> http://www.apache.org/licenses/LICENSE-2.0
> 
> ```
> 
> - 
> - Unless required by applicable law or agreed to in writing, software distributed under the License is distributed
> - on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License
> - for the specific language governing permissions and limitations under the License.
> - 
> 
> \*/  
> definition(  
> name: “Battery Monitor”,  
> namespace: “Pope”,  
> author: “Anders Heie”,  
> description: "Monitors all Battery levels and sends a notification if lower than a set threshold. A Button allows an immediate check. ",  
> category: “Convenience”,  
> iconUrl: “[https://s3.amazonaws.com/smartapp-icons/Convenience/Cat-Convenience.png](https://s3.amazonaws.com/smartapp-icons/Convenience/Cat-Convenience.png)”,  
> iconX2Url: “[https://s3.amazonaws.com/smartapp-icons/Convenience/Cat-Convenience@2x.png](https://s3.amazonaws.com/smartapp-icons/Convenience/Cat-Convenience@2x.png)”)
> 
> preferences {  
> section(“Battery Settings”) {  
> input “threshold”, “number”, title: “Alert when below…”, required: true  
> input “batteries”, “capability.battery”, title: “Which devices?”, multiple: true  
> input “theTime”, “time”, title: “Time to battery check every day”  
> }  
> }
> 
> def installed() {  
> log.debug “Installed with settings: ${settings}”  
> initialize()  
> }
> 
> def updated() {  
> log.debug “Updated with settings: ${settings}”  
> unschedule()  
> initialize()  
> }
> 
> def initialize() {
> 
> ```
> //schedule the job
> // http://docs.smartthings.com/en/latest/smartapp-developers-guide/scheduling.html
> schedule(theTime, doBatteryCheck)
> 
> //run at install too
> doBatteryCheck()
> 
> ```
> 
> }
> 
> def doBatteryCheck() {  
> log.debug “doBatteryCheck called at ${new Date()}”
> 
> ```
> def belowLevelCntr = 0
> 
> ```
> 
> def pushMsg = “”
> 
> for (batteryDevice in batteries) {  
> def batteryLevel = batteryDevice.currentValue(“battery”)  
> log.debug “${batteryDevice.name} ‘${batteryDevice.label}’ battery: ${batteryLevel}% versus alarm at ${settings.threshold}”  
> if ( batteryLevel \<= settings.threshold ) {  
> pushMsg += “${batteryDevice.name} ‘${batteryDevice.label}’ battery: ${batteryLevel}% \n”  
> belowLevelCntr++  
> }  
> }
> 
> ```
> if (belowLevelCntr ){
> pushMsg = "You have ${belowLevelCntr} devices below the set alarm level ${settings.threshold}% \n" + pushMsg
> 
> } else {
> pushMsg = "Battery Check App executed with no devices below ${settings.threshold}%"
> }
> 
> log.debug(pushMsg)
> 
> sendPush(pushMsg)
> 
> ```
> 
> }

---

<div class="post-metadata">

**Author:** ![logeox](https://yyz2.discourse-cdn.com/smartthings/user_avatar/community.smartthings.com/logeox/32/46650_2.png) [@logeox](https://community.smartthings.com/u/logeox)\
**Post date:** [November 10, 2017, 5:26pm UTC](https://community.smartthings.com/t/smart-battery-monitor/104667/2 "2017-11-10T17:26:26Z")

</div>

what makes this one different than the others?

---

<div class="post-metadata">

**Author:** ![themightypope](https://avatars.discourse-cdn.com/v4/letter/t/b77776/32.png) [@themightypope](https://community.smartthings.com/u/themightypope)\
**Post date:** [November 10, 2017, 5:43pm UTC](https://community.smartthings.com/t/smart-battery-monitor/104667/3 "2017-11-10T17:43:19Z")

</div>

I don’t know, I haven’t really look at any others. Just trying to share.

---

<div class="post-metadata">

**Author:** ![logeox](https://yyz2.discourse-cdn.com/smartthings/user_avatar/community.smartthings.com/logeox/32/46650_2.png) [@logeox](https://community.smartthings.com/u/logeox)\
**Post date:** [November 10, 2017, 8:55pm UTC](https://community.smartthings.com/t/smart-battery-monitor/104667/4 "2017-11-10T20:55:10Z")

</div>

Fair enough, just thought you had some improvements to an existing Battery Monitor.

---

<div class="post-metadata">

**Author:** ![Philippe\_Portes](https://yyz2.discourse-cdn.com/smartthings/user_avatar/community.smartthings.com/philippe_portes/32/67960_2.png) [@Philippe\_Portes](https://community.smartthings.com/u/Philippe_Portes)\
**Post date:** [November 11, 2017, 2:17am UTC](https://community.smartthings.com/t/smart-battery-monitor/104667/5 "2017-11-11T02:17:28Z")

</div>

That’s a nice idea to have an app for that except when sensors go from 100% to malfunctions just over night.  
This kind of apps makes sense with brand new sensors and batteries, but once you enter the vicious loop of Amazon ordered CR2450 by 20 every 3 or 4 months, you will realize that the only way to detect battery low is when:

1. sensors turn off-line
2. sensors have erratic behavior like reporting temperature but no longer open/close or acceleration.

Thanks for sharing though

---

<div class="post-metadata">

**Author:** ![themightypope](https://avatars.discourse-cdn.com/v4/letter/t/b77776/32.png) [@themightypope](https://community.smartthings.com/u/themightypope)\
**Post date:** [November 11, 2017, 3:59am UTC](https://community.smartthings.com/t/smart-battery-monitor/104667/6 "2017-11-11T03:59:40Z")

</div>

Yeah, malfunctions are harder to detect. Maybe the battery works, but no one opened the door for a week, which could look like a malfunction but it’s not. I really just wanted the switch batteries just BEFORE they run out, rather than get annoyed right AFTER they run out, so thus… this app… 🙂

---

<div class="post-metadata">

**Author:** ![dlloyd242](https://yyz2.discourse-cdn.com/smartthings/user_avatar/community.smartthings.com/dlloyd242/32/66900_2.png) [@dlloyd242](https://community.smartthings.com/u/dlloyd242)\
**Post date:** [January 15, 2019, 1:18pm UTC](https://community.smartthings.com/t/smart-battery-monitor/104667/7 "2019-01-15T13:18:54Z")

</div>

Getting an error when trying to install;

startup failed: script\_app\_metadata\_b6f999d6\_15c5\_422d\_ac29\_b5b91b163078: 13: unexpected token: Monitor1” @ line 13, column 16. name: “Battery Monitor1”, ^ 1 error

Any idea?
