Notified when refrigerator too warm?


(Chrislindinger) #1

I’d like to be notified if my refrigerator is too warm - anyone know how to do this? I’ve seen the SmartApps that notify when too cold… but not too warm.


(Av8rdude) #2

Chris,
I wanted the same app and just changed the too cold app to do exactly what you are asking. You need access to the developer web site. Luckily you can just click and have access:


From there you need to make a new app in “My SmartApps”. Then paste the code below into your new app. Save and then publish. When you Explore Smart Apps you will have a new category of “My Apps”…
Cheers,
Scott

/**

  • The Beer is Too Hot
  • Author: Scott Jones
    */
    preferences {
    section(“Monitor the temperature…”) {
    input “temperatureSensor1”, “capability.temperatureMeasurement”
    }
    section(“When the temperature rises 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 rises above $tooHot:  sending SMS to $phone1"
		sendSms(phone1, "${temperatureSensor1.label} is too hot, reporting a temperature of ${evt.value}${evt.unit}")
	}
}

}


(Cj) #3

Careful when pasting stuff that is listed like this, many times things like quote and dashes will be translated into Unicode. Best to paste into something like Notepad first and then into the IDE.


(Chrislindinger) #4

thanks for the code and the advice!


(Chrislindinger) #5

Does it take some time for the app to show up in “my apps”? I published it in MY APPS 5min ago and it isn’t there yet…

thanks for helping a newb


(Av8rdude) #6

Try force closing the app on your IOS device and relaunch it. Or logout on the app and then log back in. There are refresh issues with the mobile app.
Newbie, non-developer… Helping newbie :slight_smile:
Scott


(Chrislindinger) #7

I did that and no dice - I’ll give it some time… thanks!


(Chrislindinger) #8

Scott - there’s an error when trying to save this… any ideas?

https://dl.dropboxusercontent.com/u/1313504/Screen%20Shot%202013-06-06%20at%2012.54.05%20PM.png

startup failed:
script13705375984321604657023.groovy: 7: unexpected token: the @ line 7, column 18.
section(“Monitor the temperature…”) {
^

1 error


(Av8rdude) #9

Yeah it’s a formatting issue. Like mentioned earlier this is a bad place to cut and paste. If you want to do it yourself from scratch…just go make a new app and copy the it’s too cold example into your new app. Then edit the code in the places referencing temp<= and make it >=.
Look at the edits I did and you will figure it out. I’m not a coder just a hacker hardware guy :slight_smile:
Cheers,
Scott


(Chrislindinger) #10

Thanks - I pasted it in plain text… oh well… thanks…

Prob the best way to learn

Thanks Scott