mirror of
https://github.com/mtan93/SmartThingsPublic.git
synced 2026-03-09 05:11:52 +00:00
Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1e325a1a07 |
@@ -1,129 +0,0 @@
|
||||
/**
|
||||
* 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.
|
||||
*
|
||||
* Alfred Workflow
|
||||
*
|
||||
* Author: SmartThings
|
||||
*/
|
||||
|
||||
definition(
|
||||
name: "윤정은",
|
||||
namespace: "윤정은",
|
||||
author: "SmartThings",
|
||||
description: "This SmartApp allows you to interact with the things in your physical graph through Alfred.",
|
||||
category: "Convenience",
|
||||
iconUrl: "https://s3.amazonaws.com/smartapp-icons/Partner/alfred-app.png",
|
||||
iconX2Url: "https://s3.amazonaws.com/smartapp-icons/Partner/alfred-app@2x.png",
|
||||
oauth: [displayName: "SmartThings Alfred Workflow", displayLink: ""]
|
||||
)
|
||||
|
||||
preferences {
|
||||
section("Allow Alfred to Control These Things...") {
|
||||
input "switches", "capability.switch", title: "Which Switches?", multiple: true, required: false
|
||||
input "locks", "capability.lock", title: "Which Locks?", multiple: true, required: false
|
||||
}
|
||||
}
|
||||
|
||||
mappings {
|
||||
path("/switches") {
|
||||
action: [
|
||||
GET: "listSwitches",
|
||||
PUT: "updateSwitches"
|
||||
]
|
||||
}
|
||||
path("/switches/:id") {
|
||||
action: [
|
||||
GET: "showSwitch",
|
||||
PUT: "updateSwitch"
|
||||
]
|
||||
}
|
||||
path("/locks") {
|
||||
action: [
|
||||
GET: "listLocks",
|
||||
PUT: "updateLocks"
|
||||
]
|
||||
}
|
||||
path("/locks/:id") {
|
||||
action: [
|
||||
GET: "showLock",
|
||||
PUT: "updateLock"
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
def installed() {}
|
||||
|
||||
def updated() {}
|
||||
|
||||
def listSwitches() {
|
||||
switches.collect { device(it,"switch") }
|
||||
}
|
||||
void updateSwitches() {
|
||||
updateAll(switches)
|
||||
}
|
||||
def showSwitch() {
|
||||
show(switches, "switch")
|
||||
}
|
||||
void updateSwitch() {
|
||||
update(switches)
|
||||
}
|
||||
|
||||
def listLocks() {
|
||||
locks.collect { device(it, "lock") }
|
||||
}
|
||||
void updateLocks() {
|
||||
updateAll(locks)
|
||||
}
|
||||
def showLock() {
|
||||
show(locks, "lock")
|
||||
}
|
||||
void updateLock() {
|
||||
update(locks)
|
||||
}
|
||||
|
||||
private void updateAll(devices) {
|
||||
def command = request.JSON?.command
|
||||
if (command) {
|
||||
devices."$command"()
|
||||
}
|
||||
}
|
||||
|
||||
private void update(devices) {
|
||||
log.debug "update, request: ${request.JSON}, params: ${params}, devices: $devices.id"
|
||||
def command = request.JSON?.command
|
||||
if (command) {
|
||||
def device = devices.find { it.id == params.id }
|
||||
if (!device) {
|
||||
httpError(404, "Device not found")
|
||||
} else {
|
||||
device."$command"()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private show(devices, name) {
|
||||
def device = devices.find { it.id == params.id }
|
||||
if (!device) {
|
||||
httpError(404, "Device not found")
|
||||
}
|
||||
else {
|
||||
def s = device.currentState(name)
|
||||
[id: device.id, label: device.displayName, name: device.displayName, state: s]
|
||||
}
|
||||
}
|
||||
|
||||
private device(it, name) {
|
||||
if (it) {
|
||||
def s = it.currentState(name)
|
||||
[id: it.id, label: it.displayName, name: it.displayName, state: s]
|
||||
}
|
||||
}
|
||||
@@ -1,143 +1,142 @@
|
||||
/**
|
||||
* 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.
|
||||
*
|
||||
* Virtual Thermostat
|
||||
*
|
||||
* Author: SmartThings
|
||||
*/
|
||||
definition(
|
||||
name: "Virtual Thermostat",
|
||||
namespace: "smartthings",
|
||||
author: "SmartThings",
|
||||
description: "Control a space heater or window air conditioner in conjunction with any temperature sensor, like a SmartSense Multi.",
|
||||
category: "Green Living",
|
||||
iconUrl: "https://s3.amazonaws.com/smartapp-icons/Meta/temp_thermo-switch.png",
|
||||
iconX2Url: "https://s3.amazonaws.com/smartapp-icons/Meta/temp_thermo-switch@2x.png"
|
||||
)
|
||||
|
||||
preferences {
|
||||
section("Choose a temperature sensor... "){
|
||||
input "sensor", "capability.temperatureMeasurement", title: "Sensor"
|
||||
}
|
||||
section("Select the heater or air conditioner outlet(s)... "){
|
||||
input "outlets", "capability.switch", title: "Outlets", multiple: true
|
||||
}
|
||||
section("Set the desired temperature..."){
|
||||
input "setpoint", "decimal", title: "Set Temp"
|
||||
}
|
||||
section("When there's been movement from (optional, leave blank to not require motion)..."){
|
||||
input "motion", "capability.motionSensor", title: "Motion", required: false
|
||||
}
|
||||
section("Within this number of minutes..."){
|
||||
input "minutes", "number", title: "Minutes", required: false
|
||||
}
|
||||
section("But never go below (or above if A/C) this value with or without motion..."){
|
||||
input "emergencySetpoint", "decimal", title: "Emer Temp", required: false
|
||||
}
|
||||
section("Select 'heat' for a heater and 'cool' for an air conditioner..."){
|
||||
input "mode", "enum", title: "Heating or cooling?", options: ["heat","cool"]
|
||||
}
|
||||
}
|
||||
|
||||
def installed()
|
||||
{
|
||||
subscribe(sensor, "temperature", temperatureHandler)
|
||||
if (motion) {
|
||||
subscribe(motion, "motion", motionHandler)
|
||||
}
|
||||
}
|
||||
|
||||
def updated()
|
||||
{
|
||||
unsubscribe()
|
||||
subscribe(sensor, "temperature", temperatureHandler)
|
||||
if (motion) {
|
||||
subscribe(motion, "motion", motionHandler)
|
||||
}
|
||||
}
|
||||
|
||||
def temperatureHandler(evt)
|
||||
{
|
||||
def isActive = hasBeenRecentMotion()
|
||||
if (isActive || emergencySetpoint) {
|
||||
evaluate(evt.doubleValue, isActive ? setpoint : emergencySetpoint)
|
||||
}
|
||||
else {
|
||||
outlets.off()
|
||||
}
|
||||
}
|
||||
|
||||
def motionHandler(evt)
|
||||
{
|
||||
if (evt.value == "active") {
|
||||
def lastTemp = sensor.currentTemperature
|
||||
if (lastTemp != null) {
|
||||
evaluate(lastTemp, setpoint)
|
||||
}
|
||||
} else if (evt.value == "inactive") {
|
||||
def isActive = hasBeenRecentMotion()
|
||||
log.debug "INACTIVE($isActive)"
|
||||
if (isActive || emergencySetpoint) {
|
||||
def lastTemp = sensor.currentTemperature
|
||||
if (lastTemp != null) {
|
||||
evaluate(lastTemp, isActive ? setpoint : emergencySetpoint)
|
||||
}
|
||||
}
|
||||
else {
|
||||
outlets.off()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private evaluate(currentTemp, desiredTemp)
|
||||
{
|
||||
log.debug "EVALUATE($currentTemp, $desiredTemp)"
|
||||
def threshold = 1.0
|
||||
if (mode == "cool") {
|
||||
// air conditioner
|
||||
if (currentTemp - desiredTemp >= threshold) {
|
||||
outlets.on()
|
||||
}
|
||||
else if (desiredTemp - currentTemp >= threshold) {
|
||||
outlets.off()
|
||||
}
|
||||
}
|
||||
else {
|
||||
// heater
|
||||
if (desiredTemp - currentTemp >= threshold) {
|
||||
outlets.on()
|
||||
}
|
||||
else if (currentTemp - desiredTemp >= threshold) {
|
||||
outlets.off()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private hasBeenRecentMotion()
|
||||
{
|
||||
def isActive = false
|
||||
if (motion && minutes) {
|
||||
def deltaMinutes = minutes as Long
|
||||
if (deltaMinutes) {
|
||||
def motionEvents = motion.eventsSince(new Date(now() - (60000 * deltaMinutes)))
|
||||
log.trace "Found ${motionEvents?.size() ?: 0} events in the last $deltaMinutes minutes"
|
||||
if (motionEvents.find { it.value == "active" }) {
|
||||
isActive = true
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
isActive = true
|
||||
}
|
||||
isActive
|
||||
}
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*
|
||||
* Virtual Thermostat
|
||||
*
|
||||
* Author: SmartThings
|
||||
*/
|
||||
definition(
|
||||
name: "Virtual Thermostat",
|
||||
namespace: "smartthings",
|
||||
author: "SmartThings",
|
||||
description: "Control a space heater or window air conditioner in conjunction with any temperature sensor, like a SmartSense Multi.",
|
||||
category: "Green Living",
|
||||
iconUrl: "https://s3.amazonaws.com/smartapp-icons/Meta/temp_thermo-switch.png",
|
||||
iconX2Url: "https://s3.amazonaws.com/smartapp-icons/Meta/temp_thermo-switch@2x.png"
|
||||
)
|
||||
|
||||
preferences {
|
||||
section("Choose a temperature sensor... "){
|
||||
input "sensor", "capability.temperatureMeasurement", title: "Sensor"
|
||||
}
|
||||
section("Select the heater or air conditioner outlet(s)... "){
|
||||
input "outlets", "capability.switch", title: "Outlets", multiple: true
|
||||
}
|
||||
section("Set the desired temperature..."){
|
||||
input "setpoint", "decimal", title: "Set Temp"
|
||||
}
|
||||
section("When there's been movement from (optional, leave blank to not require motion)..."){
|
||||
input "motion", "capability.motionSensor", title: "Motion", required: false
|
||||
}
|
||||
section("Within this number of minutes..."){
|
||||
input "minutes", "number", title: "Minutes", required: false
|
||||
}
|
||||
section("But never go below (or above if A/C) this value with or without motion..."){
|
||||
input "emergencySetpoint", "decimal", title: "Emer Temp", required: false
|
||||
}
|
||||
section("Select 'heat' for a heater and 'cool' for an air conditioner..."){
|
||||
input "mode", "enum", title: "Heating or cooling?", options: ["heat","cool"]
|
||||
}
|
||||
}
|
||||
|
||||
def installed()
|
||||
{
|
||||
subscribe(sensor, "temperature", temperatureHandler)
|
||||
if (motion) {
|
||||
subscribe(motion, "motion", motionHandler)
|
||||
}
|
||||
}
|
||||
|
||||
def updated()
|
||||
{
|
||||
unsubscribe()
|
||||
subscribe(sensor, "temperature", temperatureHandler)
|
||||
if (motion) {
|
||||
subscribe(motion, "motion", motionHandler)
|
||||
}
|
||||
}
|
||||
|
||||
def temperatureHandler(evt)
|
||||
{
|
||||
def isActive = hasBeenRecentMotion()
|
||||
if (isActive || emergencySetpoint) {
|
||||
evaluate(evt.doubleValue, isActive ? setpoint : emergencySetpoint)
|
||||
}
|
||||
else {
|
||||
outlets.off()
|
||||
}
|
||||
}
|
||||
|
||||
def motionHandler(evt)
|
||||
{
|
||||
if (evt.value == "active") {
|
||||
def lastTemp = sensor.currentTemperature
|
||||
if (lastTemp != null) {
|
||||
evaluate(lastTemp, setpoint)
|
||||
}
|
||||
} else if (evt.value == "inactive") {
|
||||
def isActive = hasBeenRecentMotion()
|
||||
log.debug "INACTIVE($isActive)"
|
||||
if (isActive || emergencySetpoint) {
|
||||
def lastTemp = sensor.currentTemperature
|
||||
if (lastTemp != null) {
|
||||
evaluate(lastTemp, isActive ? setpoint : emergencySetpoint)
|
||||
}
|
||||
}
|
||||
else {
|
||||
outlets.off()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private evaluate(currentTemp, desiredTemp)
|
||||
{
|
||||
log.debug "EVALUATE($currentTemp, $desiredTemp)"
|
||||
def threshold = 1.0
|
||||
if (mode == "cool") {
|
||||
// air conditioner
|
||||
if (currentTemp - desiredTemp >= threshold) {
|
||||
outlets.on()
|
||||
}
|
||||
else if (desiredTemp - currentTemp >= threshold) {
|
||||
outlets.off()
|
||||
}
|
||||
}
|
||||
else {
|
||||
// heater
|
||||
if (desiredTemp - currentTemp >= threshold) {
|
||||
outlets.on()
|
||||
}
|
||||
else if (currentTemp - desiredTemp >= threshold) {
|
||||
outlets.off()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private hasBeenRecentMotion()
|
||||
{
|
||||
def isActive = false
|
||||
if (motion && minutes) {
|
||||
def deltaMinutes = minutes as Long
|
||||
if (deltaMinutes) {
|
||||
def motionEvents = motion.eventsSince(new Date(now() - (60000 * deltaMinutes)))
|
||||
log.trace "Found ${motionEvents?.size() ?: 0} events in the last $deltaMinutes minutes"
|
||||
if (motionEvents.find { it.value == "active" }) {
|
||||
isActive = true
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
isActive = true
|
||||
}
|
||||
isActive
|
||||
}
|
||||
Reference in New Issue
Block a user