Getting device events by name/attribute


#1

I have a 4-in-1 temperature/humidity/motion/illuminance sensor, and I want to get the past few temperature events in a smart app. When I do the following I get events for all attributes:

preferences {
	section("Oil heater control:") {
        input "tempSensor", "capability.temperatureMeasurement", required: true, title: "What temperature sensor?"
    }
}

def initialize() {
	subscribe(tempSensor, "temperature", temperatureHandler)
}

def temperatureHandler(evt) {	
    def temperatures = tempSensor.events(max: 4)
}

Is there a way I can pass in the name of the event (temperature) into the tempSensor.events() call? Or do I have to manually track the history of the events (in a global variable or similar) I receive in the handler?


(www.rboyapps.com - Make your home your butler!) #2

tempSensor is a multi sensor device so it will have all the events reported by the DTH when you read it back. However you should be able to filter the events by name temperature


#3

Thanks for the help. I got it working by reading the temperature directly from the temperatureHandler event, and storing the previous value in the state collection. That should be quicker than querying for all past values too.