mirror of
https://github.com/mtan93/SmartThingsPublic.git
synced 2026-03-23 05:10:50 +00:00
Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9bc02b30c8 |
@@ -10,45 +10,133 @@
|
|||||||
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License
|
* 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.
|
* for the specific language governing permissions and limitations under the License.
|
||||||
*
|
*
|
||||||
* Big Turn OFF
|
* Virtual Thermostat
|
||||||
*
|
*
|
||||||
* Author: SmartThings
|
* Author: SmartThings
|
||||||
*/
|
*/
|
||||||
definition(
|
definition(
|
||||||
name: "이상규",
|
name: "임희진",
|
||||||
namespace: "smartthings",
|
namespace: "smartthings",
|
||||||
author: "SmartThings",
|
author: "SmartThings",
|
||||||
description: "Turn your lights off when the SmartApp is tapped or activated",
|
description: "Control a space heater or window air conditioner in conjunction with any temperature sensor, like a SmartSense Multi.",
|
||||||
category: "Convenience",
|
category: "Green Living",
|
||||||
iconUrl: "https://s3.amazonaws.com/smartapp-icons/Meta/light_outlet.png",
|
iconUrl: "https://s3.amazonaws.com/smartapp-icons/Meta/temp_thermo-switch.png",
|
||||||
iconX2Url: "https://s3.amazonaws.com/smartapp-icons/Meta/light_outlet@2x.png"
|
iconX2Url: "https://s3.amazonaws.com/smartapp-icons/Meta/temp_thermo-switch@2x.png"
|
||||||
)
|
)
|
||||||
|
|
||||||
preferences {
|
preferences {
|
||||||
section("When I touch the app, turn off...") {
|
section("Choose a temperature sensor... "){
|
||||||
input "switches", "capability.switch", multiple: true
|
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()
|
def installed()
|
||||||
{
|
{
|
||||||
subscribe(location, changedLocationMode)
|
subscribe(sensor, "temperature", temperatureHandler)
|
||||||
subscribe(app, appTouch)
|
if (motion) {
|
||||||
|
subscribe(motion, "motion", motionHandler)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
def updated()
|
def updated()
|
||||||
{
|
{
|
||||||
unsubscribe()
|
unsubscribe()
|
||||||
subscribe(location, changedLocationMode)
|
subscribe(sensor, "temperature", temperatureHandler)
|
||||||
subscribe(app, appTouch)
|
if (motion) {
|
||||||
|
subscribe(motion, "motion", motionHandler)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
def changedLocationMode(evt) {
|
def temperatureHandler(evt)
|
||||||
log.debug "changedLocationMode: $evt"
|
{
|
||||||
switches?.off()
|
def isActive = hasBeenRecentMotion()
|
||||||
|
if (isActive || emergencySetpoint) {
|
||||||
|
evaluate(evt.doubleValue, isActive ? setpoint : emergencySetpoint)
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
outlets.off()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
def appTouch(evt) {
|
def motionHandler(evt)
|
||||||
log.debug "appTouch: $evt"
|
{
|
||||||
switches?.off()
|
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