Separate the steps. If an alarm needs to sound has no direct relation to time or door status. But also if the door was opened during the alarm.
So seperate it, pseudo code
if(time == alarmTime && time != lastCheckedTime){
alarmOn = true
}
if(alarmOn && doorBecomesOpen){
alarmOn = false
}
if(alarmOn){
soundAlarm(0
}
Also, when you start doing almost the same twice there is an easier way ![]()
AND link to the library please. There are tons of libraries and some even have the same name but work differently.