On turning on, set a time variable to $now. Set time variable to {$now}.
On turn off, set number variable = same variable - $now
You now have the number of milliseconds between the two
Set variable = variable / 60000
You now have the minutes. Good luck
Update: second Set Variable should be $now - {variable} to keep it positive