mirror of
https://github.com/mtan93/SmartThingsPublic.git
synced 2026-03-26 05:14:11 +00:00
Compare commits
1 Commits
MSA-1792-2
...
MSA-1782-1
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9558191c49 |
@@ -1,145 +0,0 @@
|
|||||||
/**
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* BeSense Z-Wave Motion Sensor
|
|
||||||
*
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
metadata {
|
|
||||||
definition (name: "BeSense Motion Sensor", namespace: "BeSense Sensors", author: "BeSense") {
|
|
||||||
capability "Motion Sensor"
|
|
||||||
capability "Sensor"
|
|
||||||
capability "Battery"
|
|
||||||
capability "Tamper Alert"
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
fingerprint mfr: "0214", prod: "0002", model: "0002", deviceJoinName: "Besense Motion Sensor" // Besense motion sensor
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
simulator {
|
|
||||||
status "inactive": "command: 3003, payload: 00"
|
|
||||||
status "active": "command: 3003, payload: FF"
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
tiles(scale: 1) {
|
|
||||||
standardTile("motion", "device.motion", width: 3, height: 3, canChangeIcon: true) {
|
|
||||||
state("active", label:'motion', icon:"st.motion.motion.active", backgroundColor:"#ea0f46", nextState:"inactive")
|
|
||||||
state("inactive", label:'no motion', icon:"st.motion.motion.inactive", backgroundColor:"#27CC73", nextState:"active")
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
valueTile("battery", "device.battery", inactiveLabel: false, decoration: "flat") {
|
|
||||||
state("battery", label:'${currentValue}% battery', unit:"")
|
|
||||||
}
|
|
||||||
|
|
||||||
main "motion"
|
|
||||||
details(["motion", "battery", "tamper"])
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
def parse(String description) {
|
|
||||||
def result = null
|
|
||||||
if (description.startsWith("Err")) {
|
|
||||||
result = createEvent(descriptionText:description)
|
|
||||||
} else {
|
|
||||||
def cmd = zwave.parse(description, [0x20: 1, 0x30:1, 0x80: 1, 0x84: 1, 0x71: 6, 0x9C: 1])
|
|
||||||
if (cmd) {
|
|
||||||
result = zwaveEvent(cmd)
|
|
||||||
} else {
|
|
||||||
result = createEvent(value: description, descriptionText: description, isStateChange: false)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return result
|
|
||||||
}
|
|
||||||
|
|
||||||
def zwaveEvent(physicalgraph.zwave.commands.alarmv2.AlarmReport cmd)
|
|
||||||
{
|
|
||||||
def map = [:]
|
|
||||||
map.name = "tamper"
|
|
||||||
map.value = cmd.alarmLevel == 255 ? "tampered" : "secured"
|
|
||||||
if (map.value == "tampered") {
|
|
||||||
map.value = "tampered"
|
|
||||||
map.descriptionText = "$device.displayName has been tampered with"
|
|
||||||
map.isStateChange = "true"
|
|
||||||
map.display = "true"
|
|
||||||
log.debug "tampered: $map"
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
map.value = "secured"
|
|
||||||
map.descriptionText = "$device.displayName is secured"
|
|
||||||
map.isStateChange = "true"
|
|
||||||
map.display = "true"
|
|
||||||
log.debug "secure: $map"
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
createEvent(map)
|
|
||||||
}
|
|
||||||
|
|
||||||
def sensorValueEvent(value) {
|
|
||||||
if (value) {
|
|
||||||
createEvent(name: "motion", value: "active", descriptionText: "$device.displayName detected motion")
|
|
||||||
} else {
|
|
||||||
createEvent(name: "motion", value: "inactive", descriptionText: "$device.displayName motion has stopped")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
def zwaveEvent(physicalgraph.zwave.commands.basicv1.BasicReport cmd)
|
|
||||||
{
|
|
||||||
sensorValueEvent(cmd.value)
|
|
||||||
}
|
|
||||||
|
|
||||||
def zwaveEvent(physicalgraph.zwave.commands.basicv1.BasicSet cmd)
|
|
||||||
{
|
|
||||||
sensorValueEvent(cmd.value)
|
|
||||||
}
|
|
||||||
|
|
||||||
def zwaveEvent(physicalgraph.zwave.commands.switchbinaryv1.SwitchBinaryReport cmd)
|
|
||||||
{
|
|
||||||
sensorValueEvent(cmd.value)
|
|
||||||
}
|
|
||||||
|
|
||||||
def zwaveEvent(physicalgraph.zwave.commands.sensorbinaryv1.SensorBinaryReport cmd)
|
|
||||||
{
|
|
||||||
sensorValueEvent(cmd.sensorValue)
|
|
||||||
}
|
|
||||||
|
|
||||||
def zwaveEvent(physicalgraph.zwave.commands.sensoralarmv1.SensorAlarmReport cmd)
|
|
||||||
{
|
|
||||||
sensorValueEvent(cmd.sensorState)
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
def zwaveEvent(physicalgraph.zwave.commands.wakeupv1.WakeUpNotification cmd)
|
|
||||||
{
|
|
||||||
def result = [createEvent(descriptionText: "${device.displayName} woke up", isStateChange: false)]
|
|
||||||
|
|
||||||
if (!state.lastbat || (new Date().time) - state.lastbat > 53*60*60*1000) {
|
|
||||||
result << response(zwave.batteryV1.batteryGet())
|
|
||||||
} else {
|
|
||||||
result << response(zwave.wakeUpV1.wakeUpNoMoreInformation())
|
|
||||||
}
|
|
||||||
result
|
|
||||||
}
|
|
||||||
|
|
||||||
def zwaveEvent(physicalgraph.zwave.commands.batteryv1.BatteryReport cmd) {
|
|
||||||
def map = [ name: "battery", unit: "%" ]
|
|
||||||
if (cmd.batteryLevel == 0xFF) {
|
|
||||||
map.value = 1
|
|
||||||
map.descriptionText = "${device.displayName} has a low battery"
|
|
||||||
map.isStateChange = true
|
|
||||||
} else {
|
|
||||||
map.value = cmd.batteryLevel
|
|
||||||
}
|
|
||||||
state.lastbat = new Date().time
|
|
||||||
[createEvent(map), response(zwave.wakeUpV1.wakeUpNoMoreInformation())]
|
|
||||||
}
|
|
||||||
@@ -14,7 +14,6 @@ metadata {
|
|||||||
capability "Refresh"
|
capability "Refresh"
|
||||||
capability "Sensor"
|
capability "Sensor"
|
||||||
capability "Health Check"
|
capability "Health Check"
|
||||||
capability "Light"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
simulator {
|
simulator {
|
||||||
|
|||||||
@@ -13,7 +13,6 @@ metadata {
|
|||||||
capability "Refresh"
|
capability "Refresh"
|
||||||
capability "Sensor"
|
capability "Sensor"
|
||||||
capability "Health Check"
|
capability "Health Check"
|
||||||
capability "Light"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
simulator {
|
simulator {
|
||||||
|
|||||||
@@ -36,7 +36,6 @@ metadata {
|
|||||||
capability "Switch"
|
capability "Switch"
|
||||||
capability "Refresh"
|
capability "Refresh"
|
||||||
capability "Contact Sensor"
|
capability "Contact Sensor"
|
||||||
capability "Light"
|
|
||||||
|
|
||||||
attribute "powered", "string"
|
attribute "powered", "string"
|
||||||
|
|
||||||
|
|||||||
@@ -23,7 +23,6 @@ Works with:
|
|||||||
* **Switch** - can detect state (possible values: on/off)
|
* **Switch** - can detect state (possible values: on/off)
|
||||||
* **Switch Level** - represents current light level, usually 0-100 in percent
|
* **Switch Level** - represents current light level, usually 0-100 in percent
|
||||||
* **Health Check** - indicates ability to get device health notifications
|
* **Health Check** - indicates ability to get device health notifications
|
||||||
* **Light** - indicates that the device belongs to Light category.
|
|
||||||
|
|
||||||
## Device Health
|
## Device Health
|
||||||
|
|
||||||
|
|||||||
@@ -22,7 +22,6 @@ metadata {
|
|||||||
capability "Switch"
|
capability "Switch"
|
||||||
capability "Switch Level"
|
capability "Switch Level"
|
||||||
capability "Health Check"
|
capability "Health Check"
|
||||||
capability "Light"
|
|
||||||
|
|
||||||
fingerprint profileId: "0104", inClusters: "0000, 0003, 0004, 0005, 0006, 0008, 0B04"
|
fingerprint profileId: "0104", inClusters: "0000, 0003, 0004, 0005, 0006, 0008, 0B04"
|
||||||
fingerprint profileId: "0104", inClusters: "0000, 0003, 0004, 0005, 0006, 0008, 0702"
|
fingerprint profileId: "0104", inClusters: "0000, 0003, 0004, 0005, 0006, 0008, 0702"
|
||||||
|
|||||||
@@ -21,7 +21,6 @@ metadata {
|
|||||||
capability "Sensor"
|
capability "Sensor"
|
||||||
capability "Switch"
|
capability "Switch"
|
||||||
capability "Health Check"
|
capability "Health Check"
|
||||||
capability "Light"
|
|
||||||
|
|
||||||
fingerprint profileId: "0104", inClusters: "0000, 0003, 0004, 0005, 0006, 0B04"
|
fingerprint profileId: "0104", inClusters: "0000, 0003, 0004, 0005, 0006, 0B04"
|
||||||
fingerprint profileId: "0104", inClusters: "0000, 0003, 0004, 0005, 0006, 0702"
|
fingerprint profileId: "0104", inClusters: "0000, 0003, 0004, 0005, 0006, 0702"
|
||||||
|
|||||||
@@ -6,12 +6,6 @@ Works with:
|
|||||||
|
|
||||||
* [Leviton Plug-in Lamp Dimmer Module (DZPD3-1LW)](https://www.smartthings.com/works-with-smartthings/outlets/leviton-plug-in-lamp-dimmer-module)
|
* [Leviton Plug-in Lamp Dimmer Module (DZPD3-1LW)](https://www.smartthings.com/works-with-smartthings/outlets/leviton-plug-in-lamp-dimmer-module)
|
||||||
* [Leviton Universal Dimmer (DZMX1-LZ)](https://www.smartthings.com/works-with-smartthings/switches-and-dimmers/leviton-universal-dimmer)
|
* [Leviton Universal Dimmer (DZMX1-LZ)](https://www.smartthings.com/works-with-smartthings/switches-and-dimmers/leviton-universal-dimmer)
|
||||||
* [Leviton 1000W Incandescent Dimmer](https://www.smartthings.com/works-with-smartthings/leviton/leviton-1000w-incandescent-dimmer)
|
|
||||||
* [Leviton 600W Incandescent Dimmer](https://www.smartthings.com/works-with-smartthings/leviton/leviton-600w-incandescent-dimmer)
|
|
||||||
* [Enerwave In-Wall Dimmer](https://www.smartthings.com/works-with-smartthings/enerwave/enerwave-in-wall-dimmer-zw500d)
|
|
||||||
* [Leviton 3-Speed Fan Controller](https://www.smartthings.com/works-with-smartthings/leviton/leviton-3-speed-fan-controller)
|
|
||||||
* [Leviton Magnetic Low Voltage Dimmer](https://www.smartthings.com/works-with-smartthings/leviton/leviton-magnetic-low-voltage-dimmer)
|
|
||||||
* [Remotec Technology Plug-In Dimmer](https://www.smartthings.com/works-with-smartthings/remotec-technology/remotec-technology-plug-in-dimmer)
|
|
||||||
|
|
||||||
## Table of contents
|
## Table of contents
|
||||||
|
|
||||||
@@ -46,9 +40,4 @@ If the device doesn't pair when trying from the SmartThings mobile app, it is po
|
|||||||
Pairing needs to be tried again by placing the device closer to the hub.
|
Pairing needs to be tried again by placing the device closer to the hub.
|
||||||
Instructions related to pairing, resetting and removing the device from SmartThings can be found in the following link:
|
Instructions related to pairing, resetting and removing the device from SmartThings can be found in the following link:
|
||||||
* [Leviton Plug-in Lamp Dimmer Module (DZPD3-1LW) Troubleshooting Tips](https://support.smartthings.com/hc/en-us/articles/206171053-How-to-connect-Leviton-Z-Wave-devices)
|
* [Leviton Plug-in Lamp Dimmer Module (DZPD3-1LW) Troubleshooting Tips](https://support.smartthings.com/hc/en-us/articles/206171053-How-to-connect-Leviton-Z-Wave-devices)
|
||||||
* [Leviton Universal Dimmer (DZMX1-LZ) Troubleshooting Tips](https://support.smartthings.com/hc/en-us/articles/206171053-How-to-connect-Leviton-Z-Wave-devices)
|
* [Leviton Universal Dimmer (DZMX1-LZ) Troubleshooting Tips](https://support.smartthings.com/hc/en-us/articles/206171053-How-to-connect-Leviton-Z-Wave-devices)
|
||||||
* [Leviton 1000W Incandescent Dimmer Troubleshooting Tips](https://support.smartthings.com/hc/en-us/articles/206171053-How-to-connect-Leviton-Z-Wave-devices)
|
|
||||||
* [Leviton 600W Incandescent Dimmer Troubleshooting Tips](https://support.smartthings.com/hc/en-us/articles/206171053-How-to-connect-Leviton-Z-Wave-devices)
|
|
||||||
* [Leviton 3-Speed Fan Controller Troubleshooting Tips](https://support.smartthings.com/hc/en-us/articles/206171053-How-to-connect-Leviton-Z-Wave-devices)
|
|
||||||
* [Enerwave In-Wall Dimmer Troubleshooting Tips](https://support.smartthings.com/hc/en-us/articles/204854176-How-to-connect-Enerwave-switches-and-dimmers)
|
|
||||||
* [Remotec Technology Plug-In Dimmer Troubleshooting Tips](https://support.smartthings.com/hc/en-us/articles/202295150-Remotec-Technology-Plug-In-Dimmer-ZDS-100-)
|
|
||||||
@@ -20,7 +20,6 @@ metadata {
|
|||||||
capability "Polling"
|
capability "Polling"
|
||||||
capability "Refresh"
|
capability "Refresh"
|
||||||
capability "Sensor"
|
capability "Sensor"
|
||||||
capability "Light"
|
|
||||||
|
|
||||||
fingerprint inClusters: "0x26", deviceJoinName: "Z-Wave Dimmer"
|
fingerprint inClusters: "0x26", deviceJoinName: "Z-Wave Dimmer"
|
||||||
fingerprint mfr:"001D", prod:"1902", deviceJoinName: "Z-Wave Dimmer"
|
fingerprint mfr:"001D", prod:"1902", deviceJoinName: "Z-Wave Dimmer"
|
||||||
@@ -29,8 +28,6 @@ metadata {
|
|||||||
fingerprint mfr:"001D", prod:"1001", model:"0334", deviceJoinName: "Leviton 3-Speed Fan Controller"
|
fingerprint mfr:"001D", prod:"1001", model:"0334", deviceJoinName: "Leviton 3-Speed Fan Controller"
|
||||||
fingerprint mfr:"001D", prod:"0602", model:"0334", deviceJoinName: "Leviton Magnetic Low Voltage Dimmer"
|
fingerprint mfr:"001D", prod:"0602", model:"0334", deviceJoinName: "Leviton Magnetic Low Voltage Dimmer"
|
||||||
fingerprint mfr:"001D", prod:"0401", model:"0334", deviceJoinName: "Leviton 600W Incandescent Dimmer"
|
fingerprint mfr:"001D", prod:"0401", model:"0334", deviceJoinName: "Leviton 600W Incandescent Dimmer"
|
||||||
fingerprint mfr:"0111", prod:"8200", model:"0200", deviceJoinName: "Remotec Technology Plug-In Dimmer"
|
|
||||||
fingerprint mfr:"1104", prod:"001D", model:"0501", deviceJoinName: "Leviton 1000W Incandescant Dimmer"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
simulator {
|
simulator {
|
||||||
|
|||||||
@@ -25,7 +25,6 @@ metadata {
|
|||||||
capability "Switch Level"
|
capability "Switch Level"
|
||||||
capability "Sensor"
|
capability "Sensor"
|
||||||
capability "Actuator"
|
capability "Actuator"
|
||||||
capability "Light"
|
|
||||||
|
|
||||||
command "reset"
|
command "reset"
|
||||||
|
|
||||||
|
|||||||
@@ -21,7 +21,6 @@ metadata {
|
|||||||
capability "Refresh"
|
capability "Refresh"
|
||||||
capability "Configuration"
|
capability "Configuration"
|
||||||
capability "Sensor"
|
capability "Sensor"
|
||||||
capability "Light"
|
|
||||||
|
|
||||||
command "reset"
|
command "reset"
|
||||||
|
|
||||||
|
|||||||
@@ -19,7 +19,6 @@ metadata {
|
|||||||
capability "Polling"
|
capability "Polling"
|
||||||
capability "Refresh"
|
capability "Refresh"
|
||||||
capability "Sensor"
|
capability "Sensor"
|
||||||
capability "Light"
|
|
||||||
|
|
||||||
fingerprint inClusters: "0x25", deviceJoinName: "Z-Wave Switch"
|
fingerprint inClusters: "0x25", deviceJoinName: "Z-Wave Switch"
|
||||||
fingerprint mfr:"001D", prod:"1A02", model:"0334", deviceJoinName: "Leviton Appliance Module"
|
fingerprint mfr:"001D", prod:"1A02", model:"0334", deviceJoinName: "Leviton Appliance Module"
|
||||||
@@ -27,8 +26,6 @@ metadata {
|
|||||||
fingerprint mfr:"001D", prod:"1D04", model:"0334", deviceJoinName: "Leviton Outlet"
|
fingerprint mfr:"001D", prod:"1D04", model:"0334", deviceJoinName: "Leviton Outlet"
|
||||||
fingerprint mfr:"001D", prod:"1C02", model:"0334", deviceJoinName: "Leviton Switch"
|
fingerprint mfr:"001D", prod:"1C02", model:"0334", deviceJoinName: "Leviton Switch"
|
||||||
fingerprint mfr:"001D", prod:"0301", model:"0334", deviceJoinName: "Leviton 15A Switch"
|
fingerprint mfr:"001D", prod:"0301", model:"0334", deviceJoinName: "Leviton 15A Switch"
|
||||||
fingerprint mfr:"001D", prod:"0F01", model:"0334", deviceJoinName: "Leviton 5A Incandescent Switch"
|
|
||||||
fingerprint mfr:"001D", prod:"1603", model:"0334", deviceJoinName: "Leviton 15A Split Duplex Receptacle"
|
|
||||||
fingerprint mfr:"011A", prod:"0101", model:"0102", deviceJoinName: "Enerwave On/Off Switch"
|
fingerprint mfr:"011A", prod:"0101", model:"0102", deviceJoinName: "Enerwave On/Off Switch"
|
||||||
fingerprint mfr:"011A", prod:"0101", model:"0603", deviceJoinName: "Enerwave Duplex Receptacle"
|
fingerprint mfr:"011A", prod:"0101", model:"0603", deviceJoinName: "Enerwave Duplex Receptacle"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,7 +20,6 @@ metadata {
|
|||||||
capability "Refresh"
|
capability "Refresh"
|
||||||
capability "Sensor"
|
capability "Sensor"
|
||||||
capability "Health Check"
|
capability "Health Check"
|
||||||
capability "Light"
|
|
||||||
|
|
||||||
fingerprint mfr:"0063", prod:"4952", deviceJoinName: "Z-Wave Wall Switch"
|
fingerprint mfr:"0063", prod:"4952", deviceJoinName: "Z-Wave Wall Switch"
|
||||||
fingerprint mfr:"0063", prod:"5257", deviceJoinName: "Z-Wave Wall Switch"
|
fingerprint mfr:"0063", prod:"5257", deviceJoinName: "Z-Wave Wall Switch"
|
||||||
|
|||||||
@@ -0,0 +1,179 @@
|
|||||||
|
/**
|
||||||
|
* Switch control based on motion/door sensors
|
||||||
|
*
|
||||||
|
* Copyright 2017 narges noori
|
||||||
|
*
|
||||||
|
* 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: "Switch control based on motion/door sensors",
|
||||||
|
namespace: "nnoori0527",
|
||||||
|
author: "narges noori",
|
||||||
|
description: "This application turns on the outlet if the entrace door opens (multipurpose sensor) and there is motion in front of the motion sensor for a user defined amount of time (say 5 minutes). If there is no activity in front of the motion sensor for a user defined amount of time (say 10 minutes) the outlet is turned off.",
|
||||||
|
category: "Convenience",
|
||||||
|
iconUrl: "https://s3.amazonaws.com/smartapp-icons/Convenience/Cat-Convenience.png",
|
||||||
|
iconX2Url: "https://s3.amazonaws.com/smartapp-icons/Convenience/Cat-Convenience@2x.png",
|
||||||
|
iconX3Url: "https://s3.amazonaws.com/smartapp-icons/Convenience/Cat-Convenience@2x.png",
|
||||||
|
oauth: [displayName: "Switch/outlet control", displayLink: ""])
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
preferences {
|
||||||
|
|
||||||
|
section ("Allow external service to control these things...") {
|
||||||
|
input "switches", "capability.switch", multiple: true, required: true
|
||||||
|
}
|
||||||
|
|
||||||
|
section("Turn on when motion detected after someone opens the door:") {
|
||||||
|
input "motionSensor", "capability.motionSensor", required: true, title: "Where?"
|
||||||
|
}
|
||||||
|
|
||||||
|
section("Turn on when there's movement for:") {
|
||||||
|
input "minutes", "number", required: true, title: "Minutes to turn on TV?"
|
||||||
|
}
|
||||||
|
section("Turn on when there's movement for:") {
|
||||||
|
input "minutesInactive", "number", required: true, title: "Minutes to wait before turning off TV?"
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
section("Turn on when door open:") {
|
||||||
|
input "doorOpenCloseDetector", "capability.contactSensor", required: true, title: "Where?"
|
||||||
|
}
|
||||||
|
|
||||||
|
section("Turn on this outlet") {
|
||||||
|
input "tvOutlet", "capability.switch", required: true
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
def installed() {
|
||||||
|
initialize()
|
||||||
|
}
|
||||||
|
|
||||||
|
def updated() {
|
||||||
|
unsubscribe()
|
||||||
|
initialize()
|
||||||
|
}
|
||||||
|
|
||||||
|
def initialize() {
|
||||||
|
subscribe(doorOpenCloseDetector, "contact.open", doorOpenedHandler)
|
||||||
|
subscribe(motionSensor, "motion.inactive", motionStoppedHandler)
|
||||||
|
}
|
||||||
|
|
||||||
|
def doorOpenedHandler(evt){
|
||||||
|
log.debug "doorOpenedHandler called: $evt"
|
||||||
|
runIn(60 * minutes, checkMotion)
|
||||||
|
//tvOutlet.on()
|
||||||
|
}
|
||||||
|
|
||||||
|
def checkMotion() {
|
||||||
|
log.debug "In checkMotion scheduled method"
|
||||||
|
|
||||||
|
def motionState = motionSensor.currentState("motion")
|
||||||
|
|
||||||
|
if (motionState.value == "active") {
|
||||||
|
// get the time elapsed between now and when the motion reported inactive
|
||||||
|
def elapsed = now() - motionState.date.time
|
||||||
|
|
||||||
|
// elapsed time is in milliseconds, so the threshold must be converted to milliseconds too
|
||||||
|
def threshold = 1000 * 60 * minutes
|
||||||
|
|
||||||
|
if (elapsed <= threshold) {
|
||||||
|
log.debug "Motion has stayed active long enough since last check ($elapsed ms): turning outlet on"
|
||||||
|
//myswitch.on()
|
||||||
|
tvOutlet.on()
|
||||||
|
} else {
|
||||||
|
log.debug "Motion has not stayed active long enough since last check ($elapsed ms): doing nothing"
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// Motion active; just log it and do nothing
|
||||||
|
log.debug "Motion is inactive, do nothing and wait for active"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
def motionStoppedHandler(evt) {
|
||||||
|
log.debug "motionStoppedHandler called: $evt"
|
||||||
|
runIn(60 * (minutesInactive+1), checkMotionTurnOff)
|
||||||
|
}
|
||||||
|
|
||||||
|
def checkMotionTurnOff() {
|
||||||
|
log.debug "In checkMotionTurnOff scheduled method"
|
||||||
|
|
||||||
|
def motionState = motionSensor.currentState("motion")
|
||||||
|
|
||||||
|
if (motionState.value == "inactive") {
|
||||||
|
// get the time elapsed between now and when the motion reported inactive
|
||||||
|
def elapsed = now() - motionState.date.time
|
||||||
|
|
||||||
|
// elapsed time is in milliseconds, so the threshold must be converted to milliseconds too
|
||||||
|
def threshold = 1000 * 60 * minutesInactive
|
||||||
|
|
||||||
|
if (elapsed >= threshold) {
|
||||||
|
log.debug "Motion has stayed inactive long enough since last check ($elapsed ms): turning switch off"
|
||||||
|
tvOutlet.off()
|
||||||
|
} else {
|
||||||
|
log.debug "Motion has not stayed inactive long enough since last check ($elapsed ms): doing nothing"
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// Motion active; just log it and do nothing
|
||||||
|
log.debug "Motion is active, do nothing and wait for inactive"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
mappings {
|
||||||
|
path("/switches") {
|
||||||
|
action: [
|
||||||
|
GET: "listSwitches"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
path("/switches/:command") {
|
||||||
|
action: [
|
||||||
|
PUT: "updateSwitches"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// returns a list like
|
||||||
|
// [[name: "kitchen lamp", value: "off"], [name: "bathroom", value: "on"]]
|
||||||
|
def listSwitches() {
|
||||||
|
|
||||||
|
def resp = []
|
||||||
|
switches.each {
|
||||||
|
resp << [name: it.displayName, value: it.currentValue("switch")]
|
||||||
|
}
|
||||||
|
return resp
|
||||||
|
}
|
||||||
|
|
||||||
|
void updateSwitches() {
|
||||||
|
// use the built-in request object to get the command parameter
|
||||||
|
def command = params.command
|
||||||
|
|
||||||
|
// all switches have the comand
|
||||||
|
// execute the command on all switches
|
||||||
|
// (note we can do this on the array - the command will be invoked on every element
|
||||||
|
switch(command) {
|
||||||
|
case "on":
|
||||||
|
switches.on()
|
||||||
|
break
|
||||||
|
case "off":
|
||||||
|
switches.off()
|
||||||
|
break
|
||||||
|
default:
|
||||||
|
httpError(400, "$command is not a valid command for all switches specified")
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Reference in New Issue
Block a user