This is awesome! Power is Out based on state of v1 Motion Sensor


(Convinced ST will never be unbroken…) #1

Here in the Sierra, power outages are a way of life. They can be caused by heavy rain or wind, ice and snow, or some flatlander thinking he can drive his shiny new 4WD on icy/snowy mountain roads the same way he does in the city.

Didn’t even know this capability existed… thanks Jesse Ziegler!

/**
 *  Power Is Out
 *
 *  Copyright 2014 Jesse Ziegler
 *
 */

definition(
    name: "Power Is Out",
    namespace: "smartthings",
    author: "Jesse Ziegler",
    description: "Alert me of power loss using motion detector's change from wired-power to battery-power. SmartThings hub and internet connection must be working! You can connect the hub and internet connection device (e.g. modem, router, etc.) to a battery backup power strip so that the motion detector and detect the loss and the hub and router will still have enough power to get the message out before they fail as well.",
    category: "Safety & Security",
    iconUrl: "https://s3.amazonaws.com/smartapp-icons/Convenience/Cat-Convenience.png",
    iconX2Url: "https://s3.amazonaws.com/smartapp-icons/Convenience/Cat-Convenience@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

	}
}

def installed() {
	subscribe(motion1, "powerSource.battery", onBatteryPowerHandler)
    subscribe(motion1, "powerSource.powered", PoweredPowerHandler)
}

def updated() {
	unsubscribe()
	subscribe(motion1, "powerSource.battery", onBatteryPowerHandler)
    subscribe(motion1, "powerSource.powered", PoweredPowerHandler)
}


def onBatteryPowerHandler(evt) {
	log.trace "$evt.value: $evt"
	def msg = "${motion1.label ?: motion1.name} sensed Power is Out!"
    
	log.debug "sending push for power is out"
	sendPush(msg)
    
    if ( phone1 && pushAndPhone ) {
    	log.debug "sending SMS to ${phone1}"
   	sendSms(phone1, msg)
	}
}

def PoweredPowerHandler(evt) {
	log.trace "$evt.value: $evt"
	def msg = "${motion1.label ?: motion1.name} sensed Power is Back On!"
    
	log.debug "sending push for power is back on"
	sendPush(msg)
    
    if ( phone1 && pushAndPhone ) {
    	log.debug "sending SMS to ${phone1}"
    	sendSms(phone1, msg)
	}
}

Power Outage Notification
A sensor to detect if a device is powered on?
Aeon Energy Switch to Alarm if Freezer Loses Power?
Alert electrical power off
Samsung Smartthings Motion Sensor randomly goes off
How to get an alert in case of power outage/failure?
[BETA v0515] Hampton Bay Zigbee Ceiling Fan/Light Controller
Power Outage App Possibility?
ST Motion V1 - logging warning
(Ian D) #2

Is it just for me or while the switch to battery power is detected immediately, it can take several minutes before the switch to AC is detected? I’m using the app with the first generation SmartSense Motion Sensor that can be USB powered.


(Convinced ST will never be unbroken…) #3

I am not seeing this. Just tested it and it took longer to report the outage than the restoration. Guessing it just depends on smartthings latency at the moment.


(Ian D) #4

You’re right, I’ve just experienced the same thing. Thanks!


(Wayne) #5

Nice, which motion sensor is this for? I am looking for a notification when power is out, and restored.


#6

The Original SmartThings motion sensor, also called v1. Sold in the Shop on this site.

It’s unusual because it can be powered via USB or battery. So the code posted above detected when it switched from one to another. Kind of like those emergency flashlights that you plug into a receptacle and that shift to battery and turn bright when there’s no longer power to draw from.

However at present this can only work if there’s still power to the wifi and the ST hub.


(Convinced ST will never be unbroken…) #7

BTW… if you’re using smart lamps like Hue or GE Link, you may want to turn them off when power is restored (as they will all come on). If so there is an updated version of this SmartApp on my web site that will do this and more.

http://soletc.com/SmartThings


(Wayne) #8

@JDRoberts, thanks I’ll grab one.

@scottinpollock, thanks. That is exactly the use case I was looking for. I’ll grab your app.


(Greg) #9

So what are the chances with hub v2 that we can monitor loss of power with the hub going to battery power?

And upon restoration fix all our smart bulbs?


#10

Does anyone know if this app still works with the new v2 motion sensor?


(Convinced ST will never be unbroken…) #11

No, as they removed the ability to plug in power.


(Fast, Good, Cheap...pick two.) #12

I’ve got the V1 motion sensor with 120v and have not been successful in getting this app to work.

When my power goes out and comes back on all my G.E. bulbs come on and the app tied to the sensir just doesn’t cut them off.

I never did troubleshoot why as there has been too many other things to fix lately.


(Convinced ST will never be unbroken…) #13

Do you at least get a notification?


(Fast, Good, Cheap...pick two.) #14

No sir

Edit:

Is this still true?..if so that’s why it doesn’t work for me.

To be fair, I’m not sure I’ve applied the app / logic correctly in that I do not have a ham bridge.

I’ve got a V1 motion sensor and have my lights set to cut off on power restore.

I’ll follow up here with some screen shots.


#15

This hasn’t worked for me in some time. The power flickered the other night and my bedroom lights all turned on. I waited for Alexa to boot back up and told her to turn them back off.


(Fast, Good, Cheap...pick two.) #16

Fancy! :smile:

What if it happens while you’re gone though? I’ve only had that happen once, but still, seems silly there isn’t an easy solve.


#17

I’d like to know if this app could be retrofitted to work with an Aeon Labs Home Energy Monitor (v1) device since it has battery power and hard wired power. I have my modem/router/smartthings hub on UPS, so I would be able to still get the notifications. See here:

Maybe I will try my hand at it by modifying this somewhat old smartapp. I’m just not sure if the same events (powerSource.battery and powerSource.powered) are the same for the HEM v1… but maybe I can find some similar events in documentation?


(Convinced ST will never be unbroken…) #18

I just tested here and it’s broken. What do you want to bet someone at SmartThings removed the powerSource event from the default deviceType!? If that turns out to be the case, it is pretty distressing to hear that operational aspects of SmartThings own legacy devices are so quickly (and silently) wiped of the surface of the planet.


(Convinced ST will never be unbroken…) #19

Actually, my v1 motion sensor is still linked to the correct ‘SmartSense Motion’ deviceType… the event is just not being sent anymore.

So… off to support I go.


(Dan) #20

I just submitted a support ticket also. I will be extremely disappointed if this functionality has been deprecated. I specifically bought a V1 motion detector for use with the power alert app (slightly modified).