# Alert event based on comparison of times

**URL:** <https://forum.inductiveautomation.com/t/alert-event-based-on-comparison-of-times/629>\
**Category:** Archived Topics\
**Created:** [April 4, 2008, 10:25pm UTC](https://forum.inductiveautomation.com/t/alert-event-based-on-comparison-of-times/629 "2008-04-04T22:25:02Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![TimE](https://avatars.discourse-cdn.com/v4/letter/t/ee59a6/32.png) [@TimE](https://forum.inductiveautomation.com/u/TimE)\
**Post date:** [April 4, 2008, 10:25pm UTC](https://forum.inductiveautomation.com/t/alert-event-based-on-comparison-of-times/629/1 "2008-04-04T22:25:02Z")

</div>

I have a request to send an email to management any time the equipment is below a certain speed for more than 30 minutes.

A = equipment A RPM  
B = equipment B RPM

If (A is less than 20) and (B is less than 20) for more than 30 minutes then send email

These are the action items setup so far  
ExtA\_On Expression, If({ExtA\_RPM}\>20,1,0)  
ExtB\_On Expression, If({ExtB\_RPM}\>20,1,0)  
LineDown Expression, If(!{ExtA\_ON}&!{ExtB\_ON},1,0) Alert is configured to send an email

How do I handle the time of the initial event and the comparison?

---

<div class="post-metadata">

**Author:** ![Carl.Gould](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/carl.gould/32/7262_2.png) [@Carl.Gould](https://forum.inductiveautomation.com/u/Carl.Gould)\
**Post date:** [April 4, 2008, 11:31pm UTC](https://forum.inductiveautomation.com/t/alert-event-based-on-comparison-of-times/629/2 "2008-04-04T23:31:57Z")

</div>

FactorySQL alerting doesn’t have a “only send the notification if the alert has been active for more than…” ability.

You could try something like this:  
If you can move the logic of the LineDown expression into a PLC tag, you can use an hour meter item and an action item to alert on when the hour meter item is \> 30 minutes.

It might be even easier to move all of the logic into a PLC timer, and just alert off of that.

Hope this helps,

---

<div class="post-metadata">

**Author:** ![Robert.McKenzie](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/robert.mckenzie/32/4134_2.png) [@Robert.McKenzie](https://forum.inductiveautomation.com/u/Robert.McKenzie)\
**Post date:** [April 7, 2008, 3:27pm UTC](https://forum.inductiveautomation.com/t/alert-event-based-on-comparison-of-times/629/3 "2008-04-07T15:27:52Z")

</div>

TimE,

You could use action items, but it would become more convoluted. You would need a few:

1. get the stored variable
2. get the current time
3. see if the current time is \> 20 minutes since the stored variable (this is the group trigger)
4. if the trigger was 0 (the group didn’t run), set the stored variable to now

Because the GetVariable function is first, you are getting the one from the last time the group ran. example: (make sure you put these groups in this order)[code]1)name: last\_time  
GetVariable(“time”,0)

1. name: current\_time  
SELECT DATE\_FORMAT(NOW(), “%H%i”)

2. name: trigger  
if({last\_time}+20\<{current\_time},1,0)

3. name: store\_time  
if({trigger},0,StoreVariable(“time”, {current\_time}))[/code]

I have to warn you though, this way is more prone to errors. You are better off doing what Carl suggested, but if you are set on doing it in FactorySQL, this is how you would.
