emoncms/event — pull request #18 by casestudies (2013-09-16 01:24:41+00:00)
Title: added event-trigger time delay parameter

I came across a need to delay an alert for a certain amount of time before actually sending the alert. I thought this might be a handy feature for others and that you may want to add it.

I'm monitoring a dehumidifier's power usage. When it turns off, I was trying to send an alert, indicating the unit was full (power goes down when it's not running of course). However, the unit sometimes cycles on and off depending on the humidity. It may turn off only for a minute and then turn back on for an hour. I came up with the idea to set a delay before the event message is actually sent. So it would only send a message after one hour of the condition being true. Each time the condition is indicated as false, it resets a timestamp that's used to calculate if the time delay period has elapsed.

I tested it with a frequently updating value (uptime) from an arduino node. It seems to work as expected, and seems to behave nicely when using a "Mutetime" parameter too.

The following is the solution I came up with. The downside might be that it updates a time value in the database each time the feed check is processed (seems to be every time a value is sent from the node that has an event entry attached to it), but I couldn't figure out how to get around this easily. If there's another solution that's more elegant, by all means, use that one! I tried to leave as much code alone as I could manage. If there's another way to make it cleaner, that's great!