Page 1 of 1

Closed door notification

PostPosted: Wed Oct 16, 2013 3:31 am
by rpuas
After finally connecting & configuring a magnetic switch for my door, I was able to configure the push notifications.
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

}

Re: Closed door notification

PostPosted: Wed Oct 16, 2013 9:58 pm
by support
Thanks for sharing!

Re: Closed door notification

PostPosted: Sat Aug 23, 2014 10:21 pm
by dave
Thank you so much! I have been wanting to have this function for ages!!

Re: Closed door notification

PostPosted: Sun Nov 30, 2014 12:09 am
by V8mgb
I was just thinking of adding this feature and came across your post. A little careful cut and paste is all it took. Thanks, works great!

Re: Closed door notification

PostPosted: Sat Nov 21, 2015 8:59 am
by aurelutz2007
I got it also working, but not the way I wanted...
For the moment I have one gate and one garage, each with a magnetic sensor attached and I wanted to have the open/close notification independent working (get a message for gate open/close and for garage open/close).

Now is just fire an open notification when gate or garage was opened, but not for both on the same time.
And the close notification is sent only if both garage and gate were opened. If I only open the garage for example, I get open notification, but when closing it I'm getting no notification.

Can someone help me with that?