Very good work.

For user-friendly State Duration, I would add this line in scripts
$d = floor ($f_duration / 1440);
$h = floor (($f_duration – $d * 1440) / 60);
$m = round($f_duration – ($d * 1440) – ($h * 60));

and changed this line
#$body .= “State Duration:$f_duration mins.
“;

to something like this
$body .= “State Duration:$d days $h hours $m minutes
“;

anyway good job!