I find the Open & Watchguard notifications very useful, but I found that I needed a closed notification as well.
So I copied the code for the Open notification and modified it to return a Close notification.
In keeping with the existing format, I added a define to the Notifications section.....
//*******************************************************************
// Notifications
//*******************************************************************
// if defined, will fire a notification when any door/device stays open more than the specified number of minutes
#define NOTIFICATIONS_WATCHDOG_MINUTES 20
// if defined, will fire a notification every time and as soon as any door/device gets opened
#define NOTIFICATIONS_OPEN
// if defined, will fire a notification every time and as soon as any door/device gets closed
#define NOTIFICATIONS_CLOSED
...and added the modified Closed notification handler right after the Open notification handler...
if (!openDetected)
{
notificationSent = false;
delay(500);
}
}
#endif
//----------------------------------------------------------------------------------------------------
//----------------------------------------------------------------------------------------------------
#if defined(NOTIFICATIONS_CLOSED)
//----------------------------------------------------------------------------------------------------
void closedNotificationsHandler()
{
static boolean notificationSent = false;
boolean closeDetected = false;
for (int i = 0; i < sizeof(statusPins); ++i)
{
if (!isOpen(statusPins[i]))
{
#if defined(NOTIFICATIONS_SERIAL_DEBUGGING)
Serial.print(F("*** closed notification handler - detected a closed device/door @ pin #"));
Serial.print(statusPins[i]);
Serial.println(F(" ***"));
#endif
if (!notificationSent)
{
#if defined(NOTIFICATIONS_SERIAL_DEBUGGING)
Serial.println(F("*** closed notification handler - sending notification ***"));
#endif
char subject[] = "Closed Notification";
char body[] = "The garage door has just been closed.";
#if defined(PUSH_NOTIFICATIONS)
notifyViaPush(subject, body);
#endif
#if defined(SMS_NOTIFICATIONS)
notifyViaSms(subject, body);
#endif
#if defined(SMTP_NOTIFICATIONS)
notifyViaEmail(subject, body);
#endif
notificationSent = true;
}
else
{
#if defined(NOTIFICATIONS_SERIAL_DEBUGGING)
Serial.println(F("*** closed notification handler - NOT sending notification ***"));
#endif
}
closeDetected = true;
break;
}
}
// if all door/devices are open, reset notificationSent semaphore so that further notifications
// can be sent. This is done to avoid flooding recipient with notifications for a same event occurrence.
if (!closeDetected)
{
notificationSent = false;
delay(500);
}
}
#endif
//----------------------------------------------------------------------------------------------------
//----------------------------------------------------------------------------------------------------
void setup()
{
Note that I changed the char subject [] to "Closed Notification", and did the same for "Open Notification" & "Watchguard Notification" in the corresponding handlers. Makes it easier to read through notifications on Prowl app.
Finally, I added a call to the Closed Notification handler in the loop...
void loop()
{
char buffer[200];
int len = sizeof(buffer);
webserver.processConnection(buffer, &len);
#if defined(NOTIFICATIONS_WATCHDOG_MINUTES)
watchDogNotificationsHandler();
#endif
#if defined(NOTIFICATIONS_OPEN)
openNotificationsHandler();
#endif
#if defined(NOTIFICATIONS_CLOSED)
closedNotificationsHandler();
#endif
}