Simple temperature retrieval from smartthing multi sensor?


(javaservlets) #1

Hi: I can’t figure out why the following temperatureHandler() is reachable in the simulator when I use the virtual sensor but isn’t called when I substitute in either of the smartThings moisture or multi sensors. I’ve tried variations, as well as the ‘too cold’ demo. (BTW, I can catch the Open/Closed states no problem with the multi sensor…)

Any suggestions are appreciated:

definition(
name: “kitchen temperature”,
namespace: “”,
author: “n/a”,
description: “n/a”,
category: “My Apps”,
iconUrl: “https://s3.amazonaws.com/smartapp-icons/Convenience/Cat-Convenience.png”,
iconX2Url: “https://s3.amazonaws.com/smartapp-icons/Convenience/Cat-Convenience@2x.png”,
iconX3Url: “https://s3.amazonaws.com/smartapp-icons/Convenience/Cat-Convenience@2x.png”)

preferences {
section(“Temp”) {
input “tempSensor”, “capability.temperatureMeasurement”
}
}

def installed() {
log.debug "Installed with settings: ${settings}"
initialize()
}

def updated() {
log.debug "Updated with settings: ${settings}"
unsubscribe()
initialize()
}

def initialize() {
subscribe(tempSensor, “temperature”, temperatureHandler)
}

def temperatureHandler(evt) {
log.debug(“handler finally reached”)
def currentState = tempSensor.currentState(“temperature”)
log.debug “temperature value as a string: ${currentState.value}”
}


(javaservlets) #2

[Update] I see that the physical devices broadcast temperatures about every 15 minutes, thus if anyone has suggestions on how to poll for that info instead of waiting for it to pushed…


(Patrick Stuart [@pstuart]) #3

It should report on full degree change and only poll every 15 for status.

So getting latest device value should always be the current temp without the need to poll.

Excessive polling will kill the battery and just flood the network.


(javaservlets) #4

Thanks for the response… Perhaps another way to ask my same question: when I use the virtual sensor the handler is reachable right away; but when I use the physical ones I have to wait for the next broadcast thus is there a way to get the current temperature without having to wait?


(Patrick Stuart [@pstuart]) #5
def x = [device].latestValue("temperature")

Where [device] is the subscribed device name.


(Barry) #6

FWIW, since you’ve subscribed to “temperature” changes, inside your handler you can merely reference evt.value which should be the temperature value being updated…


(Vlad Horătău) #7

I’m having the same problem, and i’ve trying to solve it for hours. Have you possible solve it? The virtual one is logging the value right away, but the physical ones won’t do anything… Please help me!
Thx a lot!