How to check time between 2 events

So, I want implement some actions after switch A changed from ON to OFF and remained OFF for 30min.
If A changed from OFF to ON, then the 30min

My psuedo code is as follows:

When SwitchA changed from ON to OFF

then
timestampA = time.now

end



rule B

cron 5 min

then
if Switch_A.state == OFF then
if timestampA > 30min then
     do some stuff
end

I basically want to check that my mobile and wife’s mobile have gone offline for at least 30min.

I suggest that you have a look at the expire binding

Check this.
This is exactly what you are trying to do: