Temperature Subscription not triggering handler

For some reason, the method temperatureChangedHandler is never fired. I’ve tried with both the virtual temperatureMeasurement device and one of my SmartThings Multisensors. Does anyone see something wrong in this:

/**
 *  Thermostat Mode Changer
 *
 *  Copyright 2016 Jeremy Beckham
 *
 *  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: "Thermostat Mode Changer",
    namespace: "jbeckh2",
    author: "Jeremy Beckham",
    description: "Changes the mode of a thermostat when the temperature of a sensor gets too cold or too hot.",
    category: "Convenience",
    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("Change this Thermostat's:"){
    	input "thermostat", "capability.thermostat", required:true, title: "Thermostat?"
    }
    section("Mode to:"){
    	input "desiredmode", "enum", required:true, title:"Mode", options: ["heat", "cool", "off", "auto"]
    }
    section("When this temperature sensor:") {
		input "sensor", "capability.temperatureMeasurement", required: true, title: "Sensor?"
	}
    section("Is Less Than or Is Greater Than") {
    	input "lessorgreater", "enum", required:true, title:"Less Than/Greater Than", options: ["less", "greater"]
    }
    section("This Temperature") {
    	input "triggerTemp", "number", title:"Temperature"
    }
    
}

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

	initialize()
}

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

	unsubscribe()
	initialize()
}

def initialize() {
	// TODO: subscribe to attributes, devices, locations, etc.
    subscribe(sensor, "temperature", temperatureChangedHandler)
}    

// TODO: implement event handlers
def temperatureChangedHandler(evt) {
	log.debug "Temperature Changed Detected ${evt}"
    if (desiredmode != thermostat.thermostatMode) {
    	if (lessorgreater == "less") {
        	if (evt.doubleValue < triggerTemp) {
            	updateMode()
            }
        } else {
        	if (evt.doubleValue > triggerTemp) {
            	updateMode()
            }
        }
    }
}

def updateMode() {
	thermostat.setThermostatMode(desiredMode)
}
  1. Have you checked Live Logging? It will show both the DTH and the SmartApp output to make it easier to trace interactions.

  2. Regarding #1, it is helpful to make a copy of the DTH and add extra log.debug() commands if the existing DTH doesn’t have sufficient info.

  3. Also check the Event Log for the Device Instance.