Accessing Motion Sensor Recent Activity

Hi all

Is it possible to access the history of motion sensors in smart apps? I’d like to be able to only trigger events in the room with the most recent activity. Ie, when an external door opens blink the lights in an occupied room only.

Any advise or thoughts greatly appreciated


Yes, totally possible.

You can get the events for a device using (sorted in reverse chronological order).

So you could find all the “active” events, then sort to find the most recent one.

Here’s a quick n dirty pass at it (not tested), and I bet there are some ninjas out there who could whip something more terse and efficient, because something seems off about this. I look forward to seeing other solutions…

def getMostRecentMotion() {
    	def activeEvents = []
	motions.each { motion ->
    	    activeEvents +={it.value == "active"})