Well, yes, FindAlarmByKey() is not searching through already terminated alarms, only current ones. And even if everything happens within one EPP rule, alarm termination happens first and server action happens after that.
So the solution for now is to store the ID somehow before alarm termination. We can use filtering script in the EPP rule:
a = FindAlarmByKey($event.lastAlarmKey);
$event.setNamedParameter("lastAlarmID", a.id);
return true;
return true; is needed since this is filtering script and EPP rule will be processed further only if this script returns true.
And in your script that is used by the %[script] macro:
return $event.getParameter("lastAlarmID");
We are adding a new parameter to the event. This parameter will be accessible in any EPP rule that goes below the one where it's being added.
Ah, and actually you don't need the %[script] thing any more - you can just use %<lastAlarmID> macro - this should return value of event's parameter.