added event-trigger time delay parameter #18
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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!