Arduino MKR 1300 RTC subtracting 1 second every 8 hours

I used the RTC, from an Arduino MKR 1300 with integrated RTC, as an alarm that will trigger a “boolean”(it’s an integer) that will tell the loop to run a certain method every minute and then send some data every 5 minutes. It’s on an active loop but the method to send data ONLY WORKS if it’s inside the loop (no idea why). The problem is the RTC apparently is subtracting 1 second at every 8 hours or so after a few days the timing might come off and instead of sending data every xx:10:xx-xx:15:xx it might send data xx:09:xx-xx:14:xx.

Here’s the code:

#include <EmonLib.h>
#include <RTCZero.h>
#include <MKRWAN.h>


EnergyMonitor emon1;
EnergyMonitor emon2;
EnergyMonitor emon3;
RTCZero rtc;
LoRaModem modem;

String appEui = "1234567891011121";
String appKey = "ffffffffffffffffffffffffffffffff";

/* INITIAL_TIME */
const byte seconds = 0;
const byte minutes = 0;
const byte hours = 0;
const byte day = 17;
const byte month = 12;
const byte year = 18;


byte second_alarm = 0;
byte minute_alarm = 0;
byte hour_alarm = 0;
byte INTERVAL = 60;
int SEND_LOOP = 5;

int totalKW;
int counter= 0;
int alarm_Triggered = 0;

void setup()
{
  Serial.begin(115200);
  if (!modem.begin(EU868)) {
    Serial.println("Failed to start module");
    while (1) {}
  };
  Serial.print("Your module version is: ");
  Serial.println(modem.version());
  Serial.print("Your device EUI is: ");
  Serial.println(modem.deviceEUI());

  Serial.println("Connecting");
  int connected = modem.joinOTAA(appEui, appKey);
  if (!connected) {
    Serial.println("Something went wrong; are you indoor? Move near a window and retry");
    while (1) {}
  }
  Serial.println("Connected");

  // Set poll interval to 60 secs.
  modem.minPollInterval(60);

  analogReadResolution(9);
  emon1.current(1, 53);
  emon2.current(2, 53);
  emon3.current(3, 53);
  counter= 0;

  rtc.begin(); // initialize RTC

  rtc.setAlarmTime(hour_alarm, minute_alarm, second_alarm);
  rtc.enableAlarm(rtc.MATCH_HHMMSS);
  rtc.attachInterrupt(triggerAlarm);

  // Set the time
  rtc.setHours(hours);
  rtc.setMinutes(minutes);
  rtc.setSeconds(seconds);

  // Set the date
  rtc.setDay(day);
  rtc.setMonth(month);
  rtc.setYear(year);


}

void loop() {
  if (alarm_Triggered == 1) {
    dataMonitor();
    alarm_Triggered = 0;
  }
}

void dataMonitor() {

  int totalWatt = 0;
  unsigned long delay_send = 0;
  int sending = 0;

  double Irms1 = emon1.calcIrms(600);
  if (Irms1 < 0.3) Irms1 = 0;
  double Watt1 = Irms1 * 230;

  double Irms2 = emon2.calcIrms(600);
  if (Irms2 < 0.3) Irms2 = 0;
  double Watt2 = Irms2 * 230;

  double Irms3 = emon3.calcIrms(600);
  if (Irms3 < 0.3) Irms3 = 0;
  double Watt3 = Irms3 * 230;

  totalWatt = Watt1 + Watt2 + Watt3;
  totalKW = totalKW + totalWatt / 1000;
  Serial.println(counter);

  sendDataChecker(Irms1, Irms2, Irms3);
  setAlarm();
  counter= counter+ 1;

}

void sendDataChecker(double Irms1, double Irms2, double Irms3) {
  if (counter== SEND_LOOP) {
    double IrmsTotal = Irms1 + Irms2 + Irms3;
    String msg = "{\"id\":\"avac_aud2\",\"kW\":" + String(totalKW) + ", \"current\":" + String(IrmsTotal) + "}";
    int err;
    Serial.println("Ready to Send");
    modem.beginPacket();
    modem.print(msg);
    err = modem.endPacket(true);
    Serial.println("Sent1");
    if (err > 0) {
      //message sent correctly
      Serial.println("Sent");
      counter= 0;
      totalKW = 0;
    } else {
      Serial.println("ERR");
      counter= 0;
    }
  }
}


void setAlarm() {
  second_alarm += INTERVAL;
  if (second_alarm >= 60) {
    minute_alarm++;
    second_alarm = 0;
  }
  if (minute_alarm >= 60) {
    hour_alarm++;
    minute_alarm = 0;
  }
  if (hour_alarm >= 24) {
    hour_alarm = 0;
  }

  rtc.setAlarmTime(hour_alarm, minute_alarm, second_alarm);
}

void triggerAlarm() {
  alarm_Triggered = 1;
}

How much time are you using inside dataMonitor() [which also calls the send routine]? A second or two?
You might want to immediate set the alarm for next time and the begin processing...

void loop() {
  if (alarm_Triggered == 1) {
    alarm_Triggered = 0;
    setAlarm();        // prepare for next time
    dataMonitor();   // do what we need to do
  }
}