Several of the same type of alarms can be used at the same time. This is because they are all assigned unique IDs. This experimental sketch makes use of the triggerOnce alarms to see that they can be used as intended in the final coding. They can and the sketch below is the same logic as will be used in the final Hot Water Cylinder controller.

The input to the triggerOnce is in a time_t type of variable. I suspect if it was not defined as time_t it would be treated as seconds from the time that the Arduino began running the code. This would make for some very long waits.

Related Project Pages

The extra libraries required for this sketch are:

You can also download the libraries from the following webpage: A Collection of Arduino Libraries Used in This Project.

The sketch below can be downloaded from here: AlarmSequencerv2.ino

/*
AlarmSequencerv2.ino
This sketch uses a couple of the same type of alarms using the
same logic as we intend to use in the Hot Water Cylinder
Controller.
The sketch will use two triggerOnce alarms to control an LED.
It is designed to initialise itself automatically with the 
first alarm event thirty seconds after being started.
*/

#include <Time.h>
#include <Wire.h>
#include <TimeAlarms.h>
#include <DS1307RTC.h>

boolean StatusFlag = true;  //This is the flag to enable or
// disable the HWC. If it is "true" then the HWC is enabled.
int LEDPin = 13;  //Dis isde pin the LED is on, this will
// simulate the signal to the HWC controller.
int  Interval = 25;  //Time between alarm pairs
int  Period = 5;  //Time within alarm pair
// The following global variables are given values temporarily until
// the RealTime Clock is initialised
time_t HWCdisableTime = 0;  //Next alarm to disable the HWC
time_t HWCenableTime = 0;  //Next alarm to enable the HWC

void setup()
{
  pinMode(13,OUTPUT);
//  Serial.begin(9600);
  setSyncProvider(RTC.get);   // the function to get the time from the RTC
  HWCdisableTime = now()+30;  // This initial alarm setting is set for thirty
  // seconds after the time now.
  HWCenableTime = HWCdisableTime + Period + random(2,8);  //This is
  //the other alarm's initial setting.
}

void loop()
{
  Alarm.triggerOnce(HWCdisableTime,HWCDisable);  //Set alarm to disable the HWC
  Alarm.triggerOnce(HWCenableTime,HWCenable);  //Set alarm to enable the HWC
  // The reason for using two alarms is so that the switching is
  // absolute rather than a toggle. This means that an override
  // button can be introduced in such a way that it will not
  // completely stuff up the operation.
  digitalWrite(LEDPin, StatusFlag);	// set the LED based on StatusFlag 
  Alarm.delay(1000);  //using a one second delay to control the alarms
}
 
 void HWCDisable()
 {
   StatusFlag = false;  //Disable the HWC
   HWCenableTime = HWCdisableTime + Period  + random(2,8);
   // This sets the new time to enable the HWC
 }
 
 void HWCenable()
 {
   StatusFlag = true;  //Enable the HWC
   HWCdisableTime = HWCenableTime + Interval + random(2,15);
   // This sets the new time to disable the HWC
 }