mirror of
https://github.com/mtan93/SmartThingsPublic.git
synced 2026-03-12 13:21:53 +00:00
Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e249b31938 |
104
devicetypes/astralink/panic-button.src/panic-button.groovy
Normal file
104
devicetypes/astralink/panic-button.src/panic-button.groovy
Normal file
@@ -0,0 +1,104 @@
|
||||
/**
|
||||
* Copyright 2015 SmartThings
|
||||
*
|
||||
* 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:
|
||||
*
|
||||
* 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
|
||||
* 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.
|
||||
*
|
||||
*/
|
||||
metadata {
|
||||
definition (name: "Panic Button", namespace: "astralink", author: "SmartThings") {
|
||||
capability "Button"
|
||||
capability "Battery"
|
||||
}
|
||||
|
||||
simulator {
|
||||
status "button 1 pushed": "command: 2001, payload: 01"
|
||||
status "button 1 held": "command: 2001, payload: 15"
|
||||
status "button 2 pushed": "command: 2001, payload: 29"
|
||||
status "button 2 held": "command: 2001, payload: 3D"
|
||||
status "button 3 pushed": "command: 2001, payload: 51"
|
||||
status "button 3 held": "command: 2001, payload: 65"
|
||||
status "button 4 pushed": "command: 2001, payload: 79"
|
||||
status "button 4 held": "command: 2001, payload: 8D"
|
||||
status "wakeup": "command: 8407, payload: "
|
||||
}
|
||||
tiles {
|
||||
standardTile("button", "device.button", width: 2, height: 2) {
|
||||
state "default", label: "", icon: "st.unknown.zwave.remote-controller", backgroundColor: "#ffffff"
|
||||
}
|
||||
main "button"
|
||||
details(["button"])
|
||||
}
|
||||
}
|
||||
|
||||
def parse(String description) {
|
||||
def results = []
|
||||
if (description.startsWith("Err")) {
|
||||
results = createEvent(descriptionText:description, displayed:true)
|
||||
} else {
|
||||
def cmd = zwave.parse(description, [0x2B: 1, 0x80: 1, 0x84: 1])
|
||||
if(cmd) results += zwaveEvent(cmd)
|
||||
if(!results) results = [ descriptionText: cmd, displayed: false ]
|
||||
}
|
||||
log.debug("Parsed '$description' to $results")
|
||||
return results
|
||||
}
|
||||
|
||||
def zwaveEvent(physicalgraph.zwave.commands.wakeupv1.WakeUpNotification cmd) {
|
||||
def results = [createEvent(descriptionText: "$device.displayName woke up", isStateChange: false)]
|
||||
|
||||
results += configurationCmds().collect{ response(it) }
|
||||
results << response(zwave.wakeUpV1.wakeUpNoMoreInformation().format())
|
||||
|
||||
return results
|
||||
}
|
||||
|
||||
def buttonEvent(button, pushed) {
|
||||
button = button as Integer
|
||||
if (pushed) {
|
||||
createEvent(name: "button", value: "pushed", data: [buttonNumber: button], descriptionText: "$device.displayName button $button was pushed", isStateChange: true)
|
||||
} else {
|
||||
createEvent(name: "button", value: "pushed", data: [buttonNumber: button], descriptionText: "$device.displayName button $button was pushed", isStateChange: true)
|
||||
}
|
||||
}
|
||||
|
||||
def zwaveEvent(physicalgraph.zwave.commands.sceneactivationv1.SceneActivationSet cmd) {
|
||||
Integer button = ((cmd.sceneId + 1) / 2) as Integer
|
||||
Boolean pushed = !(cmd.sceneId % 2)
|
||||
buttonEvent(button, pushed)
|
||||
}
|
||||
|
||||
def zwaveEvent(physicalgraph.zwave.commands.basicv1.BasicSet cmd) {
|
||||
Integer button = (cmd.value / 40 + 1) as Integer
|
||||
Boolean pushed = (button * 40 - cmd.value) <= 20
|
||||
buttonEvent(button, pushed)
|
||||
}
|
||||
|
||||
def zwaveEvent(physicalgraph.zwave.Command cmd) {
|
||||
[ descriptionText: "$device.displayName: $cmd", linkText:device.displayName, displayed: false ]
|
||||
}
|
||||
|
||||
def configurationCmds() {
|
||||
def cmds = []
|
||||
def hubId = zwaveHubNodeId
|
||||
(1..4).each { button ->
|
||||
cmds << zwave.configurationV1.configurationSet(parameterNumber: 240+button, scaledConfigurationValue: 1).format()
|
||||
}
|
||||
(1..4).each { button ->
|
||||
cmds << zwave.configurationV1.configurationSet(parameterNumber: (button-1)*40, configurationValue: [hubId, (button-1)*40 + 1, 0, 0]).format()
|
||||
cmds << zwave.configurationV1.configurationSet(parameterNumber: (button-1)*40 + 20, configurationValue: [hubId, (button-1)*40 + 21, 0, 0]).format()
|
||||
}
|
||||
cmds
|
||||
}
|
||||
|
||||
def configure() {
|
||||
def cmds = configurationCmds()
|
||||
log.debug("Sending configuration: $cmds")
|
||||
return cmds
|
||||
}
|
||||
@@ -1,142 +0,0 @@
|
||||
definition (
|
||||
name: "Leave home secure",
|
||||
namespace: "richardneville",
|
||||
author: "Richard Neville",
|
||||
description: "Tells us if the doors and windows are open when we go out.",
|
||||
category: "My Apps",
|
||||
iconUrl: "http://animl.co.uk/img/SmartThingsLeaveHomeSecure.png",
|
||||
iconX2Url: "http://animl.co.uk/img/SmartThingsLeaveHomeSecure@2x.png",
|
||||
iconX3Url: "http://animl.co.uk/img/SmartThingsLeaveHomeSecure@2x.png"
|
||||
)
|
||||
|
||||
preferences {
|
||||
section("Things to report on") {
|
||||
input "contactSensorThings", "capability.contactSensor", required: true, multiple: true,
|
||||
title: "Select which things to watch:"
|
||||
paragraph "This SmartApp reports if the doors and windows are left open when we go out. The report can be triggered in various ways. v0.1"
|
||||
}
|
||||
section("Things to trigger the report") {
|
||||
input "presenceThings", "capability.presenceSensor", required: false, multiple: true,
|
||||
title: "Notify when these things leave home:"
|
||||
input "contactSensorTrigger", "capability.contactSensor", required: false, multiple: true,
|
||||
title: "Notify when this thing closes:"
|
||||
input "motionSensorThing", "capability.motionSensor", required: false, multiple: true,
|
||||
title: "Notify when movement is detected near this thing:"
|
||||
}
|
||||
section("Settings") {
|
||||
input "fullReport", "bool", title: "Full report, even if things are closed?", required: false
|
||||
input "pushNotification", "bool", title: "Push the message out?", required: false
|
||||
input("recipients", "contact", title: "Send messages to:") {
|
||||
input "phone", "phone", title: "Send an SMS to:", description: "Phone Number", required: false
|
||||
}
|
||||
paragraph "(If no recipients are selected, app will just send a push notification instead.)"
|
||||
}
|
||||
}
|
||||
|
||||
def installed() {
|
||||
initialize()
|
||||
}
|
||||
|
||||
def updated() {
|
||||
unsubscribe()
|
||||
initialize()
|
||||
}
|
||||
|
||||
def initialize() {
|
||||
subscribe(presenceThings, "presence", presenceHandler)
|
||||
subscribe(contactSensorTrigger, "contact", contactHandler)
|
||||
subscribe(motionSensorThing, "motion", motionHandler)
|
||||
|
||||
/*
|
||||
subscribe(switchThing, "switch", switchHandler)
|
||||
*/
|
||||
}
|
||||
|
||||
def presenceHandler(evt) {
|
||||
if (evt.value == "not present") {
|
||||
if (allThingsLeftHome()) {
|
||||
checkIfHouseSecure()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
def contactHandler(evt) {
|
||||
if (evt.value == "closed") {
|
||||
checkIfHouseSecure()
|
||||
}
|
||||
}
|
||||
|
||||
def motionHandler(evt) {
|
||||
if (evt.value == "active") {
|
||||
// motion detected
|
||||
checkIfHouseSecure()
|
||||
} else if (evt.value == "inactive") {
|
||||
// motion stopped
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
def switchHandler(evt) {
|
||||
if (debugMode) {
|
||||
checkIfHouseSecure()
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
private checkIfHouseSecure() {
|
||||
for (contactSensorThing in contactSensorThings) {
|
||||
def sensorState = contactSensorThing.currentState("contact").value
|
||||
if (sensorState == "open" || fullReport) {
|
||||
sendMsg("${contactSensorThing.displayName} is ${sensorState}.")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private allThingsLeftHome() {
|
||||
def result = true
|
||||
for (presenceThing in presenceThings) {
|
||||
if (presenceThing.currentPresence == "present") {
|
||||
// someone is present, so set result to false and terminate the loop.
|
||||
result = false
|
||||
break
|
||||
}
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
private sendMsg(msg) {
|
||||
if (pushNotification) {
|
||||
// check that contact book is enabled and recipients selected
|
||||
if (location.contactBookEnabled && recipients) {
|
||||
sendNotificationToContacts(msg, recipients)
|
||||
} else if (phone) { // check that the user did select a phone number
|
||||
sendNotificationEvent("SMS sent to ${phone}")
|
||||
sendSms(phone, msg)
|
||||
//sendNotification(msg, [method: "phone", phone: "1234567890"])
|
||||
} else {
|
||||
sendPush(msg)
|
||||
}
|
||||
} else {
|
||||
sendNotificationEvent(msg)
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
def switchHandler(evt) {
|
||||
if (evt.value == "on") {
|
||||
//sendPush("The ${switchThing.displayName} is on!")
|
||||
} else if (evt.value == "off") {
|
||||
//sendPush("The ${switchThing.displayName} is off!")
|
||||
}
|
||||
}
|
||||
|
||||
def contactHandler(evt) {
|
||||
if (evt.value == "open") {
|
||||
// contactSensor open
|
||||
} else if (evt.value == "closed") {
|
||||
// contactSensor closed
|
||||
}
|
||||
}
|
||||
|
||||
*/
|
||||
@@ -50,7 +50,7 @@ preferences {
|
||||
}
|
||||
section("Send Notifications?") {
|
||||
input("recipients", "contact", title: "Send notifications to") {
|
||||
input "phone", "phone", title: "Send an SMS to this number?", required:false
|
||||
input "phone", "phone", title: "Send an SMS to this number?"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -266,9 +266,7 @@ def sendAway(msg) {
|
||||
}
|
||||
else {
|
||||
sendPush(msg)
|
||||
if(phone){
|
||||
sendSms(phone, msg)
|
||||
}
|
||||
sendSms(phone, msg)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -282,9 +280,7 @@ def sendHome(msg) {
|
||||
}
|
||||
else {
|
||||
sendPush(msg)
|
||||
if(phone){
|
||||
sendSms(phone, msg)
|
||||
}
|
||||
sendSms(phone, msg)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -343,4 +339,4 @@ private getTimeIntervalLabel() {
|
||||
|
||||
private hideOptionsSection() {
|
||||
(starting || ending || days || modes) ? false: true
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user