2 * Low Battery Notification
8 namespace: "com.sudarkoff",
9 author: "George Sudarkoff",
10 description: "Notify when battery charge drops below the specified level.",
11 category: "Convenience",
12 iconUrl: "https://s3.amazonaws.com/smartapp-icons/Convenience/Cat-Convenience.png",
13 iconX2Url: "https://s3.amazonaws.com/smartapp-icons/Convenience/Cat-Convenience%402x.png"
17 section ("When battery change in these devices") {
18 input "devices", "capability.battery", title:"Battery Operated Devices", multiple: true
20 section ("Drops below this level") {
21 input "level", "number", title:"Battery Level (%)"
24 input "sendPushMessage", "bool", title: "Send a push notification?", required: false
25 input "phone", "phone", title: "Send a Text Message?", required: false
39 if (level < 5 || level > 90) {
40 sendPush("Battery level should be between 5 and 90 percent")
43 subscribe(devices, "battery", batteryHandler)
45 state.lowBattNoticeSent = [:]
49 def batteryHandler(evt) {
53 private send(message) {
55 sendSms(phone, message)
57 if (sendPushMessage) {
62 private updateBatteryStatus() {
63 for (device in devices) {
64 if (device.currentBattery < level) {
65 if (!state.lowBattNoticeSent.containsKey(device.id)) {
66 send("${device.displayName}'s battery is at ${device.currentBattery}%.")
68 state.lowBattNoticeSent[(device.id)] = true
71 if (state.lowBattNoticeSent.containsKey(device.id)) {
72 state.lowBattNoticeSent.remove(device.id)