mirror of
https://github.com/mtan93/SmartThingsPublic.git
synced 2026-03-13 13:21:53 +00:00
Compare commits
1 Commits
MSA-1786-1
...
MSA-1792-2
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
11501f4c31 |
@@ -0,0 +1,145 @@
|
||||
/**
|
||||
*
|
||||
*
|
||||
* 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())]
|
||||
}
|
||||
@@ -1,130 +0,0 @@
|
||||
/**
|
||||
* Smart Humidifier
|
||||
*
|
||||
* Copyright 2014 Sheikh Dawood
|
||||
*
|
||||
* 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: "Smart Dehumidifier",
|
||||
namespace: "Sheikhsphere",
|
||||
author: "Sheikh Dawood",
|
||||
description: "Turn on/off dehumidifier based on relative humidity from a sensor.",
|
||||
category: "Convenience",
|
||||
iconUrl: "https://graph.api.smartthings.com/api/devices/icons/st.Weather.weather12-icn",
|
||||
iconX2Url: "https://graph.api.smartthings.com/api/devices/icons/st.Weather.weather12-icn?displaySize=2x",
|
||||
iconX3Url: "https://graph.api.smartthings.com/api/devices/icons/st.Weather.weather12-icn?displaySize=3x",
|
||||
oauth: true)
|
||||
|
||||
|
||||
preferences {
|
||||
section("Monitor the humidity of:") {
|
||||
input "humiditySensor1", "capability.relativeHumidityMeasurement"
|
||||
}
|
||||
section("When the humidity rises above:") {
|
||||
input "humidityHigh", "number", title: "Percentage ?"
|
||||
}
|
||||
section("When the humidity drops below:") {
|
||||
input "humidityLow", "number", title: "Percentage ?"
|
||||
}
|
||||
section("Control Humidifier:") {
|
||||
input "switch1", "capability.switch"
|
||||
}
|
||||
section( "Notifications" ) {
|
||||
input "sendPushMessage", "enum", title: "Send a push notification?", metadata:[values:["Yes","No"]], required:false
|
||||
input "phone1", "phone", title: "Send a Text Message?", required: false
|
||||
}
|
||||
}
|
||||
|
||||
def installed() {
|
||||
subscribe(humiditySensor1, "humidity", humidityHandler)
|
||||
}
|
||||
|
||||
def updated() {
|
||||
unsubscribe()
|
||||
subscribe(humiditySensor1, "humidity", humidityHandler)
|
||||
}
|
||||
|
||||
def humidityHandler(evt) {
|
||||
log.trace "humidity: $evt.value"
|
||||
log.trace "set high point: $humidityHigh"
|
||||
log.trace "set low point: $humidityLow"
|
||||
|
||||
def currentHumidity = Double.parseDouble(evt.value.replace("%", ""))
|
||||
def humidityHigh1 = humidityHigh
|
||||
def humidityLow1 = humidityLow
|
||||
def mySwitch = settings.switch1
|
||||
|
||||
if (currentHumidity >= humidityHigh1) {
|
||||
log.debug "Checking how long the humidity sensor has been reporting >= $humidityHigh1"
|
||||
|
||||
// Don't send a continuous stream of text messages
|
||||
def deltaMinutes = 10
|
||||
def timeAgo = new Date(now() - (1000 * 60 * deltaMinutes).toLong())
|
||||
def recentEvents = humiditySensor1.eventsSince(timeAgo)
|
||||
log.trace "Found ${recentEvents?.size() ?: 0} events in the last $deltaMinutes minutes"
|
||||
def alreadySentSms1 = recentEvents.count { Double.parseDouble(it.value.replace("%", "")) >= humidityHigh1 } > 1
|
||||
|
||||
if (alreadySentSms1) {
|
||||
log.debug "Notification already sent within the last $deltaMinutes minutes"
|
||||
|
||||
} else {
|
||||
if (state.lastStatus != "on") {
|
||||
log.debug "Humidity Rose Above $humidityHigh1: sending SMS and deactivating $mySwitch"
|
||||
send("${humiditySensor1.label} sensed high humidity level of ${evt.value}, turning on ${switch1.label}")
|
||||
switch1?.on()
|
||||
state.lastStatus = "on"
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (currentHumidity <= humidityLow1) {
|
||||
log.debug "Checking how long the humidity sensor has been reporting <= $humidityLow1"
|
||||
|
||||
// Don't send a continuous stream of text messages
|
||||
def deltaMinutes = 10
|
||||
def timeAgo = new Date(now() - (1000 * 60 * deltaMinutes).toLong())
|
||||
def recentEvents = humiditySensor1.eventsSince(timeAgo)
|
||||
log.trace "Found ${recentEvents?.size() ?: 0} events in the last $deltaMinutes minutes"
|
||||
def alreadySentSms2 = recentEvents.count { Double.parseDouble(it.value.replace("%", "")) <= humidityLow1 } > 1
|
||||
|
||||
if (alreadySentSms2) {
|
||||
log.debug "Notification already sent within the last $deltaMinutes minutes"
|
||||
|
||||
} else {
|
||||
if (state.lastStatus != "off") {
|
||||
log.debug "Humidity Dropped Below $humidityLow1: sending SMS and activating $mySwitch"
|
||||
send("${humiditySensor1.label} sensed low humidity level of ${evt.value}, turning off ${switch1.label}")
|
||||
switch1?.off()
|
||||
state.lastStatus = "off"
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
//log.debug "Humidity remained in threshold: sending SMS to $phone1 and activating $mySwitch"
|
||||
//send("${humiditySensor1.label} sensed humidity level of ${evt.value} is within threshold, keeping off ${switch1.label}")
|
||||
//switch1?.off()
|
||||
}
|
||||
}
|
||||
|
||||
private send(msg) {
|
||||
if ( sendPushMessage != "No" ) {
|
||||
log.debug( "sending push message" )
|
||||
sendPush( msg )
|
||||
}
|
||||
|
||||
if ( phone1 ) {
|
||||
log.debug( "sending text message" )
|
||||
sendSms( phone1, msg )
|
||||
}
|
||||
|
||||
log.debug msg
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user