mirror of
https://github.com/mtan93/SmartThingsPublic.git
synced 2026-03-08 05:31:56 +00:00
Compare commits
1 Commits
PROD_2017.
...
MSA-1866-1
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d38516f779 |
36
devicetypes/mcresci/motionjc.src/motionjc.groovy
Normal file
36
devicetypes/mcresci/motionjc.src/motionjc.groovy
Normal file
@@ -0,0 +1,36 @@
|
||||
/**
|
||||
* motionJC
|
||||
*
|
||||
* Copyright 2017 Maria Jesus Cresci
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
*/
|
||||
metadata {
|
||||
definition (name: "motionJC", namespace: "mcresci", author: "Maria Jesus Cresci") {
|
||||
capability "Motion Sensor"
|
||||
}
|
||||
|
||||
|
||||
simulator {
|
||||
// TODO: define status and reply messages here
|
||||
}
|
||||
|
||||
tiles {
|
||||
// TODO: define your main and details tiles here
|
||||
}
|
||||
}
|
||||
|
||||
// parse events into attributes
|
||||
def parse(String description) {
|
||||
log.debug "Parsing '${description}'"
|
||||
// TODO: handle 'motion' attribute
|
||||
|
||||
}
|
||||
48
devicetypes/mcresci/switch.src/switch.groovy
Normal file
48
devicetypes/mcresci/switch.src/switch.groovy
Normal file
@@ -0,0 +1,48 @@
|
||||
/**
|
||||
* Switch
|
||||
*
|
||||
* Copyright 2017 Maria Jesus Cresci
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
*/
|
||||
metadata {
|
||||
definition (name: "Switch", namespace: "mcresci", author: "Maria Jesus Cresci") {
|
||||
capability "Switch"
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
simulator {
|
||||
// TODO: define status and reply messages here
|
||||
}
|
||||
|
||||
tiles{
|
||||
|
||||
}
|
||||
|
||||
// parse events into attributes
|
||||
def parse(String description) {
|
||||
log.debug "Parsing '${description}'"
|
||||
// TODO: handle 'switch' attribute
|
||||
|
||||
}
|
||||
|
||||
// handle commands
|
||||
def on() {
|
||||
log.debug "Executing 'on'"
|
||||
// TODO: handle 'on' command
|
||||
}
|
||||
|
||||
def off() {
|
||||
log.debug "Executing 'off'"
|
||||
// TODO: handle 'off' command
|
||||
}
|
||||
47
devicetypes/mcresci/testjc.src/testjc.groovy
Normal file
47
devicetypes/mcresci/testjc.src/testjc.groovy
Normal file
@@ -0,0 +1,47 @@
|
||||
/**
|
||||
* testJC
|
||||
*
|
||||
* Copyright 2017 Maria Jesus Cresci
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
*/
|
||||
metadata {
|
||||
definition (name: "testJC", namespace: "mcresci", author: "Maria Jesus Cresci") {
|
||||
capability "Switch"
|
||||
}
|
||||
|
||||
|
||||
simulator {
|
||||
// TODO: define status and reply messages here
|
||||
}
|
||||
|
||||
tiles {
|
||||
// TODO: define your main and details tiles here
|
||||
}
|
||||
}
|
||||
|
||||
// parse events into attributes
|
||||
def parse(String description) {
|
||||
log.debug "Parsing '${description}'"
|
||||
// TODO: handle 'switch' attribute
|
||||
|
||||
}
|
||||
|
||||
// handle commands
|
||||
def on() {
|
||||
log.debug "Executing 'on'"
|
||||
theswitch.on()
|
||||
}
|
||||
|
||||
def off() {
|
||||
log.debug "Executing 'off'"
|
||||
theswitch.off()
|
||||
}
|
||||
110
smartapps/mcrescii/jcapp.src/jcapp.groovy
Normal file
110
smartapps/mcrescii/jcapp.src/jcapp.groovy
Normal file
@@ -0,0 +1,110 @@
|
||||
/**
|
||||
* jcApp
|
||||
*
|
||||
* Copyright 2017 Maria Jesus Cresci
|
||||
*
|
||||
* 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: "jcApp",
|
||||
namespace: "mcrescii",
|
||||
author: "Maria Jesus Cresci",
|
||||
description: "Description test",
|
||||
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")
|
||||
|
||||
|
||||
preferences {
|
||||
section("Turn on when motion detected:") {
|
||||
input "themotion", "capability.motionSensor", required: true, title: "Where?"
|
||||
}
|
||||
section("Send Push Notification?") {
|
||||
input "sendPush", "bool", required: false,
|
||||
title: "Send Push Notification when motion?"
|
||||
}
|
||||
section("Turn off when there's been no movement for") {
|
||||
input "minutes", "number", required: true, title: "Minutes?"
|
||||
}
|
||||
section("Turn on this light") {
|
||||
input "theswitch", "capability.switch", required: true
|
||||
}
|
||||
}
|
||||
|
||||
def installed() {
|
||||
initialize()
|
||||
}
|
||||
|
||||
def updated() {
|
||||
unsubscribe()
|
||||
initialize()
|
||||
}
|
||||
|
||||
def initialize() {
|
||||
subscribe(themotion, "motion.active", motionDetectedHandler)
|
||||
subscribe(themotion, "motion.inactive", motionStoppedHandler)
|
||||
subscribe(theswitch, "switch.off", switchOFFHandler)
|
||||
subscribe(theswitch, "switch.on", switchONHandler)
|
||||
}
|
||||
|
||||
def switchOFFHandler(evt){
|
||||
log.debug "switchOFFHandler called: $evt"
|
||||
if (sendPush) {
|
||||
sendPush("Switch OFF")
|
||||
}
|
||||
}
|
||||
|
||||
def switchONHandler(evt){
|
||||
log.debug "switchOFFHandler called: $evt"
|
||||
if (sendPush) {
|
||||
sendPush("Switch ON")
|
||||
}
|
||||
}
|
||||
|
||||
def motionDetectedHandler(evt) {
|
||||
log.debug "motionDetectedHandler called: $evt"
|
||||
theswitch.on()
|
||||
if (sendPush) {
|
||||
sendPush("Atenti, se detecto movimiento!")
|
||||
}
|
||||
}
|
||||
|
||||
def motionStoppedHandler(evt) {
|
||||
log.debug "motionStoppedHandler called: $evt"
|
||||
runIn(60 * minutes, checkMotion)
|
||||
}
|
||||
|
||||
def checkMotion() {
|
||||
log.debug "In checkMotion scheduled method"
|
||||
|
||||
def motionState = themotion.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 * minutes
|
||||
|
||||
if (elapsed >= threshold) {
|
||||
log.debug "Motion has stayed inactive long enough since last check ($elapsed ms): turning switch off"
|
||||
theswitch.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"
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: implement event handlers
|
||||
Reference in New Issue
Block a user