mirror of
https://github.com/mtan93/SmartThingsPublic.git
synced 2026-03-12 05:11:52 +00:00
Compare commits
1 Commits
MSA-1792-2
...
MSA-1799-1
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c8b38c1073 |
@@ -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())]
|
||||
}
|
||||
@@ -0,0 +1,95 @@
|
||||
/**
|
||||
* Web Services SmartApp
|
||||
*
|
||||
* Copyright 2017 Light Engine R&D
|
||||
*
|
||||
* 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: "Web Services SmartApp",
|
||||
namespace: "lightenginernd",
|
||||
author: "Light Engine R&D",
|
||||
description: "Web Services SmartApp 1st",
|
||||
category: "",
|
||||
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: "Web Services SmartApp", displayLink: "http://localhost:4567"]
|
||||
)
|
||||
|
||||
preferences {
|
||||
section ("Allow external service to control these things...") {
|
||||
input "switches", "capability.switch", multiple: true, required: true
|
||||
}
|
||||
}
|
||||
|
||||
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")
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
def installed() {
|
||||
log.debug "Installed with settings: ${settings}"
|
||||
|
||||
initialize()
|
||||
}
|
||||
|
||||
def updated() {
|
||||
log.debug "Updated with settings: ${settings}"
|
||||
|
||||
unsubscribe()
|
||||
initialize()
|
||||
}
|
||||
|
||||
def initialize() {
|
||||
// TODO: subscribe to attributes, devices, locations, etc.
|
||||
}
|
||||
|
||||
// TODO: implement event handlers
|
||||
Reference in New Issue
Block a user