High Temperature Notify


(Mc Q22) #1

Has anyone created or know of an app that will utilize my multi-sense sensors which I have installed inside a network closet to trigger a push and text notification when the temperature rises above a certain level? I’m looking for one that can do both push and SMS notification with the option to just have either or selected. Please let me know. Thanks!


(Zach Naimon) #2

Hey,

I wrote a SmartApp that notifies (Push or SMS) if temperature falls below or rises above certain temperatures.

/**
 *  Temperature Warning
 *
 *  Author: Zach Naimon
 *	zach@smartthings.com
 *  Date: 2013-06-13
 */

preferences {
	 section("Temperature Sensors"){
		input "exSensor", "capability.temperatureMeasurement", title: "Choose Sensor"
   } 
    section("Temperature "){
		input "minTemp", "decimal", title: "Minimum Temperature"
        input "maxTemp", "decimal", title: "Maximum Temperature"
   }     
    section("Contacting You"){
   		input "phone1", "phone", title: "Phone Number (Optional.  Push Notification will be sent if left blank)", required: false
        input "freq", "decimal", title: "Frequency of notifications (In minutes.  Only one notification will be sent if left blank.)", required: false
       
   }

}

def installed() {
	subscribe(exSensor, "temperature", eTemperatureHandler) 
    
}
def updated() {
	unsubscribe()
	subscribe(exSensor, "temperature", eTemperatureHandler)
   
}
def sendNotifHi() {
        	def exTemp = exSensor.latestValue("temperature")
    		log.debug exTemp
    		def difTempHi = (exTemp - maxTemp)
    		log.debug difTempHi
            if (phone1) {
			sendSms(phone1, "The outside temperature is $exTemp degrees, $difTempHi degrees above optimal temperature range.")
     
    		}
        	else{
        	sendPush("The outside temperature is $exTemp degrees, $difTempHi degrees above optimal temperature range.")
        	}
    }
def sendNotifLo() {
            def exTemp = exSensor.latestValue("temperature")
    		log.debug exTemp
    		def difTempLo = (minTemp - exTemp)
    		log.debug difTempLo   
    if (phone1) {
        sendSms(phone1, "The outside temperature is $exTemp degrees, $difTempLo degrees below optimal temperature range.")
        	
    	}
        else{
        sendPush("The outside temperature is $exTemp degrees, $difTempLo degrees below optimal temperature range.")
        }
} 
    
def eTemperatureHandler(evt){    
	if(exTemp > maxTemp){
    	if(freq) {
        schedule("0 0/$freq * * * ?", sendNotifHi)
        }
        else{
        sendNotifHi()
        }
    }
    if(exTemp < minTemp){
    	if(freq) {
        schedule("0 0/$freq * * * ?", sendNotifLo)
        }
        else{
        sendNotifLo()
        }
    }   
}
    

Should be fairly straightforward to edit if you like.

Cheers!


(Mc Q22) #3

Hey Zach,

Thanks for this! This is a really helpful app. I also have another app that I am currently using for something else which also alerts to high temperature. However it only sends text as of now. I’ve pasted the code below and was wondering if you could help me add push notification capabilities to it?

/**
 *  It's Too Hot V2
 *
 *  Author: Garrett
 */
preferences {
	section("Monitor the temperature...") {
		input "temperatureSensor1", "capability.temperatureMeasurement"
	}
	section("When the temperature is above...") {
		input "temperature1", "number", title: "Temperature?"
	}
	section("Text me at...") {
		input "phone1", "phone", title: "Phone number?"
	}
}

def installed() {
	subscribe(temperatureSensor1, "temperature", temperatureHandler)
}

def updated() {
	unsubscribe()
	subscribe(temperatureSensor1, "temperature", temperatureHandler)
}

def temperatureHandler(evt) {
	log.trace "temperature: $evt.value, $evt"

	def tooHot = temperature1

	// TODO: Replace event checks with internal state (the most reliable way to know if an SMS has been sent recently or not).
	if (evt.doubleValue >= tooHot) {
		log.debug "Checking how long the temperature sensor has been reporting >= $tooHot"

		// Don't send a continuous stream of text messages
		def deltaMinutes = 10 // TODO: Ask for "retry interval" in prefs?
		def timeAgo = new Date(now() - (1000 * 60 * deltaMinutes).toLong())
		def recentEvents = temperatureSensor1.eventsSince(timeAgo)
		log.trace "Found ${recentEvents?.size() ?: 0} events in the last $deltaMinutes minutes"
		def alreadySentSms = recentEvents.count { it.doubleValue >= tooHot } > 1

		if (alreadySentSms) {
			log.debug "SMS already sent to $phone1 within the last $deltaMinutes minutes"
			// TODO: Send "Temperature back to normal" SMS
		} else {
			log.debug "Temperature rose above $tooHot:  sending SMS to $phone1"
			sendSms(phone1, "${temperatureSensor1.label} is too hot, reporting a temperature of ${evt.value}${evt.unit}")
		}
	}
}

(Zach Naimon) #4

I would just change

 else {
			log.debug "Temperature rose above $tooHot:  sending SMS to $phone1"
			sendSms(phone1, "${temperatureSensor1.label} is too hot, reporting a temperature of ${evt.value}${evt.unit}")
		}

into

else {
log.debug "Temperature rose above $tooHot:  sending SMS to $phone1"
if(phone1){		
sendSms(phone1, "${temperatureSensor1.label} is too hot, reporting a temperature of ${evt.value}${evt.unit}")
}
else{
sendPush("${temperatureSensor1.label} is too hot, reporting a temperature of ${evt.value}${evt.unit}")
}
}

And then just set change your preference line to

input "phone1", "phone", title: "Phone number?", required: false

So that if you don’t enter a phone number it’ll send you a push instead.


(Tom) #5

Awesome job Zach!

How could you modify this app to ask for a specify amount of minutes then set the thermostat to a specified temp? I can set the temp from code borrowed from Keep Me Cozy but I don’t know how add in the delay/time period. Is there an API call for this?

Keep up the good work at ST.

Thanks
Tom


(Aaronw) #6

So I’ve put this app into the IDE, but I get weird alerts like (The temperature is 64 degrees, -14 below the optimal temperature). This doesn’t make a lot of sense to me, but I have no idea where the debugs show up so I can troubleshoot it… How should I go ahead?


(Jeff DeWolfe) #7

I don’t think there is a need for that app anymore now that SmartThings has it built into the Dashboard.