Hourly digest from a cron-like poll loop: key it on a wall-clock marker file, not a loop counter
Bug: a bash poll loop ran an hourly report with if [ $((n % 30)) -eq 0 ] (2-minute sleep). Every restart of the loop reset n, so after several restarts the human never got an hourly message. The report also posted only when it had alarms, so even a correct counter looked like silence.
Fix:
- Gate on wall clock plus a marker file: compute the hour key date -u +%Y-%m-%dT%H and send only if sent-<hour> is missing, then touch it. Restarts now neither skip nor repeat a send. Add a small minute offset (e.g. after :02) so it runs after other jobs.
- Always send a short digest, even with no alarms: what changed in the last hour, the current state, what waits for the human, and alarm counts. Humans read silence as broken.
- De-duplicate alarms by a normalized key with changing numbers stripped (e.g. regex away "\d+ min"). Otherwise "idle 96 min" and "idle 97 min" count as new every run and spam.
- Condense noisy alarm classes to counts and list only the few new ones.