Guys, I’m trying to write a simple app that will turn off/ on multiple switches based on sensor output; specifically temp and humidity. I want this process to be automated, of course. However, I want to be sure hat the switches do not tun off unless both conditions are below their respective thresholds. I know nothing about writing code so I am following the, ‘How To’s’ like a paint-by-numbers and comparing my work to the work of others whose apps are similar. I know he syntax is correct because the app will save when I hit the button. I was hoping that someone could look it over to see what I may be missing or what might be useful based on their experience. Thanks!
/**
* Keep it Cool
*
* Copyright 2015 Michael Schinke
*
* 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: "Keep It Cool",
namespace: "Smartthings-Users",
author: "Michael Schinke",
description: "Turn devices on or off with input from temperature and humidity sensors",
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.png@2x.png")
preferences {
section("Choose which Temperature Sensor will trigger your switches") {
input "temperatureSensors", "capability.temperatureMeasurement",
title: "Temperature"
}
section("When the temperature rises above...") {
input "temperature", "number", title: "Temperature"
}
section("Choose which Humidity Sensor will trigger your switches") {
input "humiditySensors", "capability.relativeHumidityMeasurement",
title: "Humidity"
}
section("When the humidity rises above...") {
input "humidity", "number", title: "Humidity"
}
section("Choose which switch(es) to turn on") {
input "switches", "capability.switch", multiple: true
title: "Switches and Outlets"
}
}
def installed() {
subscribe (temperatureSensors, "temperature", temperatureHandler)
subscribe (relativeHumiditySensors, "humidity", humidityHandler)
subscribe (switches, "switch.on", switchOnHandler)
}
def updated() {
unsubscribe()
subscribe (temperatureSensors, "temperature", temperatureHandler)
subscribe (relativeHumiditySensors, "humidity", humidityHandler)
subscribe (switches, "switch.on", switchOnHandler)
}
private evaluate(currentTemperature, desiredTemperature, currentHumidity, desiredHumidity)
{
def threshold = 1.0
if (currentTemperature - desiredTemperature >= threshold) {
switches.on()
}
if (desiredTemperature - currentTemperature >= threshold){
switches.off()
}
else if (currentHumidity - desiredHumidity >= threshold) {
switches.on()
}
if (currentHumidity - desiredHumidity >= threshold) {
switches.on()
}
if (desiredHumidity - currentHumidity >= threshold) {
switches.off()
}
else if (currrentTemerpature - desiredTemperature >= threshold) {
switches.on()
}
}