Counting the number of times a specific alarm triggered and consolidating the notification

Good day to you wonderful people,

I’m trying to figure out the best way to handle a specific case of alarm notification.
Here’s what I have:
Lots of devices, let’s call them A1, A2… Xn.
Each of those has an alarm indicating that it tried to do something and failed. They are configured to keep trying for a while, each failed attempt triggers the alarm.
Now, it sometimes happen A LOT: I got back to work this week and had 6244 notification emails, most of those already being a consolidation on a 5 minutes delay.
Now here’s what I need to do:
Delay and consolidate this alarm so it doesn’t overflow my mailbox with notifications, but still keep a count of each specific alarm: I need to know how many times it triggered for A1, how many times it triggered for D27, etc.
I’m flexible with the overall behavior here, if anyone has a suggestion… I’ll take it.

I’m not very well versed in alarm notification pipelines, but I’ve been looking through the documentation and forums and could not find a proper solution - or any solution for that matter.
I’ve been trying things with a counter tag and scripts in the pipeline that lookup that tag and increment it, but I get stuck on things like resetting that counter when the alarm is finally sent for example.

Any help and/or suggestion is welcome and appreciated,

Thank you in advance and have a great day !