Haiku On Arm/Disarm - Email Notification with User Information.

dgriffith

Member
I would like to be able to send emails on Disarm and Arm that show which user armed the system. (Similar to Push Notification) Does anyone have sample code to get that user information?

The following works well to send a notification on Disarm but I don't know how to access the user that performed the action.

I'd like to do the same for Arming which should be easy once I know how to access the user information.

Code:
function onAreaDisarm(area) {
	    helper.sendMail(controller, '[email protected]', 'System Disarmed ', 'Alarm Disarmed for Controller: ' + controller.name);
}

Thanks!
 
This is a little bit tricky because the info is not sent by the controller. You will have to load the last few Events and locate the relevant event and then you will have the info needed.
 
Here's something I wrote up quick to do this, seems to work great:

Code:
function onAreaArm(area) {
    controller.refreshEvents(1);
    controller.addQueueCheckpoint("sendLastEvent");
}

function onAreaDisarm(area) {
    controller.refreshEvents(1);
    controller.addQueueCheckpoint("sendLastEvent");
}

function onQueueCheckpointReach(checkpoint) {
    if(checkpoint == "sendLastEvent") {
        var lastEvent = controller.events[0];

        helper.sendNotification(controller, lastEvent.eventDescription);
    }
}

Note this assumes that no other items get logged right after the disarm/arm, so that depends on your controller's programming logic. If there are other items being logged, you might need to load more than 1 event and loop through them to find the relevant one.

Of course you can replace sendNotification with sendMail or whatever else you like.
 
Back
Top