mirror of
https://github.com/mtan93/SmartThingsPublic.git
synced 2026-03-14 13:11:52 +00:00
Compare commits
6 Commits
MSA-2031-1
...
MSA-2042-1
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c5d0798935 | ||
|
|
be9bdae4cc | ||
|
|
c278e035f6 | ||
|
|
d6b0f6a8ed | ||
|
|
62c810ba90 | ||
|
|
fb8e4a2416 |
@@ -300,15 +300,21 @@ def setColor(value) {
|
||||
value.hex = "#${hex(value.red)}${hex(value.green)}${hex(value.blue)}"
|
||||
}
|
||||
|
||||
sendEvent(name: "hue", value: value.hue, displayed: false)
|
||||
sendEvent(name: "saturation", value: value.saturation, displayed: false)
|
||||
sendEvent(name: "color", value: value.hex, displayed: false)
|
||||
if (value.level) {
|
||||
sendEvent(name: "level", value: value.level)
|
||||
}
|
||||
if (value.switch) {
|
||||
sendEvent(name: "switch", value: value.switch)
|
||||
}
|
||||
if(value.hue) {
|
||||
sendEvent(name: "hue", value: value.hue, displayed: false)
|
||||
}
|
||||
if(value.saturation) {
|
||||
sendEvent(name: "saturation", value: value.saturation, displayed: false)
|
||||
}
|
||||
if(value.hex?.trim()) {
|
||||
sendEvent(name: "color", value: value.hex, displayed: false)
|
||||
}
|
||||
if (value.level) {
|
||||
sendEvent(name: "level", value: value.level)
|
||||
}
|
||||
if (value.switch?.trim()) {
|
||||
sendEvent(name: "switch", value: value.switch)
|
||||
}
|
||||
|
||||
sendRGB(value.rh, value.gh, value.bh)
|
||||
}
|
||||
|
||||
@@ -56,6 +56,8 @@ metadata {
|
||||
def installed(){
|
||||
// Device-Watch simply pings if no device events received for 32min(checkInterval)
|
||||
sendEvent(name: "checkInterval", value: 2 * 15 * 60 + 2 * 60, displayed: false, data: [protocol: "zwave", hubHardwareId: device.hub.hardwareID])
|
||||
|
||||
response(refresh())
|
||||
}
|
||||
|
||||
def updated(){
|
||||
@@ -85,11 +87,17 @@ def zwaveEvent(physicalgraph.zwave.Command cmd) {
|
||||
}
|
||||
|
||||
def open() {
|
||||
zwave.switchBinaryV1.switchBinarySet(switchValue: 0x00).format()
|
||||
delayBetween([
|
||||
zwave.switchBinaryV1.switchBinarySet(switchValue: 0x00).format(),
|
||||
zwave.switchBinaryV1.switchBinaryGet().format()
|
||||
], 500)
|
||||
}
|
||||
|
||||
def close() {
|
||||
zwave.switchBinaryV1.switchBinarySet(switchValue: 0xFF).format()
|
||||
delayBetween([
|
||||
zwave.switchBinaryV1.switchBinarySet(switchValue: 0xFF).format(),
|
||||
zwave.switchBinaryV1.switchBinaryGet().format()
|
||||
], 500)
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -105,6 +113,6 @@ def refresh() {
|
||||
|
||||
def createEventWithDebug(eventMap) {
|
||||
def event = createEvent(eventMap)
|
||||
log.debug "Event created with ${event?.descriptionText}"
|
||||
log.debug "Event created with ${event?.name}:${event?.value} - ${event?.descriptionText}"
|
||||
return event
|
||||
}
|
||||
|
||||
@@ -1,317 +0,0 @@
|
||||
/**
|
||||
* RealApplication_CA
|
||||
*
|
||||
* Copyright 2017 Venkata Kishore Chilakala
|
||||
*
|
||||
* 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: "RealApplication_CA",
|
||||
namespace: "CA",
|
||||
author: "Venkata Kishore Chilakala",
|
||||
description: "myApp",
|
||||
category: "SmartThings Labs",
|
||||
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")
|
||||
|
||||
|
||||
preferences {
|
||||
section("Allow External Service to Control These Things...")
|
||||
{
|
||||
|
||||
input "motions", "capability.motionSensor", title: "Which Motion Sensors?", multiple: true, required: false
|
||||
input "contacts", "capability.contactSensor",title: "Which Contact Sensor?", multiple: true, required: false
|
||||
input "presences", "capability.presenceSensor",title: "Which Presence Sensor?", multiple: true, required: false
|
||||
input "switches", "capability.switchLevel", title: "Which Switches?", multiple: true, required: false
|
||||
input "levelSwitches","capability.switchLevel",title: "Which Level Switch?",multiple: true, required:false
|
||||
input "relativeHumidity","capability.relativeHumidityMeasurement",title: "Humidity",multiple:true,required:false
|
||||
input "temperature","capability.temperatureMeasurement",title: "Temperature Measurement",multiple:true,required:false
|
||||
input "lock","capability.lock",title: "Door Lock", multiple:true,required:false
|
||||
input "hubs",title: "Hubs",multiple:false,required:false
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
def installed() {
|
||||
initialize()
|
||||
}
|
||||
|
||||
def updated() {
|
||||
initialize()
|
||||
}
|
||||
|
||||
mappings {
|
||||
|
||||
path("/devices")
|
||||
{
|
||||
action:[
|
||||
GET:"listDevices"
|
||||
]
|
||||
}
|
||||
|
||||
path("/hubs") {
|
||||
log.debug "list action"
|
||||
action: [
|
||||
GET: "listAll"
|
||||
]
|
||||
}
|
||||
|
||||
path("/switches") {
|
||||
action: [
|
||||
GET:"listSwitches",
|
||||
PUT:"updateSwitches"
|
||||
]
|
||||
}
|
||||
path("/switches/:id") {
|
||||
action: [
|
||||
GET:"showSwitch",
|
||||
PUT:"updateSwitch"
|
||||
]
|
||||
}
|
||||
path("/levelSwitches") {
|
||||
action: [
|
||||
GET:"listLevelSwitches",
|
||||
PUT:"updateLevelSwitches"
|
||||
]
|
||||
}
|
||||
path("/levelSwitches/:id") {
|
||||
action: [
|
||||
GET:"showLevelSwitch",
|
||||
PUT:"updateLevelSwitch"
|
||||
]
|
||||
}
|
||||
path("/motions") {
|
||||
|
||||
action: [
|
||||
GET:"listMotions",
|
||||
PUT:"updateMotions"
|
||||
]
|
||||
}
|
||||
path("/motions/:id"){
|
||||
action:[
|
||||
GET:"showMotion",
|
||||
PUT:"updateMotion"
|
||||
]
|
||||
}
|
||||
path("/presences")
|
||||
{
|
||||
action:[
|
||||
GET:"listPresenceSensor",
|
||||
PUT:"updatePresenceSensor"
|
||||
]
|
||||
}
|
||||
path("/presences/:id")
|
||||
{
|
||||
action:[
|
||||
GET:"showPresence",
|
||||
PUT:"updatePresence"
|
||||
]
|
||||
}
|
||||
path("/locks") {
|
||||
action: [
|
||||
GET:"listLocks",
|
||||
PUT:"updateLocks"
|
||||
]
|
||||
}
|
||||
|
||||
path("/locks/:id") {
|
||||
action: [
|
||||
GET:"showLock",
|
||||
PUT:"updateLock"
|
||||
]
|
||||
}
|
||||
path("/contacts")
|
||||
{
|
||||
action: [
|
||||
GET: "listContacts",
|
||||
PUP: "updateContacts"
|
||||
]
|
||||
}
|
||||
path ("/contacts/:id")
|
||||
{
|
||||
action:[
|
||||
GET:"showContact",
|
||||
PUT:"updateContact"
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
def listAll()
|
||||
{
|
||||
[location_id :location.id,hub_id:location.hubs*.id,hub_type:location.hubs*.type,hub_name:location.hubs*.name,hub_firm_ver:location.hubs*.firmwareVersionString,hub_ip:location.hubs*.localIP,hub_port:location.hubs*.localSrvPortTCP]
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
def listSwitches() {
|
||||
switches.collect { device(it,"switch") }
|
||||
}
|
||||
void updateSwitches() {
|
||||
updateAll(switches)
|
||||
}
|
||||
def showSwitch() {
|
||||
show(switches, "switch")
|
||||
}
|
||||
void updateSwitch() {
|
||||
update(switches)
|
||||
}
|
||||
def listLevelSwitches() {
|
||||
|
||||
levelSwitches.collect { device(it,"level") }
|
||||
// motions.collect { device(it,"motion") }
|
||||
}
|
||||
void updateLevelSwitches() {
|
||||
updateAll(levelSwitches)
|
||||
}
|
||||
def showLevelSwitch() {
|
||||
show(levelSwitches, "level")
|
||||
}
|
||||
void updateLevelSwitch() {
|
||||
update(levelSwitches)
|
||||
}
|
||||
|
||||
def listLocks() {
|
||||
lock.collect { device(it,"lock") }
|
||||
}
|
||||
void updateLocks() {
|
||||
updateAll(lock)
|
||||
}
|
||||
def showLock() {
|
||||
show(lock, "lock")
|
||||
}
|
||||
void updateLock() {
|
||||
update(lock)
|
||||
}
|
||||
|
||||
def listMotions() {
|
||||
motions.collect { device(it,"motion") }
|
||||
}
|
||||
void updateMotions()
|
||||
{
|
||||
updateAll(motions)
|
||||
}
|
||||
def showMotion()
|
||||
{
|
||||
show(motions, "motion")
|
||||
}
|
||||
void updateMotion()
|
||||
{
|
||||
update(motions)
|
||||
}
|
||||
|
||||
def listPresenceSensor()
|
||||
{
|
||||
presences.collect{device(it,"presence")}
|
||||
}
|
||||
void updatePresenceSensor()
|
||||
{
|
||||
updateAll(presences)
|
||||
}
|
||||
def showPresence()
|
||||
{
|
||||
show(presences,"presence")
|
||||
}
|
||||
void updatePresence()
|
||||
{
|
||||
update(presences)
|
||||
}
|
||||
|
||||
def listContacts(){
|
||||
|
||||
contacts.collect{device(it,"contact")}
|
||||
}
|
||||
void updateContacts()
|
||||
{
|
||||
updateAll(contacts)
|
||||
}
|
||||
def showContact()
|
||||
{
|
||||
show(contacts,"contact")
|
||||
}
|
||||
void updateContact()
|
||||
{
|
||||
update(contacts)
|
||||
}
|
||||
|
||||
|
||||
|
||||
private device(it, name) {
|
||||
if (it) {
|
||||
def s = it.currentState(name)
|
||||
[
|
||||
id: it.id,
|
||||
name: it.displayName,
|
||||
label: it.displayName,
|
||||
hub_name: it.hub.name,
|
||||
hub_id: it.hub.id,
|
||||
hub_ip: it.hub.localIP,
|
||||
hub_port: it.hub.localSrvPortTCP,
|
||||
state: s
|
||||
]
|
||||
}
|
||||
}
|
||||
private void updateAll(devices) {
|
||||
def command = request.JSON?.command
|
||||
if (command) {
|
||||
devices."$command"()
|
||||
}
|
||||
}
|
||||
private show(devices, name) {
|
||||
def device = devices.find { it.id == params.id }
|
||||
if (!device) {
|
||||
httpError(404, "Device not found")
|
||||
}
|
||||
else {
|
||||
log.debug " state s :: ${s}"
|
||||
log.debug "devices :: ${devices}"
|
||||
log.debug "name :: ${name}"
|
||||
def s = device.currentState(name)
|
||||
[id: device.id, label: device.displayName, name: device.displayName,state:s]
|
||||
}
|
||||
}
|
||||
private void update(devices) {
|
||||
log.debug "update, request: ${request.JSON}, params: ${params}, devices: $devices.id"
|
||||
def command = request.JSON?.command
|
||||
def value = request.JSON?.value
|
||||
|
||||
log.debug "$value"
|
||||
log.debug "$command"
|
||||
|
||||
if (command) {
|
||||
def device = devices.find { it.id == params.id }
|
||||
if (!device) {
|
||||
httpError(404, "Device not found")
|
||||
} else {
|
||||
|
||||
if("$command"=="on")
|
||||
{
|
||||
device."$command"()
|
||||
}else if("$command"=="off")
|
||||
{
|
||||
device."$command"()
|
||||
}else if("$command"=="lock")
|
||||
{
|
||||
device."$command"()
|
||||
}else if("$command"=="unlock")
|
||||
{
|
||||
device."$command"()
|
||||
}else
|
||||
{
|
||||
device.setLevel("$command")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
def initialize() {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,97 @@
|
||||
/**
|
||||
* 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.
|
||||
*
|
||||
* Left It Open
|
||||
*
|
||||
* Author: SmartThings
|
||||
* Date: 2013-05-09
|
||||
*/
|
||||
definition(
|
||||
name: "Left It Open (Set switch)",
|
||||
namespace: "smartthings",
|
||||
author: "SmartThings",
|
||||
description: "Turns on a switch if you have left a door or window open longer that a specified amount of time. Turns if off when closed",
|
||||
category: "Convenience",
|
||||
iconUrl: "https://s3.amazonaws.com/smartapp-icons/ModeMagic/bon-voyage.png",
|
||||
iconX2Url: "https://s3.amazonaws.com/smartapp-icons/ModeMagic/bon-voyage%402x.png"
|
||||
)
|
||||
|
||||
preferences {
|
||||
|
||||
section("Monitor this door or window") {
|
||||
input "contact", "capability.contactSensor"
|
||||
}
|
||||
section("And notify me if it's open for more than this many minutes (default 10)") {
|
||||
input "openThreshold", "number", description: "Number of minutes", required: false
|
||||
}
|
||||
section("Turn on/off a switch... (usually a simulated one)") {
|
||||
input "switch1", "capability.switch"
|
||||
}
|
||||
}
|
||||
|
||||
def installed() {
|
||||
log.trace "installed()"
|
||||
subscribe()
|
||||
}
|
||||
|
||||
def updated() {
|
||||
log.trace "updated()"
|
||||
unsubscribe()
|
||||
subscribe()
|
||||
}
|
||||
|
||||
def subscribe() {
|
||||
subscribe(contact, "contact.open", doorOpen)
|
||||
subscribe(contact, "contact.closed", doorClosed)
|
||||
}
|
||||
|
||||
def doorOpen(evt)
|
||||
{
|
||||
log.trace "doorOpen($evt.name: $evt.value)"
|
||||
def t0 = now()
|
||||
def delay = (openThreshold != null && openThreshold != "") ? openThreshold * 60 : 600
|
||||
runIn(delay, doorOpenTooLong, [overwrite: false])
|
||||
log.debug "scheduled doorOpenTooLong in ${now() - t0} msec"
|
||||
}
|
||||
|
||||
def doorClosed(evt)
|
||||
{
|
||||
log.trace "doorClosed($evt.name: $evt.value)"
|
||||
switch1.off()
|
||||
}
|
||||
|
||||
def doorOpenTooLong() {
|
||||
def contactState = contact.currentState("contact")
|
||||
def freq = (frequency != null && frequency != "") ? frequency * 60 : 600
|
||||
|
||||
if (contactState.value == "open") {
|
||||
def elapsed = now() - contactState.rawDateCreated.time
|
||||
def threshold = ((openThreshold != null && openThreshold != "") ? openThreshold * 60000 : 60000) - 1000
|
||||
if (elapsed >= threshold) {
|
||||
log.debug "Contact has stayed open long enough since last check ($elapsed ms): calling sendMessage()"
|
||||
sendMessage()
|
||||
runIn(freq, doorOpenTooLong, [overwrite: false])
|
||||
} else {
|
||||
log.debug "Contact has not stayed open long enough since last check ($elapsed ms): doing nothing"
|
||||
}
|
||||
} else {
|
||||
log.warn "doorOpenTooLong() called but contact is closed: doing nothing"
|
||||
}
|
||||
}
|
||||
|
||||
void sendMessage()
|
||||
{
|
||||
def minutes = (openThreshold != null && openThreshold != "") ? openThreshold : 10
|
||||
def msg = "${contact.displayName} has been left open for ${minutes} minutes."
|
||||
log.info msg
|
||||
switch1.on()
|
||||
}
|
||||
Reference in New Issue
Block a user