mirror of
https://github.com/mtan93/SmartThingsPublic.git
synced 2026-03-23 05:10:50 +00:00
Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
55765f67b7 |
@@ -66,20 +66,9 @@ metadata {
|
|||||||
import physicalgraph.zwave.commands.doorlockv1.*
|
import physicalgraph.zwave.commands.doorlockv1.*
|
||||||
import physicalgraph.zwave.commands.usercodev1.*
|
import physicalgraph.zwave.commands.usercodev1.*
|
||||||
|
|
||||||
def updated() {
|
|
||||||
try {
|
|
||||||
if (!state.init) {
|
|
||||||
state.init = true
|
|
||||||
response(secureSequence([zwave.doorLockV1.doorLockOperationGet(), zwave.batteryV1.batteryGet()]))
|
|
||||||
}
|
|
||||||
} catch (e) {
|
|
||||||
log.warn "updated() threw $e"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
def parse(String description) {
|
def parse(String description) {
|
||||||
def result = null
|
def result = null
|
||||||
if (description.startsWith("Err 106")) {
|
if (description.startsWith("Err")) {
|
||||||
if (state.sec) {
|
if (state.sec) {
|
||||||
result = createEvent(descriptionText:description, displayed:false)
|
result = createEvent(descriptionText:description, displayed:false)
|
||||||
} else {
|
} else {
|
||||||
@@ -91,8 +80,6 @@ def parse(String description) {
|
|||||||
displayed: true,
|
displayed: true,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
} else if (description == "updated") {
|
|
||||||
return null
|
|
||||||
} else {
|
} else {
|
||||||
def cmd = zwave.parse(description, [ 0x98: 1, 0x72: 2, 0x85: 2, 0x86: 1 ])
|
def cmd = zwave.parse(description, [ 0x98: 1, 0x72: 2, 0x85: 2, 0x86: 1 ])
|
||||||
if (cmd) {
|
if (cmd) {
|
||||||
@@ -299,7 +286,7 @@ def zwaveEvent(physicalgraph.zwave.commands.alarmv2.AlarmReport cmd) {
|
|||||||
}
|
}
|
||||||
break
|
break
|
||||||
case 167:
|
case 167:
|
||||||
if (!state.lastbatt || now() - state.lastbatt > 12*60*60*1000) {
|
if (!state.lastbatt || (new Date().time) - state.lastbatt > 12*60*60*1000) {
|
||||||
map = [ descriptionText: "$device.displayName: battery low", isStateChange: true ]
|
map = [ descriptionText: "$device.displayName: battery low", isStateChange: true ]
|
||||||
result << response(secure(zwave.batteryV1.batteryGet()))
|
result << response(secure(zwave.batteryV1.batteryGet()))
|
||||||
} else {
|
} else {
|
||||||
@@ -444,7 +431,7 @@ def zwaveEvent(physicalgraph.zwave.commands.batteryv1.BatteryReport cmd) {
|
|||||||
} else {
|
} else {
|
||||||
map.value = cmd.batteryLevel
|
map.value = cmd.batteryLevel
|
||||||
}
|
}
|
||||||
state.lastbatt = now()
|
state.lastbatt = new Date().time
|
||||||
createEvent(map)
|
createEvent(map)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -512,14 +499,15 @@ def refresh() {
|
|||||||
cmds << "delay 4200"
|
cmds << "delay 4200"
|
||||||
cmds << zwave.associationV1.associationGet(groupingIdentifier:2).format() // old Schlage locks use group 2 and don't secure the Association CC
|
cmds << zwave.associationV1.associationGet(groupingIdentifier:2).format() // old Schlage locks use group 2 and don't secure the Association CC
|
||||||
cmds << secure(zwave.associationV1.associationGet(groupingIdentifier:1))
|
cmds << secure(zwave.associationV1.associationGet(groupingIdentifier:1))
|
||||||
state.associationQuery = now()
|
state.associationQuery = new Date().time
|
||||||
} else if (secondsPast(state.associationQuery, 9)) {
|
} else if (new Date().time - state.associationQuery.toLong() > 9000) {
|
||||||
|
log.debug "setting association"
|
||||||
cmds << "delay 6000"
|
cmds << "delay 6000"
|
||||||
cmds << zwave.associationV1.associationSet(groupingIdentifier:2, nodeId:zwaveHubNodeId).format()
|
cmds << zwave.associationV1.associationSet(groupingIdentifier:2, nodeId:zwaveHubNodeId).format()
|
||||||
cmds << secure(zwave.associationV1.associationSet(groupingIdentifier:1, nodeId:zwaveHubNodeId))
|
cmds << secure(zwave.associationV1.associationSet(groupingIdentifier:1, nodeId:zwaveHubNodeId))
|
||||||
cmds << zwave.associationV1.associationGet(groupingIdentifier:2).format()
|
cmds << zwave.associationV1.associationGet(groupingIdentifier:2).format()
|
||||||
cmds << secure(zwave.associationV1.associationGet(groupingIdentifier:1))
|
cmds << secure(zwave.associationV1.associationGet(groupingIdentifier:1))
|
||||||
state.associationQuery = now()
|
state.associationQuery = new Date().time
|
||||||
}
|
}
|
||||||
log.debug "refresh sending ${cmds.inspect()}"
|
log.debug "refresh sending ${cmds.inspect()}"
|
||||||
cmds
|
cmds
|
||||||
@@ -527,22 +515,55 @@ def refresh() {
|
|||||||
|
|
||||||
def poll() {
|
def poll() {
|
||||||
def cmds = []
|
def cmds = []
|
||||||
// Only check lock state if it changed recently or we haven't had an update in an hour
|
if (state.assoc != zwaveHubNodeId && secondsPast(state.associationQuery, 19 * 60)) {
|
||||||
def latest = device.currentState("lock")?.date?.time
|
log.debug "setting association"
|
||||||
if (!latest || !secondsPast(latest, 6 * 60) || secondsPast(state.lastPoll, 55 * 60)) {
|
cmds << zwave.associationV1.associationSet(groupingIdentifier:2, nodeId:zwaveHubNodeId).format()
|
||||||
cmds << secure(zwave.doorLockV1.doorLockOperationGet())
|
cmds << secure(zwave.associationV1.associationSet(groupingIdentifier:1, nodeId:zwaveHubNodeId))
|
||||||
state.lastPoll = now()
|
cmds << zwave.associationV1.associationGet(groupingIdentifier:2).format()
|
||||||
} else if (!state.lastbatt || now() - state.lastbatt > 53*60*60*1000) {
|
cmds << "delay 6000"
|
||||||
cmds << secure(zwave.batteryV1.batteryGet())
|
cmds << secure(zwave.associationV1.associationGet(groupingIdentifier:1))
|
||||||
state.lastbatt = now() //inside-214
|
cmds << "delay 6000"
|
||||||
}
|
state.associationQuery = new Date().time
|
||||||
if (cmds) {
|
|
||||||
log.debug "poll is sending ${cmds.inspect()}"
|
|
||||||
cmds
|
|
||||||
} else {
|
} else {
|
||||||
// workaround to keep polling from stopping due to lack of activity
|
// Only check lock state if it changed recently or we haven't had an update in an hour
|
||||||
sendEvent(descriptionText: "skipping poll", isStateChange: true, displayed: false)
|
def latest = device.currentState("lock")?.date?.time
|
||||||
null
|
if (!latest || !secondsPast(latest, 6 * 60) || secondsPast(state.lastPoll, 55 * 60)) {
|
||||||
|
cmds << secure(zwave.doorLockV1.doorLockOperationGet())
|
||||||
|
state.lastPoll = (new Date()).time
|
||||||
|
} else if (!state.MSR) {
|
||||||
|
cmds << zwave.manufacturerSpecificV1.manufacturerSpecificGet().format()
|
||||||
|
} else if (!state.fw) {
|
||||||
|
cmds << zwave.versionV1.versionGet().format()
|
||||||
|
} else if (!state.codes) {
|
||||||
|
state.pollCode = 1
|
||||||
|
cmds << secure(zwave.userCodeV1.usersNumberGet())
|
||||||
|
} else if (state.pollCode && state.pollCode <= state.codes) {
|
||||||
|
cmds << requestCode(state.pollCode)
|
||||||
|
} else if (!state.lastbatt || (new Date().time) - state.lastbatt > 53*60*60*1000) {
|
||||||
|
cmds << secure(zwave.batteryV1.batteryGet())
|
||||||
|
} else if (!state.enc) {
|
||||||
|
encryptCodes()
|
||||||
|
state.enc = 1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
log.debug "poll is sending ${cmds.inspect()}"
|
||||||
|
device.activity()
|
||||||
|
cmds ?: null
|
||||||
|
}
|
||||||
|
|
||||||
|
private def encryptCodes() {
|
||||||
|
def keys = new ArrayList(state.keySet().findAll { it.startsWith("code") })
|
||||||
|
keys.each { key ->
|
||||||
|
def match = (key =~ /^code(\d+)$/)
|
||||||
|
if (match) try {
|
||||||
|
def keynum = match[0][1].toInteger()
|
||||||
|
if (keynum > 30 && !state[key]) {
|
||||||
|
state.remove(key)
|
||||||
|
} else if (state[key] && !state[key].startsWith("~")) {
|
||||||
|
log.debug "encrypting $key: ${state[key].inspect()}"
|
||||||
|
state[key] = encrypt(state[key])
|
||||||
|
}
|
||||||
|
} catch (java.lang.NumberFormatException e) { }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -651,7 +672,7 @@ private Boolean secondsPast(timestamp, seconds) {
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return (now() - timestamp) > (seconds * 1000)
|
return (new Date().time - timestamp) > (seconds * 1000)
|
||||||
}
|
}
|
||||||
|
|
||||||
private allCodesDeleted() {
|
private allCodesDeleted() {
|
||||||
|
|||||||
52
smartapps/bravenel/rule-machine.src/rule-machine.groovy
Normal file
52
smartapps/bravenel/rule-machine.src/rule-machine.groovy
Normal file
@@ -0,0 +1,52 @@
|
|||||||
|
/**
|
||||||
|
* Rule
|
||||||
|
*
|
||||||
|
* Copyright 2015 Bruce Ravenel
|
||||||
|
*
|
||||||
|
* Version 1.1.0 25 Nov 2015
|
||||||
|
*
|
||||||
|
* 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.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
definition(
|
||||||
|
name: "Rule Machine",
|
||||||
|
singleInstance: true,
|
||||||
|
namespace: "bravenel",
|
||||||
|
author: "Bruce Ravenel",
|
||||||
|
description: "Rule Machine",
|
||||||
|
category: "My Apps",
|
||||||
|
iconUrl: "https://s3.amazonaws.com/smartapp-icons/ModeMagic/Cat-ModeMagic.png",
|
||||||
|
iconX2Url: "https://s3.amazonaws.com/smartapp-icons/ModeMagic/Cat-ModeMagic@2x.png",
|
||||||
|
iconX3Url: "https://s3.amazonaws.com/smartapp-icons/ModeMagic/Cat-ModeMagic@3x.png"
|
||||||
|
)
|
||||||
|
|
||||||
|
preferences {
|
||||||
|
page(name: "mainPage", title: "Rules", install: true, uninstall: true,submitOnChange: true) {
|
||||||
|
section {
|
||||||
|
app(name: "childRules", appName: "Rule", namespace: "bravenel", title: "Create New Rule...", multiple: true)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
def installed() {
|
||||||
|
initialize()
|
||||||
|
}
|
||||||
|
|
||||||
|
def updated() {
|
||||||
|
unsubscribe()
|
||||||
|
initialize()
|
||||||
|
}
|
||||||
|
|
||||||
|
def initialize() {
|
||||||
|
childApps.each {child ->
|
||||||
|
log.info "Installed Rules: ${child.label}"
|
||||||
|
}
|
||||||
|
}
|
||||||
1005
smartapps/bravenel/rule.src/rule.groovy
Normal file
1005
smartapps/bravenel/rule.src/rule.groovy
Normal file
File diff suppressed because it is too large
Load Diff
@@ -1,105 +0,0 @@
|
|||||||
/**
|
|
||||||
* Light Up The Night
|
|
||||||
*
|
|
||||||
* Copyright 2015 Brian Warner
|
|
||||||
*
|
|
||||||
* 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.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
definition(
|
|
||||||
name: "Light Up The Night",
|
|
||||||
namespace: "brianwarner",
|
|
||||||
author: "Brian Warner",
|
|
||||||
description: "Turn on certain lights when a door opens at night, and turn them off a certain time after the last door closes. Great for garage doors and driveway lights.",
|
|
||||||
category: "Convenience",
|
|
||||||
iconUrl: "http://cdn.device-icons.smartthings.com/Lighting/light9-icn.png",
|
|
||||||
iconX2Url: "http://cdn.device-icons.smartthings.com/Lighting/light9-icn@2x.png",
|
|
||||||
iconX3Url: "http://cdn.device-icons.smartthings.com/Lighting/light9-icn@3x.png")
|
|
||||||
|
|
||||||
|
|
||||||
preferences {
|
|
||||||
|
|
||||||
section() {
|
|
||||||
input "contactsensors", "capability.contactSensor", multiple: true, title: "When these doors open:"
|
|
||||||
}
|
|
||||||
|
|
||||||
section() {
|
|
||||||
input "lights", "capability.switch", required: true, multiple: true, title: "Turn on these lights:"
|
|
||||||
}
|
|
||||||
|
|
||||||
section() {
|
|
||||||
input "timer", "number", required: true, title: "Keep them on until all doors are closed for this many minutes:", range: "0..240"
|
|
||||||
}
|
|
||||||
|
|
||||||
section() {
|
|
||||||
input "sunriseoffset", "number", required: true, title: "Start turning on the lights this many minutes before sunset:", range: "0..360"
|
|
||||||
}
|
|
||||||
|
|
||||||
section() {
|
|
||||||
input "sunsetoffset", "number", required: true, title: "Stop turning on the lights this many minutes after sunrise:", range: "0..360"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
def installed() {
|
|
||||||
log.debug "Installed with settings: ${settings}"
|
|
||||||
|
|
||||||
initialize()
|
|
||||||
}
|
|
||||||
|
|
||||||
def updated() {
|
|
||||||
log.debug "Updated with settings: ${settings}"
|
|
||||||
|
|
||||||
unsubscribe()
|
|
||||||
initialize()
|
|
||||||
}
|
|
||||||
|
|
||||||
def initialize() {
|
|
||||||
subscribe(garagedoors, "door.open", doorOpenHandler)
|
|
||||||
subscribe(garagedoors, "door.closed", doorClosedHandler)
|
|
||||||
subscribe(contactsensors, "contact.open", doorOpenHandler)
|
|
||||||
subscribe(contactsensors, "contact.closed", doorClosedHandler)
|
|
||||||
}
|
|
||||||
|
|
||||||
def doorOpenHandler(evt) {
|
|
||||||
// log.debug "Door opened."
|
|
||||||
def now = new Date()
|
|
||||||
def sunTime = getSunriseAndSunset(sunriseOffset: "00:$sunriseoffset", sunsetOffset: "-00:$sunsetoffset")
|
|
||||||
|
|
||||||
if (now > sunTime.sunset || now < sunTime.sunrise) {
|
|
||||||
// log.debug "Turning lights on."
|
|
||||||
lights.on()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
def doorClosedHandler(evt) {
|
|
||||||
// log.debug "A door closed."
|
|
||||||
runIn(60 * timer, checkClosed)
|
|
||||||
}
|
|
||||||
|
|
||||||
def checkClosed() {
|
|
||||||
// log.debug "Checking to ensure all doors are still closed."
|
|
||||||
|
|
||||||
def contactSensorState = contactsensors.currentState("contact")
|
|
||||||
def anyContactSensorsOpen = contactSensorState.value.findAll {it == "open"}
|
|
||||||
|
|
||||||
if (!anyContactSensorsOpen) {
|
|
||||||
def elapsed = now() - contactSensorState.date.time.max()
|
|
||||||
def timeout = 1000 * 60 * timer
|
|
||||||
|
|
||||||
if (elapsed >= timeout) {
|
|
||||||
// log.debug "Doors have stayed closed. Turning off the lights."
|
|
||||||
lights.off()
|
|
||||||
} else {
|
|
||||||
// log.debug "Doors were opened. Wait a little longer."
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// log.debug "It appears a door is still open."
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -246,9 +246,6 @@ def toggle(devices) {
|
|||||||
else if (devices*.currentValue('lock').contains('locked')) {
|
else if (devices*.currentValue('lock').contains('locked')) {
|
||||||
devices.unlock()
|
devices.unlock()
|
||||||
}
|
}
|
||||||
else if (devices*.currentValue('lock').contains('unlocked')) {
|
|
||||||
devices.lock()
|
|
||||||
}
|
|
||||||
else if (devices*.currentValue('alarm').contains('off')) {
|
else if (devices*.currentValue('alarm').contains('off')) {
|
||||||
devices.siren()
|
devices.siren()
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user