I got it solved. I think the problem was my time alarms library was fubar. The same issue started happening even with my original program that was running rock solid for months, when I downloaded that program. Created a new sketch stripped down to just alarm.alarmRepeat functions and times set from variables. Even then the time alarms wouldnt call the functions. Removed and reinstalled the libraries for time, timealarms, and timelord. After that I got time alarms to call functions
#include <Wire.h>
#include <RTClib.h>
#include <Time.h>
#include <TimeAlarms.h>
#include <TimeLord.h>
RTC_DS1307 RTC;
// Door Open Time
int sHour = 07;
int sMinute = 0;
int sSecond = 0;
// Door Close Time
int eHour = 19;
int eMinute = 25;
int eSecond = 0;
//Pump Start Time
int lHour = 12;
int lMinute = 30;
int lSecond = 0;
//Pump End Time
int xHour = 17;
int xMinute = 0;
int xSecond = 0;
//Lights On time
int LightsOnHour = 18;
int LightsOnMin = 40;
int LightsOnSec = 0;
//Lights Off Time
int LightsOffHour = 23;
int LightsOffMin = 30;
int LightsOffSec = 0;
//Set Pins
const int doorRelay = 7; //DPDT K7 and K8 relays wireed together for double pole
const int pumpRelay = 8; //K6 sprayer pump on
const int lightRelay = 9; // K5 Light Relay
void setup() {
// put your setup code here, to run once:
// Set the relays to off immediately
digitalWrite(doorRelay, HIGH);
digitalWrite(pumpRelay, HIGH);
digitalWrite(lightRelay, HIGH);
//begin libraries
Serial.begin(57600);
RTC.begin();
// Set the pinmode
pinMode(pumpRelay, OUTPUT);
pinMode(doorRelay, OUTPUT);
pinMode(lightRelay, OUTPUT);
// Notify if the RTC isn't running
if (! RTC.isrunning()) {
Serial.println("RTC is NOT running");
}
// Get time from RTC
DateTime current = RTC.now();
DateTime compiled = DateTime(__DATE__, __TIME__);
if (current.unixtime() < compiled.unixtime()) {
Serial.println("RTC is older than compile time! Updating");
RTC.adjust(DateTime(__DATE__, __TIME__));
}
// Use RTC time to set the Door Open time
setTime(sHour, sMinute, sSecond, current.day(), current.month(), current.year());
time_t s = now();
// Use RTC time to set the Door Close time
setTime(eHour, eMinute, eSecond, current.day(), current.month(), current.year());
time_t e = now();
//Set lights on times
setTime(LightsOnHour, LightsOnMin, LightsOnSec, current.day(), current.month(), current.year());
time_t onLight = now();
//Set lights off time
setTime(LightsOffHour, LightsOffMin, LightsOffSec, current.day(), current.month(), current.year());
time_t offLight = now();
// Use RTC to set time now
setTime(current.hour(), current.minute(), current.second(), current.day(), current.month(), current.year());
time_t n = now();
//Test if various operations should occur to set the door and pump if reset occurs.
if (s <= n && n <= e) {
digitalWrite(doorRelay, LOW); // Openes the chicken door
}
else {
digitalWrite(doorRelay, HIGH);
}
if (onLight <= n && n <= offLight) {
digitalWrite(lightRelay, LOW); // Openes the chicken door
}
else {
digitalWrite(lightRelay, HIGH);
}
Alarm.alarmRepeat(sHour, sMinute, sSecond, doorOpen); //sTime opens door
Alarm.alarmRepeat(eHour, eMinute, eSecond, doorClose);//eTime closes door
Alarm.alarmRepeat(LightsOnHour, LightsOnMin, LightsOnSec, lightOn);
Alarm.alarmRepeat(LightsOffHour, LightsOffMin, LightsOffSec, lightOff);
After that was working I started calling the timelord calculate alarms function in the void setup, and have the CalculateAlarms() function set the shour, sminute, LightsOnHour, and LightsOnMin, in the setup BEFORE I run the set_time function.
coopTimeLord.TimeZone(TIMEZONE * 60);
coopTimeLord.Position(LATITUDE, LONGITUDE);
setTime(current.hour(), current.minute(), current.second(), current.day(), current.month(), current.year());
//Calculate alarm times
CalculateAlarms();
// Use RTC time to set the Door Open time
setTime(sHour, sMinute, sSecond, current.day(), current.month(), current.year());
time_t s = now();
// Use RTC time to set the Door Close time
setTime(eHour, eMinute, eSecond, current.day(), current.month(), current.year());
time_t e = now();
//Set lights on times
setTime(LightsOnHour, LightsOnMin, LightsOnSec, current.day(), current.month(), current.year());
time_t onLight = now();
//Set lights off time
setTime(LightsOffHour, LightsOffMin, LightsOffSec, current.day(), current.month(), current.year());
time_t offLight = now();
// Use RTC to set time now
setTime(current.hour(), current.minute(), current.second(), current.day(), current.month(), current.year());
time_t n = now();
The calculate alarms function is here, Now I just call void setup() with an alarm.alarmRepeat function at 1 am. This calls the calculate function and resets the set_time variables for repeating alarms. This way the chicken coop door and lights open and close times are reset each day.
void CalculateAlarms() {
int nowHour = hour(),
nowMinute = minute(),
nowDay = day(),
nowMonth = month(),
nowYear = year();
Serial.println();
Serial.print("nowHour: ");
Serial.println(nowHour);
Serial.print("nowMinute: ");
Serial.println(nowMinute);
Serial.print("nowDay: ");
Serial.println(nowDay);
Serial.print("nowMonth: ");
Serial.println(nowMonth);
Serial.print("nowYear: ");
Serial.println(nowYear);
byte timeLordSunRise[] = {0, 0, 0, nowDay, nowMonth, nowYear};
byte timeLordSunSet[] = {0, 0, 0, nowDay, nowMonth, nowYear};
coopTimeLord.SunRise(timeLordSunRise);
coopTimeLord.SunSet(timeLordSunSet);
Serial.print("sunrise: ");
Serial.print(timeLordSunRise[2]);
Serial.print(":");
Serial.println(timeLordSunRise[1]);
Serial.print("sunset: ");
Serial.print(timeLordSunSet[2]);
Serial.print(":");
Serial.println(timeLordSunSet[1]);
openDoorHr = timeLordSunRise[2];
openDoorMin = timeLordSunRise[1];
closeDoorHr = timeLordSunSet[2];
closeDoorMin = timeLordSunSet[1];
if(closeDoorMin + DOOR_SHUT_AFTER_SUNSET_MIN >= 60){
closeDoorHr += (closeDoorMin + DOOR_SHUT_AFTER_SUNSET_MIN) / 60;
closeDoorMin = (closeDoorMin + DOOR_SHUT_AFTER_SUNSET_MIN) % 60;
}else{
closeDoorMin += DOOR_SHUT_AFTER_SUNSET_MIN;
}
Serial.print("open door: ");
Serial.print(openDoorHr);
Serial.print(":");
Serial.println(openDoorMin);
Serial.print("close door: ");
Serial.print(closeDoorHr);
Serial.print(":");
Serial.println(closeDoorMin);
float naturalDaylightHr;
naturalDaylightHr = 12.0f-(timeLordSunRise[2] + timeLordSunRise[1]/60.0f);
naturalDaylightHr += (timeLordSunSet[2] + timeLordSunSet[1]/60.0f)-12.0f;
Serial.print("natural daylight (hrs): ");
Serial.println(naturalDaylightHr);
lightOnHr = timeLordSunSet[2];
lightOnMin = timeLordSunSet[1];
lightOffHr = timeLordSunSet[2];
lightOffMin = timeLordSunSet[1];
float lightNeededHrs = LIGHT_PER_DAY_HRS - naturalDaylightHr;
int lightNeededMins = lightNeededHrs * 60;
Serial.print("light needed (mins): ");
Serial.println(lightNeededMins);
lightOnHr -= LIGHT_ON_BEFORE_SUNSET_HRS;
if(lightOffMin + lightNeededMins >= 60){
lightOffHr += (lightOffMin + lightNeededMins) / 60;
lightOffMin = (lightOffMin + lightNeededMins) % 60;
}else{
lightOffMin += lightNeededMins;
}
Serial.print("light on: ");
Serial.print(lightOnHr);
Serial.print(":");
Serial.println(lightOnMin);
Serial.print("light off: ");
Serial.print(lightOffHr);
Serial.print(":");
Serial.println(lightOffMin);
LightsOnHour = lightOnHr;
LightsOnMin = lightOnMin;
LightsOnSec = 0;
LightsOffHour = lightOffHr;
LightsOffMin = lightOffMin;
LightsOffSec = 0;
//set times for testing
// LightsOnHour = 17;
// LightsOnMin = 53;
// LightsOnSec = 0;
//
// LightsOffHour = 17;
// LightsOffMin = 54;
// LightsOffSec = 0;
sHour = openDoorHr;
sMinute = openDoorMin;
sSecond = 0;
eHour = closeDoorHr;
eMinute = closeDoorMin;
eSecond = 0;