How do I get the number of minutes since a date/time variable?


#1

The idea is this; I currently have Presence device arrival triggering “home” mode. I want to make it so that if we drive by the house (e.g. we “arrive” then we “leave”) WITHOUT activating the motion sensor, then the house goes back to “away” mode.

I’ve set a date/time variable called @lasthomemode that will capture the date/time that the location mode changes to home.

I’ll set up:
IF @bothaway changes to true
AND Location Mode is Home
AND Motion has been inactive since @lasthomemode
THEN set Location Mode to Away

How do I set up the “motion has been inactive since @lasthomemode” part of the piston?


#2

age([motionSensor:motion]) gives you the last activity time stamp in ms

addSeconds($now, -(age([motionSensor:motion]))/1000) = number of seconds since last activity


#3

That’s useful, but what I’m wondering is how do I set that expression up in this particular piston? I’m trying to say that:

IF MotionSensor has been inactive for atleast XYZ seconds…

the XYZ seconds isn’t the age of the motion sensor, it’s the number of seconds since the Location Mode changed to Home (that is, the number of seconds since “@lasthomemode” variable)


#4

Figured it out!

($now-@lasthomemode)/1000

I was overthinking… or maybe I was underthinking! :thinking: