definition( name: "PowerSensor", namespace: "mschilli", author: "Mike Schilli", description: "Subscribe and detect", category: "Convenience") preferences { section("Device") { input "power", "capability.contactSensor", required: true } } def installed() { initialize() } def updated() { initialize() } def initialize() { unsubscribe() subscribe(power, "contact", evthandler) } def evthandler(evt) { if(power.currentContact == "closed") { log.debug "Power back!" } else { log.debug "Power outage!" } }