Whole house fan smart app help please


(Brandon) #1

I need help figuring out how to alter the code of this app. It currently requires at least one window to be open to run but I would like to modify it so that it requires all selected windows to be open to run.

Here is the code below for the smart app…

/**

  • Whole House Fan
  • Copyright 2014 Brian Steere
  • 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: “Whole House Fan”,
namespace: “afewremarks”,
author: “Brian Steere & Mark West”,
description: “Toggle a whole house fan (switch) when: Outside is cooler than inside, Inside is above x temp, Thermostat is off”,
category: “Green Living”,
iconUrl: “https://s3.amazonaws.com/smartapp-icons/Developers/whole-house-fan.png”,
iconX2Url: “https://s3.amazonaws.com/smartapp-icons/Developers/whole-house-fan%402x.png
)

preferences {
section(“Outdoor”) {
input “outTemp”, “capability.temperatureMeasurement”, title: “Outdoor Thermometer”, required: true
}

section("Indoor") {
	input "inTemp", "capability.temperatureMeasurement", title: "Indoor Thermometer", required: true
    input "minTemp", "number", title: "Minimum Indoor Temperature"
    input "fans", "capability.switch", title: "Vent Fan", multiple: true, required: true
}

section("Windows/Doors") {
	paragraph "[Optional] Only turn on the fan if at least one of these is open"
    input "checkContacts", "enum", title: "Check windows/doors", options: ['Yes', 'No'], required: true 
	input "contacts", "capability.contactSensor", title: "Windows/Doors", multiple: true, required: false
}

section("Notifications") {
	input "sendPushMessage", "enum", title: "Send a push notification?", metadata: [values: ["Yes", "No"]], required: false
	input "phone", "phone", title: "Send a Text Message?", required: false

}
}

def installed() {
log.debug “Installed with settings: ${settings}”

initialize()

}

def updated() {
log.debug “Updated with settings: ${settings}”

unsubscribe()
initialize()

}

def initialize() {
state.fanRunning = false;

subscribe(outTemp, "temperature", "checkThings");
subscribe(inTemp, "temperature", "checkThings");
subscribe(contacts, "contact", "checkThings");

}

def checkThings(evt) {
def outsideTemp = settings.outTemp.currentTemperature
def insideTemp = settings.inTemp.currentTemperature
def somethingOpen = settings.checkContacts == ‘No’ || settings.contacts?.find { it.currentContact == ‘open’ }

log.debug "Inside: $insideTemp, Outside: $outsideTemp, Thermostat: $thermostatMode, Something Open: $somethingOpen"

def shouldRun = true;

if(insideTemp < outsideTemp) {
	log.debug "Not running due to insideTemp > outdoorTemp"
	shouldRun = false;
}

if(insideTemp < settings.minTemp) {
	log.debug "Not running due to insideTemp < minTemp"
	shouldRun = false;
}

if(!somethingOpen) {
	log.debug "Not running due to nothing open"
    shouldRun = false
}

if(shouldRun && !state.fanRunning) {
	fans.on();
    state.fanRunning = true;
    sendPush("Turn on the house fan now.")
} else if(!shouldRun && state.fanRunning) {
	fans.off();
    state.fanRunning = false;
    sendPush("Turn off the house fan now.")
}

}


#2

I’m new to this stuff so I’m sorry if I’m not much help. but if you are unable to get a solution via coding you may be able to accomplish the same thing by using CoRE.

you can find more info on this smartthings app here … CoRE


#3

Was doing some reading while trying to work on some code for myself and ran across this. I think you’ll be able to find your answer here…

Smartthings Device ref-doc

preferences {
      section() {
        // prompt user to select a device that supports the switch capability.
        // assign the chosen device to a variable named "theswitch"
        input "theswitch", "capability.switch"
    }
}
...
// access Device instance using the input name:
def deviceDisplayName = theswitch.displayName
...

If you have door and window contact sensors connected to your smartthings you can add a new “switch” input for each door/window you want to verify is open or closed in your house. You can then use “switch.getStatus()” to check if each switch is open or closed.

How getStatus() works:

Here’s an example of it in use with multiple switches to get the switch name and temperature when used with thermostat: (you may try to use switch.currentValue(“switch”) to see what it returns)

preferences {
    section() {
        input "theswitch", "capability.switch"
        input "thetemp", "capability.temperatureMeasurement"
    }
}
...
def switchattr = theswitch.currentValue("switch")
def tempattr = thetemp.currentValue("temperature")

log.debug "current switch: $switchattr"
log.debug "current temp: $tempattr"

// switch attribute returned as a string
log.debug "switchattr instanceof String? ${switchattr instanceof String}"

// temperature attribute returned as a Number
log.debug "tempatt instanceof Number? ${tempattr instanceof Number}"

...

Here’s another example from the same page: (Selecting multiple switches at one time and running a loop to check the status of each)

preferences {
    input "switches", "capability.switch", multiple: true
}

def installed() {
    switches.each {
        log.debug "switch id: ${it.id}, model name: ${it.getModelName()}"
    }
}

Hope this helps!
I’ll continue on my project now :smile: