Doing math on dates in scripts?

It looks like the template extension allows for getting the time of the last state change (state.last_updated). However, it’s not clear how to do math on that value.

Specifically, I was hoping to do something like (pseudo code):

  opened = {{now}} - {{garage_dor.state.last_updated}}
  if opened > 30 minutes:
    notification.send "Garage door opened for " + opened + " minutes

in a script.

What is the a proper way to do math on dates in scripts?

– charles

I was looking at doing something like this myself. But instead of doing I set it up as a delay on the script itself. You can see my solution here: