Arduino cloud RTC time zones

Hi I am using the library rtczero in a Arduino 33 iot in order to handle several alarms. But I figure out that the rtc time on the cloud is UTC time. So in order to adjust my alarms I had to fit them adding hours to them.

My time zone is UTC -4

// RTCZero - Version: Latest 
#include <RTCZero.h>

/* Create an rtc object */

  RTCZero alarma700am;
  RTCZero alarma1158am;
  RTCZero alarma100pm;
  RTCZero alarma458pm;
  RTCZero alarma358pm;

int timbre = A1;

int retraso = 10000;
unsigned long ultima_toma=0;

/* 
  Sketch generated by the Arduino IoT Cloud Thing "Untitled"
  https://create.arduino.cc/cloud/things/caa7a627-b776-4d77-a789-c6e9935b5fd8 

  Arduino IoT Cloud Variables description

  The following variables are automatically generated and updated when changes are made to the Thing

  bool estado_alarma;
  bool sonar;

  Variables which are marked as READ/WRITE in the Cloud Thing will also have functions
  which are called when their values are changed from the Dashboard.
  These functions are generated with the Thing and added at the end of this sketch.
*/

#include "thingProperties.h"

void setup() {
  // Initialize serial and wait for port to open:
  Serial.begin(9600);
  // This delay gives the chance to wait for a Serial Monitor without blocking if none is found
  delay(1500); 

  // Defined in thingProperties.h
  initProperties();

  // Connect to Arduino IoT Cloud
  ArduinoCloud.begin(ArduinoIoTPreferredConnection);
  
  /*
     The following function allows you to obtain more information
     related to the state of network and IoT Cloud connection and errors
     the higher number the more granular information you’ll get.
     The default is 0 (only errors).
     Maximum is 4
 */
  setDebugMessageLevel(2);
  ArduinoCloud.printDebugInfo();
  //yoooooooooooooooooooooooooooooooooooooo
   alarma700am.begin(); // initialize RTC 24H format
   alarma1158am.begin();
   alarma100pm.begin();
   alarma458pm.begin();
   alarma358pm.begin();

   alarma700am.setAlarmTime(7 + 4, 0, 0);// this is the adjusted alarm
   alarma1158am.setAlarmTime(11 + 4, 58, 0);
   alarma100pm.setAlarmTime(13 + 4, 0, 0);
   alarma458pm.setAlarmTime(16 + 4, 58, 0);
   alarma358pm.setAlarmTime(15 + 4, 58, 0);

   alarma700am.enableAlarm(alarma700am.MATCH_HHMMSS);
   alarma1158am.enableAlarm(alarma1158am.MATCH_HHMMSS);
   alarma100pm.enableAlarm(alarma100pm.MATCH_HHMMSS);
   alarma458pm.enableAlarm(alarma458pm.MATCH_HHMMSS);
   alarma358pm.enableAlarm(alarma358pm.MATCH_HHMMSS);

   alarma700am.attachInterrupt(alarmMatch);
   alarma1158am.attachInterrupt(alarmMatch);
   alarma100pm.attachInterrupt(alarmMatch);
   alarma458pm.attachInterrupt(alarmMatch);
   alarma358pm.attachInterrupt(alarmMatch);
   
   

   //alarma358pm.setAlarmDay(5);//5 es viernes
   pinMode(A1,OUTPUT);
  //yoooooooooooooooooooooooooooooooooooooo
 
}

void loop() {
  ArduinoCloud.update();
  // Your code here 
  // Print date...
  estado_alarma = false;
  if (millis()- ultima_toma > retraso){
    Serial.println("Hora");
    Serial.println(alarma700am.getHours());
    Serial.println("Minutos");
    Serial.println(alarma700am.getMinutes());
    Serial.println("Segundos");
    Serial.println(alarma700am.getSeconds());
    Serial.println("anio");
    Serial.println(alarma700am.getYear());
    Serial.println("mes");
    Serial.println(alarma700am.getMonth());
    Serial.println("dia");
    Serial.println(alarma700am.getDay());
    
    
    ultima_toma = millis();
  }
  
  
}
void alarmMatch()
{
  estado_alarma = true;
  Serial.println("Alarm Match!");
  digitalWrite(timbre,HIGH);
  delay(2000);
  digitalWrite(timbre,LOW);
  delay(1000);
  digitalWrite(timbre,HIGH);
  delay(2000);
  digitalWrite(timbre,LOW);
  delay(1000);
  digitalWrite(timbre,HIGH);
  delay(2000);
  digitalWrite(timbre,LOW);
}



void onSonarChange() {
  // Do something
  if (sonar == true){
  Serial.println("alarma suena!!!!!!");
  alarmMatch();}
  sonar = false;
  
}

My question is, is there a way, method or semthing I can do to adjust my time zone on the rtc given by cloud?

Thank you.

P.D. I am new on this.

I have modified my code, previously I stared 5 rtc, now with one instance I manage the 5 alarms, there was other mistake in my previous code.

// RTCZero - Version: Latest 
#include <RTCZero.h>

/* Create an rtc object */

  RTCZero alarma;
  

int timbre = A1;

int retraso = 10000;
unsigned long ultima_toma=0;

/* 
  Sketch generated by the Arduino IoT Cloud Thing "Untitled"
  https://create.arduino.cc/cloud/things/caa7a627-b776-4d77-a789-c6e9935b5fd8 

  Arduino IoT Cloud Variables description

  The following variables are automatically generated and updated when changes are made to the Thing

  bool estado_alarma;
  bool sonar;
  int horaw;
  int minutosw;
  int segw;
  String prox_alarma;

  Variables which are marked as READ/WRITE in the Cloud Thing will also have functions
  which are called when their values are changed from the Dashboard.
  These functions are generated with the Thing and added at the end of this sketch.
*/

#include "thingProperties.h"

void setup() {
  // Initialize serial and wait for port to open:
  Serial.begin(9600);
  // This delay gives the chance to wait for a Serial Monitor without blocking if none is found
  delay(1500); 

  // Defined in thingProperties.h
  initProperties();

  // Connect to Arduino IoT Cloud
  ArduinoCloud.begin(ArduinoIoTPreferredConnection);
  
  /*
     The following function allows you to obtain more information
     related to the state of network and IoT Cloud connection and errors
     the higher number the more granular information you’ll get.
     The default is 0 (only errors).
     Maximum is 4
 */
  setDebugMessageLevel(2);
  ArduinoCloud.printDebugInfo();
  //yoooooooooooooooooooooooooooooooooooooo
   alarma.begin(); // initialize RTC 24H format
   
   setup_alarma();
   
   alarma.enableAlarm(alarma.MATCH_HHMMSS);

   alarma.attachInterrupt(alarmMatch);
   
   pinMode(timbre,OUTPUT);
  //yoooooooooooooooooooooooooooooooooooooo
}

void loop() {
  ArduinoCloud.update();
  // Your code here 
  // Print date...
  
  if (millis()- ultima_toma > retraso){
    Serial.println("Hora");
    horaw = alarma.getHours();
    Serial.println(horaw);
    Serial.println("minutos:");
    minutosw = alarma.getMinutes();
    Serial.println(minutosw);
    Serial.println("Segundos");
    segw = alarma.getSeconds();
    Serial.println(segw);
    //Serial.println("anio");
    //Serial.println(alarma.getYear());
    //Serial.println("mes");
    //Serial.println(alarma.getMonth());
    //Serial.println("dia");
    //Serial.println(alarma.getDay());
    
    
    ultima_toma = millis();
  }
  if (estado_alarma == true){
    
    funcion_sonar();
  }

}

void alarmMatch(){
  estado_alarma = true;
  Serial.println("Alarm Match!mmmmmmmmmmmmm");
   actualizar_alarma();//pone siguente alarma
  
}

void onSonarChange() {
  // Do something
  if (sonar == true){
  Serial.println("alarma suena!!!!!!");
  funcion_sonar();
  }
}

void funcion_sonar(){
  digitalWrite(timbre,HIGH);
  delay(2000);
  digitalWrite(timbre,LOW);
  delay(1000);
  digitalWrite(timbre,HIGH);
  delay(2000);
  digitalWrite(timbre,LOW);
  delay(1000);
  digitalWrite(timbre,HIGH);
  delay(2000);
  digitalWrite(timbre,LOW);
  estado_alarma = false;
 
}

void actualizar_alarma(){
  switch (alarma.getHours()){
    case 11: 
    //7+4
    alarma.setAlarmTime(11 + 4, 58, 0);//11:58 am
    prox_alarma = "11:58 AM";
    break;
    case 15:
    //11 + 4
    alarma.setAlarmTime(13 + 4, 0, 0);//1:00 PM
    prox_alarma = "1:00 PM";
    break;
    case 17:
    //13 + 4
    alarma.setAlarmTime(15 + 4, 58, 0);//3:58 PM
    prox_alarma = "3:58 PM";
    break;
    case 19:
    //15+4
    alarma.setAlarmTime(16 + 4, 58, 0);//4:58 PM
    prox_alarma = "4:58 PM";
    case 20:
    //16 + 4
    alarma.setAlarmTime(7 + 4, 0, 0);//7:00 AM
    prox_alarma = "7:00 AM";
    break;
}}

void setup_alarma(){
  int h = alarma.getHours();
  int m = h * 60; //minutos
  if (m < 660 || m >= 1258){
    alarma.setAlarmTime(7 + 4, 0, 0);//7:00 AM
    prox_alarma = "7:00 AM";
  }
  else if (m >= 660 && m <958){
    alarma.setAlarmTime(11 + 4, 58, 0);//11:58 am
    prox_alarma = "11:58 AM";
  }
  else if (m >= 958 && m < 1020){
    alarma.setAlarmTime(13 + 4, 58, 0);//1:00 PM
    prox_alarma = "1:00 PM";
  }
  else if (m >= 1020 && m < 1198){
    alarma.setAlarmTime(15 + 4, 58, 0);//3:58 PM
    prox_alarma = "3:58 AM";
  }
  else if (m >= 1198 && m < 1258){
    alarma.setAlarmTime(16 + 4, 58, 0);//4:58 PM
    prox_alarma = "4:58 AM";
  }
  else {
    Serial.print("ninguna alarma seteada");
  }
}
  

I still new to know the day of the week which is not given by RTCzero library. I do not know if cloud library has it.

The real idea of my project is making an industrial alarm for the workshop workers.

First I tried instance 5 RTC objects, I guess that would work but I change my mind and I figurate out an setup_alarm function which handles the different alarm times.

The hardware list is:
-Arduino MKR WIFI 1010 (because it has an real RTC cristal, I had an nano 33 iot and its RTC had 2 or more minutes diference with UTC real time. https://store.arduino.cc/usa/mkr-wifi-1010
-MKR conector carrier grove. https://store.arduino.cc/usa/arduino-mkr-connector-carrier
-5V, 3.3 V two solid state relay module. I had the grove relay and it fails and I replaced it with the solid state.

I use Arduino IoT cloud to supervise the alarm operation, next alarm scheduled, and even make sound the alarm from one cloud button.

I instead of erase every post I just add my ultimate code

Now my code is:

// NTPClient - Version: Latest 
#include <NTPClient.h>
#include <SPI.h>
#include <WiFiNINA.h>
WiFiUDP ntpUDP;
NTPClient timeClient(ntpUDP, "pool.ntp.org");

int dia_sem;

// RTCZero - Version: Latest 
#include <RTCZero.h>

/* Create an rtc object */

  RTCZero alarma;
  

int timbre = 4; //rele logica inversa 1 apaga 0 prende 

int retraso = 10000;
unsigned long ultima_toma=0;

/* 
  Sketch generated by the Arduino IoT Cloud Thing "Untitled"
  https://create.arduino.cc/cloud/things/556f0561-4e05-4ffd-8ce4-58ac9fbcd252 

  Arduino IoT Cloud Variables description

  The following variables are automatically generated and updated when changes are made to the Thing

  bool estado_alarma;
  bool sonar;
  int horaw;
  int minutosw;
  int segw;
  String prox_alarma;

  Variables which are marked as READ/WRITE in the Cloud Thing will also have functions
  which are called when their values are changed from the Dashboard.
  These functions are generated with the Thing and added at the end of this sketch.
*/

#include "thingProperties.h"

//yoooooooooooooooooooooooooooooooooooooooooooo

//yoooooooooooooooooooooooooooooooooooooooooooooooooo

void setup() {
  // Initialize serial and wait for port to open:
  Serial.begin(9600);
  // This delay gives the chance to wait for a Serial Monitor without blocking if none is found
  delay(1500); 

  // Defined in thingProperties.h
  initProperties();

  // Connect to Arduino IoT Cloud
  ArduinoCloud.begin(ArduinoIoTPreferredConnection);
  
  /*
     The following function allows you to obtain more information
     related to the state of network and IoT Cloud connection and errors
     the higher number the more granular information you’ll get.
     The default is 0 (only errors).
     Maximum is 4
 */
 
  ArduinoCloud.addCallback(ArduinoIoTCloudEvent::CONNECT, doThisOnConnect);
  setDebugMessageLevel(2);
  ArduinoCloud.printDebugInfo();
  //yoooooooooooooooooooooooooooooooooooooooooooooo
    alarma.begin(); // initialize RTC 24H format
   delay(5000);
   
   setup_alarma();
   
   pinMode(timbre,OUTPUT);
   digitalWrite(timbre,HIGH);
   
   // Initialize a NTPClient to get time
  timeClient.begin();
  // Set offset time in seconds to adjust for your timezone, for example:
  // GMT +1 = 3600
  // GMT +8 = 28800
  // GMT -1 = -3600
  // GMT 0 = 0
  timeClient.setTimeOffset(-14400);

  //yooooooooooooooooooooooooooooooooooooooooooooooooooo
}

void loop() {
  ArduinoCloud.update();
  // Your code here 
  //yoooooooooooooooooooooooooooooooooooo
  if (millis()- ultima_toma > retraso){
    Serial.println("Hora");
    horaw = alarma.getHours();
    Serial.println(horaw);
    Serial.println("minutos:");
    minutosw = alarma.getMinutes();
    Serial.println(minutosw);
    Serial.println("Segundos");
    segw = alarma.getSeconds();
    Serial.println(segw);
    //Serial.println("anio");
    //Serial.println(alarma.getYear());
    //Serial.println("mes");
    //Serial.println(alarma.getMonth());
    //Serial.println("dia");
    //Serial.println(alarma.getDay());
    timeClient.update();
    Serial.println("Week day (0 to 6) starting on Sunday");
    dia_sem = timeClient.getDay();
    Serial.println(dia_sem);
    
    ultima_toma = millis();
  }
  if (estado_alarma == true){
    
    if (int(alarma.getHours()) != 19){//que no sean las 3:58 = 15 + 4
      funcion_sonar();//suena 
    }
    else{// si acaso son las 3 = 15 + 4
      if (dia_sem == 5){
        // solo si es viernes que suene
        funcion_sonar();
      }
      else{
        // de resto otro dia de la semana que no suene a las 3:58 PM
      }
    }
  
    setup_alarma();//pone siguente alarma
     
    estado_alarma = false;
  }
//yoooooooooooooooooooooooooooooooooooooooooooooooooo
} 

void alarmMatch(){
  estado_alarma = true;
  Serial.println("Alarm Match!mmmmmmmmmmmmm");
}

void onSonarChange() {
  // Do something
  if (sonar == true){
  Serial.println("alarma suena!!!!!!");
  funcion_sonar();
  }
  setup_alarma();
}

void funcion_sonar(){
  digitalWrite(timbre,LOW);
  delay(2000);
  digitalWrite(timbre,HIGH);
  delay(1000);
  digitalWrite(timbre,LOW);
  delay(2000);
  digitalWrite(timbre,HIGH);
  delay(1000);
  digitalWrite(timbre,LOW);
  delay(2000);
  digitalWrite(timbre,HIGH);
}

void setup_alarma(){
  int h = alarma.getHours();
  int m = h * 60; //minutos
  if (m < 660 || m >= 1258){
    alarma.setAlarmTime(7 + 4, 0, 0);//7:00 AM
    prox_alarma = "7:00 AM";
  }
  else if (m >= 660 && m <958){
    alarma.setAlarmTime(11 + 4, 58, 0);//11:58 am
    prox_alarma = "11:58 AM";
  }
  else if (m >= 958 && m < 1020){
    alarma.setAlarmTime(13 + 4, 0, 0);//1:00 PM
    prox_alarma = "1:00 PM";
  }
  else if (m >= 1020 && m < 1198){
    alarma.setAlarmTime(15 + 4, 58, 0);//3:58 PM
    prox_alarma = "3:58 PM";
  }
  else if (m >= 1198 && m < 1258){
    alarma.setAlarmTime(16 + 4, 58, 0);//4:58 PM
    prox_alarma = "4:58 PM";
  }
  else {
    Serial.print("ninguna alarma seteada");
  }
  alarma.enableAlarm(alarma.MATCH_HHMMSS); 

  alarma.attachInterrupt(alarmMatch);
}
  
void doThisOnConnect(){
  /* add your custom code here */
  Serial.println("Board successfully connected to Arduino IoT Cloud otra vez");
}