Compare commits

..

1 Commits

Author SHA1 Message Date
박혜진
b7f4d9e1d3 MSA-991: test 2016-03-23 02:41:50 -05:00
3 changed files with 417 additions and 417 deletions

View File

@@ -1,254 +1,254 @@
/** /**
* Copyright 2015 SmartThings * Copyright 2015 SmartThings
* *
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except * 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: * in compliance with the License. You may obtain a copy of the License at:
* *
* http://www.apache.org/licenses/LICENSE-2.0 * 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 * 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 * 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. * for the specific language governing permissions and limitations under the License.
* *
* Aeon RGBW LED Bulb * Aeon RGBW LED Bulb
* *
* Author: SmartThings * Author: SmartThings
* Date: 2015-7-12 * Date: 2015-7-12
*/ */
metadata { metadata {
definition (name: "Aeon LED Bulb", namespace: "smartthings", author: "SmartThings") { definition (name: "Aeon LED Bulb", namespace: "smartthings", author: "SmartThings") {
capability "Switch Level" capability "Switch Level"
capability "Color Control" capability "Color Control"
capability "Color Temperature" capability "Color Temperature"
capability "Switch" capability "Switch"
capability "Refresh" capability "Refresh"
capability "Actuator" capability "Actuator"
capability "Sensor" capability "Sensor"
command "reset" command "reset"
fingerprint inClusters: "0x26,0x33,0x98" fingerprint inClusters: "0x26,0x33,0x98"
fingerprint deviceId: "0x11", inClusters: "0x98,0x33" fingerprint deviceId: "0x11", inClusters: "0x98,0x33"
fingerprint deviceId: "0x1102", inClusters: "0x98" fingerprint deviceId: "0x1102", inClusters: "0x98"
} }
simulator { simulator {
} }
standardTile("switch", "device.switch", width: 1, height: 1, canChangeIcon: true) { standardTile("switch", "device.switch", width: 1, height: 1, canChangeIcon: true) {
state "on", label:'${name}', action:"switch.off", icon:"st.lights.philips.hue-single", backgroundColor:"#79b821", nextState:"turningOff" state "on", label:'${name}', action:"switch.off", icon:"st.lights.philips.hue-single", backgroundColor:"#79b821", nextState:"turningOff"
state "off", label:'${name}', action:"switch.on", icon:"st.lights.philips.hue-single", backgroundColor:"#ffffff", nextState:"turningOn" state "off", label:'${name}', action:"switch.on", icon:"st.lights.philips.hue-single", backgroundColor:"#ffffff", nextState:"turningOn"
state "turningOn", label:'${name}', action:"switch.off", icon:"st.lights.philips.hue-single", backgroundColor:"#79b821", nextState:"turningOff" state "turningOn", label:'${name}', action:"switch.off", icon:"st.lights.philips.hue-single", backgroundColor:"#79b821", nextState:"turningOff"
state "turningOff", label:'${name}', action:"switch.on", icon:"st.lights.philips.hue-single", backgroundColor:"#ffffff", nextState:"turningOn" state "turningOff", label:'${name}', action:"switch.on", icon:"st.lights.philips.hue-single", backgroundColor:"#ffffff", nextState:"turningOn"
} }
standardTile("reset", "device.reset", inactiveLabel: false, decoration: "flat") { standardTile("reset", "device.reset", inactiveLabel: false, decoration: "flat") {
state "default", label:"Reset Color", action:"reset", icon:"st.lights.philips.hue-single" state "default", label:"Reset Color", action:"reset", icon:"st.lights.philips.hue-single"
} }
standardTile("refresh", "device.switch", inactiveLabel: false, decoration: "flat") { standardTile("refresh", "device.switch", inactiveLabel: false, decoration: "flat") {
state "default", label:"", action:"refresh.refresh", icon:"st.secondary.refresh" state "default", label:"", action:"refresh.refresh", icon:"st.secondary.refresh"
} }
controlTile("levelSliderControl", "device.level", "slider", height: 1, width: 2, inactiveLabel: false, range:"(0..100)") { controlTile("levelSliderControl", "device.level", "slider", height: 1, width: 2, inactiveLabel: false, range:"(0..100)") {
state "level", action:"switch level.setLevel" state "level", action:"switch level.setLevel"
} }
controlTile("rgbSelector", "device.color", "color", height: 3, width: 3, inactiveLabel: false) { controlTile("rgbSelector", "device.color", "color", height: 3, width: 3, inactiveLabel: false) {
state "color", action:"setColor" state "color", action:"setColor"
} }
valueTile("level", "device.level", inactiveLabel: false, decoration: "flat") { valueTile("level", "device.level", inactiveLabel: false, decoration: "flat") {
state "level", label: 'Level ${currentValue}%' state "level", label: 'Level ${currentValue}%'
} }
controlTile("colorTempControl", "device.colorTemperature", "slider", height: 1, width: 2, inactiveLabel: false) { controlTile("colorTempControl", "device.colorTemperature", "slider", height: 1, width: 2, inactiveLabel: false) {
state "colorTemperature", action:"setColorTemperature" state "colorTemperature", action:"setColorTemperature"
} }
valueTile("hue", "device.hue", inactiveLabel: false, decoration: "flat") { valueTile("hue", "device.hue", inactiveLabel: false, decoration: "flat") {
state "hue", label: 'Hue ${currentValue} ' state "hue", label: 'Hue ${currentValue} '
} }
main(["switch"]) main(["switch"])
details(["switch", "levelSliderControl", "rgbSelector", "reset", "colorTempControl", "refresh"]) details(["switch", "levelSliderControl", "rgbSelector", "reset", "colorTempControl", "refresh"])
} }
def updated() { def updated() {
response(refresh()) response(refresh())
} }
def parse(description) { def parse(description) {
def result = null def result = null
if (description.startsWith("Err 106")) { if (description.startsWith("Err 106")) {
state.sec = 0 state.sec = 0
} else if (description != "updated") { } else if (description != "updated") {
def cmd = zwave.parse(description, [0x20: 1, 0x26: 3, 0x70: 1, 0x33:3]) def cmd = zwave.parse(description, [0x20: 1, 0x26: 3, 0x70: 1, 0x33:3])
if (cmd) { if (cmd) {
result = zwaveEvent(cmd) result = zwaveEvent(cmd)
log.debug("'$description' parsed to $result") log.debug("'$description' parsed to $result")
} else { } else {
log.debug("Couldn't zwave.parse '$description'") log.debug("Couldn't zwave.parse '$description'")
} }
} }
result result
} }
def zwaveEvent(physicalgraph.zwave.commands.basicv1.BasicReport cmd) { def zwaveEvent(physicalgraph.zwave.commands.basicv1.BasicReport cmd) {
dimmerEvents(cmd) dimmerEvents(cmd)
} }
def zwaveEvent(physicalgraph.zwave.commands.basicv1.BasicSet cmd) { def zwaveEvent(physicalgraph.zwave.commands.basicv1.BasicSet cmd) {
dimmerEvents(cmd) dimmerEvents(cmd)
} }
def zwaveEvent(physicalgraph.zwave.commands.switchmultilevelv3.SwitchMultilevelReport cmd) { def zwaveEvent(physicalgraph.zwave.commands.switchmultilevelv3.SwitchMultilevelReport cmd) {
dimmerEvents(cmd) dimmerEvents(cmd)
} }
private dimmerEvents(physicalgraph.zwave.Command cmd) { private dimmerEvents(physicalgraph.zwave.Command cmd) {
def value = (cmd.value ? "on" : "off") def value = (cmd.value ? "on" : "off")
def result = [createEvent(name: "switch", value: value, descriptionText: "$device.displayName was turned $value")] def result = [createEvent(name: "switch", value: value, descriptionText: "$device.displayName was turned $value")]
if (cmd.value) { if (cmd.value) {
result << createEvent(name: "level", value: cmd.value, unit: "%") result << createEvent(name: "level", value: cmd.value, unit: "%")
} }
return result return result
} }
def zwaveEvent(physicalgraph.zwave.commands.hailv1.Hail cmd) { def zwaveEvent(physicalgraph.zwave.commands.hailv1.Hail cmd) {
response(command(zwave.switchMultilevelV1.switchMultilevelGet())) response(command(zwave.switchMultilevelV1.switchMultilevelGet()))
} }
def zwaveEvent(physicalgraph.zwave.commands.securityv1.SecurityMessageEncapsulation cmd) { def zwaveEvent(physicalgraph.zwave.commands.securityv1.SecurityMessageEncapsulation cmd) {
def encapsulatedCommand = cmd.encapsulatedCommand([0x20: 1, 0x84: 1]) def encapsulatedCommand = cmd.encapsulatedCommand([0x20: 1, 0x84: 1])
if (encapsulatedCommand) { if (encapsulatedCommand) {
state.sec = 1 state.sec = 1
def result = zwaveEvent(encapsulatedCommand) def result = zwaveEvent(encapsulatedCommand)
result = result.collect { result = result.collect {
if (it instanceof physicalgraph.device.HubAction && !it.toString().startsWith("9881")) { if (it instanceof physicalgraph.device.HubAction && !it.toString().startsWith("9881")) {
response(cmd.CMD + "00" + it.toString()) response(cmd.CMD + "00" + it.toString())
} else { } else {
it it
} }
} }
result result
} }
} }
def zwaveEvent(physicalgraph.zwave.Command cmd) { def zwaveEvent(physicalgraph.zwave.Command cmd) {
def linkText = device.label ?: device.name def linkText = device.label ?: device.name
[linkText: linkText, descriptionText: "$linkText: $cmd", displayed: false] [linkText: linkText, descriptionText: "$linkText: $cmd", displayed: false]
} }
def on() { def on() {
command(zwave.basicV1.basicSet(value: 0xFF)) command(zwave.basicV1.basicSet(value: 0xFF))
} }
def off() { def off() {
command(zwave.basicV1.basicSet(value: 0x00)) command(zwave.basicV1.basicSet(value: 0x00))
} }
def setLevel(level) { def setLevel(level) {
setLevel(level, 1) setLevel(level, 1)
} }
def setLevel(level, duration) { def setLevel(level, duration) {
if(level > 99) level = 99 if(level > 99) level = 99
command(zwave.switchMultilevelV3.switchMultilevelSet(value: level, dimmingDuration: duration)) command(zwave.switchMultilevelV3.switchMultilevelSet(value: level, dimmingDuration: duration))
} }
def refresh() { def refresh() {
commands([ commands([
zwave.switchMultilevelV1.switchMultilevelGet(), zwave.switchMultilevelV1.switchMultilevelGet(),
], 1000) ], 1000)
} }
def setSaturation(percent) { def setSaturation(percent) {
log.debug "setSaturation($percent)" log.debug "setSaturation($percent)"
setColor(saturation: percent) setColor(saturation: percent)
} }
def setHue(value) { def setHue(value) {
log.debug "setHue($value)" log.debug "setHue($value)"
setColor(hue: value) setColor(hue: value)
} }
def setColor(value) { def setColor(value) {
def result = [] def result = []
log.debug "setColor: ${value}" log.debug "setColor: ${value}"
if (value.hex) { if (value.hex) {
def c = value.hex.findAll(/[0-9a-fA-F]{2}/).collect { Integer.parseInt(it, 16) } def c = value.hex.findAll(/[0-9a-fA-F]{2}/).collect { Integer.parseInt(it, 16) }
result << zwave.switchColorV3.switchColorSet(red:c[0], green:c[1], blue:c[2], warmWhite:0, coldWhite:0) result << zwave.switchColorV3.switchColorSet(red:c[0], green:c[1], blue:c[2], warmWhite:0, coldWhite:0)
} else { } else {
def hue = value.hue ?: device.currentValue("hue") def hue = value.hue ?: device.currentValue("hue")
def saturation = value.saturation ?: device.currentValue("saturation") def saturation = value.saturation ?: device.currentValue("saturation")
if(hue == null) hue = 13 if(hue == null) hue = 13
if(saturation == null) saturation = 13 if(saturation == null) saturation = 13
def rgb = huesatToRGB(hue, saturation) def rgb = huesatToRGB(hue, saturation)
result << zwave.switchColorV3.switchColorSet(red: rgb[0], green: rgb[1], blue: rgb[2], warmWhite:0, coldWhite:0) result << zwave.switchColorV3.switchColorSet(red: rgb[0], green: rgb[1], blue: rgb[2], warmWhite:0, coldWhite:0)
} }
if(value.hue) sendEvent(name: "hue", value: value.hue) if(value.hue) sendEvent(name: "hue", value: value.hue)
if(value.hex) sendEvent(name: "color", value: value.hex) if(value.hex) sendEvent(name: "color", value: value.hex)
if(value.switch) sendEvent(name: "switch", value: value.switch) if(value.switch) sendEvent(name: "switch", value: value.switch)
if(value.saturation) sendEvent(name: "saturation", value: value.saturation) if(value.saturation) sendEvent(name: "saturation", value: value.saturation)
commands(result) commands(result)
} }
def setColorTemperature(percent) { def setColorTemperature(percent) {
if(percent > 99) percent = 99 if(percent > 99) percent = 99
int warmValue = percent * 255 / 99 int warmValue = percent * 255 / 99
command(zwave.switchColorV3.switchColorSet(red:0, green:0, blue:0, warmWhite:warmValue, coldWhite:(255 - warmValue))) command(zwave.switchColorV3.switchColorSet(red:0, green:0, blue:0, warmWhite:warmValue, coldWhite:(255 - warmValue)))
} }
def reset() { def reset() {
log.debug "reset()" log.debug "reset()"
sendEvent(name: "color", value: "#ffffff") sendEvent(name: "color", value: "#ffffff")
setColorTemperature(99) setColorTemperature(99)
} }
private command(physicalgraph.zwave.Command cmd) { private command(physicalgraph.zwave.Command cmd) {
if (state.sec != 0) { if (state.sec != 0) {
zwave.securityV1.securityMessageEncapsulation().encapsulate(cmd).format() zwave.securityV1.securityMessageEncapsulation().encapsulate(cmd).format()
} else { } else {
cmd.format() cmd.format()
} }
} }
private commands(commands, delay=200) { private commands(commands, delay=200) {
delayBetween(commands.collect{ command(it) }, delay) delayBetween(commands.collect{ command(it) }, delay)
} }
def rgbToHSV(red, green, blue) { def rgbToHSV(red, green, blue) {
float r = red / 255f float r = red / 255f
float g = green / 255f float g = green / 255f
float b = blue / 255f float b = blue / 255f
float max = [r, g, b].max() float max = [r, g, b].max()
float delta = max - [r, g, b].min() float delta = max - [r, g, b].min()
def hue = 13 def hue = 13
def saturation = 0 def saturation = 0
if (max && delta) { if (max && delta) {
saturation = 100 * delta / max saturation = 100 * delta / max
if (r == max) { if (r == max) {
hue = ((g - b) / delta) * 100 / 6 hue = ((g - b) / delta) * 100 / 6
} else if (g == max) { } else if (g == max) {
hue = (2 + (b - r) / delta) * 100 / 6 hue = (2 + (b - r) / delta) * 100 / 6
} else { } else {
hue = (4 + (r - g) / delta) * 100 / 6 hue = (4 + (r - g) / delta) * 100 / 6
} }
} }
[hue: hue, saturation: saturation, value: max * 100] [hue: hue, saturation: saturation, value: max * 100]
} }
def huesatToRGB(float hue, float sat) { def huesatToRGB(float hue, float sat) {
while(hue >= 100) hue -= 100 while(hue >= 100) hue -= 100
int h = (int)(hue / 100 * 6) int h = (int)(hue / 100 * 6)
float f = hue / 100 * 6 - h float f = hue / 100 * 6 - h
int p = Math.round(255 * (1 - (sat / 100))) int p = Math.round(255 * (1 - (sat / 100)))
int q = Math.round(255 * (1 - (sat / 100) * f)) int q = Math.round(255 * (1 - (sat / 100) * f))
int t = Math.round(255 * (1 - (sat / 100) * (1 - f))) int t = Math.round(255 * (1 - (sat / 100) * (1 - f)))
switch (h) { switch (h) {
case 0: return [255, t, p] case 0: return [255, t, p]
case 1: return [q, 255, p] case 1: return [q, 255, p]
case 2: return [p, 255, t] case 2: return [p, 255, t]
case 3: return [p, q, 255] case 3: return [p, q, 255]
case 4: return [t, p, 255] case 4: return [t, p, 255]
case 5: return [255, p, q] case 5: return [255, p, q]
} }
} }

View File

@@ -1,6 +1,4 @@
private hideOptionsSection() { /**
(starting || ending || days || modes) ? false : true
}/**
* Copyright 2015 SmartThings * Copyright 2015 SmartThings
* *
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
@@ -315,8 +313,10 @@ private hhmm(time, fmt = "h:mm a")
f.format(t) f.format(t)
} }
private hideOptionsSection() {
(starting || ending || days || modes) ? false : true
}
private timeIntervalLabel() { private timeIntervalLabel() {
(starting && ending) ? hhmm(starting) + "-" + hhmm(ending, "h:mm a z") : "" (starting && ending) ? hhmm(starting) + "-" + hhmm(ending, "h:mm a z") : ""
} }

View File

@@ -1,158 +1,158 @@
/** /**
* Copyright 2015 SmartThings * Copyright 2015 SmartThings
* *
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except * 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: * in compliance with the License. You may obtain a copy of the License at:
* *
* http://www.apache.org/licenses/LICENSE-2.0 * 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 * 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 * 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. * for the specific language governing permissions and limitations under the License.
* *
* Notify Me When * Notify Me When
* *
* Author: SmartThings * Author: SmartThings
* Date: 2013-03-20 * Date: 2013-03-20
* *
* Change Log: * Change Log:
* 1. Todd Wackford * 1. Todd Wackford
* 2014-10-03: Added capability.button device picker and button.pushed event subscription. For Doorbell. * 2014-10-03: Added capability.button device picker and button.pushed event subscription. For Doorbell.
*/ */
definition( definition(
name: "Notify Me When", name: "Notify Me When",
namespace: "smartthings", namespace: "smartthings",
author: "SmartThings", author: "SmartThings",
description: "Receive notifications when anything happens in your home.", description: "Receive notifications when anything happens in your home.",
category: "Convenience", category: "Convenience",
iconUrl: "https://s3.amazonaws.com/smartapp-icons/Meta/window_contact.png", iconUrl: "https://s3.amazonaws.com/smartapp-icons/Meta/window_contact.png",
iconX2Url: "https://s3.amazonaws.com/smartapp-icons/Meta/window_contact@2x.png" iconX2Url: "https://s3.amazonaws.com/smartapp-icons/Meta/window_contact@2x.png"
) )
preferences { preferences {
section("Choose one or more, when..."){ section("Choose one or more, when..."){
input "button", "capability.button", title: "Button Pushed", required: false, multiple: true //tw input "button", "capability.button", title: "Button Pushed", required: false, multiple: true //tw
input "motion", "capability.motionSensor", title: "Motion Here", required: false, multiple: true input "motion", "capability.motionSensor", title: "Motion Here", required: false, multiple: true
input "contact", "capability.contactSensor", title: "Contact Opens", required: false, multiple: true input "contact", "capability.contactSensor", title: "Contact Opens", required: false, multiple: true
input "contactClosed", "capability.contactSensor", title: "Contact Closes", required: false, multiple: true input "contactClosed", "capability.contactSensor", title: "Contact Closes", required: false, multiple: true
input "acceleration", "capability.accelerationSensor", title: "Acceleration Detected", required: false, multiple: true input "acceleration", "capability.accelerationSensor", title: "Acceleration Detected", required: false, multiple: true
input "mySwitch", "capability.switch", title: "Switch Turned On", required: false, multiple: true input "mySwitch", "capability.switch", title: "Switch Turned On", required: false, multiple: true
input "mySwitchOff", "capability.switch", title: "Switch Turned Off", required: false, multiple: true input "mySwitchOff", "capability.switch", title: "Switch Turned Off", required: false, multiple: true
input "arrivalPresence", "capability.presenceSensor", title: "Arrival Of", required: false, multiple: true input "arrivalPresence", "capability.presenceSensor", title: "Arrival Of", required: false, multiple: true
input "departurePresence", "capability.presenceSensor", title: "Departure Of", required: false, multiple: true input "departurePresence", "capability.presenceSensor", title: "Departure Of", required: false, multiple: true
input "smoke", "capability.smokeDetector", title: "Smoke Detected", required: false, multiple: true input "smoke", "capability.smokeDetector", title: "Smoke Detected", required: false, multiple: true
input "water", "capability.waterSensor", title: "Water Sensor Wet", required: false, multiple: true input "water", "capability.waterSensor", title: "Water Sensor Wet", required: false, multiple: true
} }
section("Send this message (optional, sends standard status message if not specified)"){ section("Send this message (optional, sends standard status message if not specified)"){
input "messageText", "text", title: "Message Text", required: false input "messageText", "text", title: "Message Text", required: false
} }
section("Via a push notification and/or an SMS message"){ section("Via a push notification and/or an SMS message"){
input("recipients", "contact", title: "Send notifications to") { input("recipients", "contact", title: "Send notifications to") {
input "phone", "phone", title: "Phone Number (for SMS, optional)", required: false input "phone", "phone", title: "Phone Number (for SMS, optional)", required: false
paragraph "If outside the US please make sure to enter the proper country code" paragraph "If outside the US please make sure to enter the proper country code"
input "pushAndPhone", "enum", title: "Both Push and SMS?", required: false, options: ["Yes", "No"] input "pushAndPhone", "enum", title: "Both Push and SMS?", required: false, options: ["Yes", "No"]
} }
} }
section("Minimum time between messages (optional, defaults to every message)") { section("Minimum time between messages (optional, defaults to every message)") {
input "frequency", "decimal", title: "Minutes", required: false input "frequency", "decimal", title: "Minutes", required: false
} }
} }
def installed() { def installed() {
log.debug "Installed with settings: ${settings}" log.debug "Installed with settings: ${settings}"
subscribeToEvents() subscribeToEvents()
} }
def updated() { def updated() {
log.debug "Updated with settings: ${settings}" log.debug "Updated with settings: ${settings}"
unsubscribe() unsubscribe()
subscribeToEvents() subscribeToEvents()
} }
def subscribeToEvents() { def subscribeToEvents() {
subscribe(button, "button.pushed", eventHandler) //tw subscribe(button, "button.pushed", eventHandler) //tw
subscribe(contact, "contact.open", eventHandler) subscribe(contact, "contact.open", eventHandler)
subscribe(contactClosed, "contact.closed", eventHandler) subscribe(contactClosed, "contact.closed", eventHandler)
subscribe(acceleration, "acceleration.active", eventHandler) subscribe(acceleration, "acceleration.active", eventHandler)
subscribe(motion, "motion.active", eventHandler) subscribe(motion, "motion.active", eventHandler)
subscribe(mySwitch, "switch.on", eventHandler) subscribe(mySwitch, "switch.on", eventHandler)
subscribe(mySwitchOff, "switch.off", eventHandler) subscribe(mySwitchOff, "switch.off", eventHandler)
subscribe(arrivalPresence, "presence.present", eventHandler) subscribe(arrivalPresence, "presence.present", eventHandler)
subscribe(departurePresence, "presence.not present", eventHandler) subscribe(departurePresence, "presence.not present", eventHandler)
subscribe(smoke, "smoke.detected", eventHandler) subscribe(smoke, "smoke.detected", eventHandler)
subscribe(smoke, "smoke.tested", eventHandler) subscribe(smoke, "smoke.tested", eventHandler)
subscribe(smoke, "carbonMonoxide.detected", eventHandler) subscribe(smoke, "carbonMonoxide.detected", eventHandler)
subscribe(water, "water.wet", eventHandler) subscribe(water, "water.wet", eventHandler)
} }
def eventHandler(evt) { def eventHandler(evt) {
log.debug "Notify got evt ${evt}" log.debug "Notify got evt ${evt}"
if (frequency) { if (frequency) {
def lastTime = state[evt.deviceId] def lastTime = state[evt.deviceId]
if (lastTime == null || now() - lastTime >= frequency * 60000) { if (lastTime == null || now() - lastTime >= frequency * 60000) {
sendMessage(evt) sendMessage(evt)
} }
} }
else { else {
sendMessage(evt) sendMessage(evt)
} }
} }
private sendMessage(evt) { private sendMessage(evt) {
String msg = messageText String msg = messageText
Map options = [:] Map options = [:]
if (!messageText) { if (!messageText) {
msg = defaultText(evt) msg = defaultText(evt)
options = [translatable: true, triggerEvent: evt] options = [translatable: true, triggerEvent: evt]
} }
log.debug "$evt.name:$evt.value, pushAndPhone:$pushAndPhone, '$msg'" log.debug "$evt.name:$evt.value, pushAndPhone:$pushAndPhone, '$msg'"
if (location.contactBookEnabled) { if (location.contactBookEnabled) {
sendNotificationToContacts(msg, recipients, options) sendNotificationToContacts(msg, recipients, options)
} else { } else {
if (!phone || pushAndPhone != 'No') { if (!phone || pushAndPhone != 'No') {
log.debug 'sending push' log.debug 'sending push'
options.method = 'push' options.method = 'push'
//sendPush(msg) //sendPush(msg)
} }
if (phone) { if (phone) {
options.phone = phone options.phone = phone
log.debug 'sending SMS' log.debug 'sending SMS'
//sendSms(phone, msg) //sendSms(phone, msg)
} }
sendNotification(msg, options) sendNotification(msg, options)
} }
if (frequency) { if (frequency) {
state[evt.deviceId] = now() state[evt.deviceId] = now()
} }
} }
private defaultText(evt) { private defaultText(evt) {
if (evt.name == 'presence') { if (evt.name == 'presence') {
if (evt.value == 'present') { if (evt.value == 'present') {
if (includeArticle) { if (includeArticle) {
'{{ triggerEvent.linkText }} has arrived at the {{ location.name }}' '{{ triggerEvent.linkText }} has arrived at the {{ location.name }}'
} }
else { else {
'{{ triggerEvent.linkText }} has arrived at {{ location.name }}' '{{ triggerEvent.linkText }} has arrived at {{ location.name }}'
} }
} else { } else {
if (includeArticle) { if (includeArticle) {
'{{ triggerEvent.linkText }} has left the {{ location.name }}' '{{ triggerEvent.linkText }} has left the {{ location.name }}'
} }
else { else {
'{{ triggerEvent.linkText }} has left {{ location.name }}' '{{ triggerEvent.linkText }} has left {{ location.name }}'
} }
} }
} else { } else {
'{{ triggerEvent.descriptionText }}' '{{ triggerEvent.descriptionText }}'
} }
} }
private getIncludeArticle() { private getIncludeArticle() {
def name = location.name.toLowerCase() def name = location.name.toLowerCase()
def segs = name.split(" ") def segs = name.split(" ")
!(["work","home"].contains(name) || (segs.size() > 1 && (["the","my","a","an"].contains(segs[0]) || segs[0].endsWith("'s")))) !(["work","home"].contains(name) || (segs.size() > 1 && (["the","my","a","an"].contains(segs[0]) || segs[0].endsWith("'s"))))
} }