I used an app written by Scottin Pollock. I canât remember if I edited it or not.
/**
- Power Failure
-
- Copyright 2014 Scottin Pollock
-
*/
definition(
name: âPower Failureâ,
namespace: âdpvorsterâ,
author: âScottin Pollockâ,
description: "Notify me of power failure and restoration using motion detectorâs change from wired-power to battery-power, and optionally manipulate lights and send a HAM Bridge Command. ",
category: âMy Appsâ,
iconUrl: âhttp://solutionsetcetera.com/stuff/STIcons/powerFailure.pngâ,
iconX2Url: âhttp://solutionsetcetera.com/stuff/STIcons/powerFailure@2x.pngâ
)
preferences {
section(âWhen there is wired-power loss onâŠâ) {
input âmotion1â, âcapability.motionSensorâ, title: âWhere?â
}
section(âVia a push notification and a text message(optional)â){
input âpushAndPhoneâ, âenumâ, title: âSend Text?â, required: false, metadata: [values: [âYesâ,âNoâ]]
input âphone1â, âphoneâ, title: âPhone Number (for Text, optional)â, required: false
}
section(âMake changes to the following when powered is restoredâŠâ){
input âoffSwitchesâ, âcapability.switchâ, title: âTurn these offâ, required: false, multiple: true
input âonSwitchesâ, âcapability.switchâ, title: âTurn these on if after sunsetâ, required: false, multiple: true
}
}
def installed() {
init()
}
def updated() {
unsubscribe()
init()
}
def init() {
subscribe(motion1, âpowerSource.batteryâ, powerOff)
subscribe(motion1, âpowerSource.poweredâ, powerOn)
}
def powerOff(evt) {
def msg = âA Power Failure has Just Occurred!â
log.debug "sending push for power is out"
sendPush(msg)
if ( phone1 && pushAndPhone ) {
log.debug "sending SMS to ${phone1}"
sendSms(phone1, msg)
}
}
def powerOn(evt) {
def msg = âThe Power has Been Restored!â
log.debug "sending push for power is back on"
sendPush(msg)
if ( phone1 && pushAndPhone ) {
log.debug "sending SMS to ${phone1}"
sendSms(phone1, msg)
}
if ( offSwitches ) {
log.debug "killing Hues"
offSwitches.off()
}
if ( onSwitches ) {
log.debug "restoring Hues"
def ss = getSunriseAndSunset()
def now = new Date()
def dark = ss.sunset
if ( dark.before(now) ) {
onSwitches.on()
}
}
}