# Alarm over time

**URL:** <https://forum.inductiveautomation.com/t/alarm-over-time/79396>\
**Category:** Ignition\
**Tags:** vision\
**Created:** [September 20, 2023, 1:42pm UTC](https://forum.inductiveautomation.com/t/alarm-over-time/79396 "2023-09-20T13:42:25Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Nathan\_Higgins1](https://avatars.discourse-cdn.com/v4/letter/n/8797f3/32.png) [@Nathan\_Higgins1](https://forum.inductiveautomation.com/u/Nathan_Higgins1)\
**Post date:** [September 20, 2023, 1:42pm UTC](https://forum.inductiveautomation.com/t/alarm-over-time/79396/1 "2023-09-20T13:42:25Z")

</div>

I need to trigger an alarm if a value changes by a set amount under a set time.. Any idea how to do that?

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [September 20, 2023, 1:52pm UTC](https://forum.inductiveautomation.com/t/alarm-over-time/79396/2 "2023-09-20T13:52:40Z")

</div>

To know the past of a tag you have to collect history (not necessarily with the tag historian, but that's easiest). Then you need to regularly query history of the time period of interest and look for the changes that matter. Probably compute a "rate of change" as a number. Then use a normal alarm definition on that computed value.

---

<div class="post-metadata">

**Author:** ![Nathan\_Higgins1](https://avatars.discourse-cdn.com/v4/letter/n/8797f3/32.png) [@Nathan\_Higgins1](https://forum.inductiveautomation.com/u/Nathan_Higgins1)\
**Post date:** [September 20, 2023, 2:43pm UTC](https://forum.inductiveautomation.com/t/alarm-over-time/79396/3 "2023-09-20T14:43:17Z")

</div>

Thanks for the quick response..I'm very new to Ignition programming. How would I write a history query?

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [September 20, 2023, 3:01pm UTC](https://forum.inductiveautomation.com/t/alarm-over-time/79396/4 "2023-09-20T15:01:51Z")

</div>

So, the simplest approach is to run a gateway timer event that asks the historian for the min & max values of that tag for the set time period. Start here: [system.tag.queryTagHistory()](https://docs.inductiveautomation.com/display/DOC81/system.tag.queryTagHistory)

(First, turn on and configure history for the source tag.)

You want aggregation mode = "MinMax", return size = 1. You'll get a dataset with two rows, one containing the minimum for the time period, and the other containing the maximum. Subtract to get the absolute value of the maximum change in the time period. Write that to the new memory tag.

(Last, configure the alarm on the memory tag.)

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [September 20, 2023, 3:16pm UTC](https://forum.inductiveautomation.com/t/alarm-over-time/79396/5 "2023-09-20T15:16:30Z")

</div>

You might be able to approximate the behavior you're looking for with the deadband and active delay settings on the alarm:  
[https://docs.inductiveautomation.com/display/DOC81/Tag+Alarm+Properties#TagAlarmProperties-ReferenceTable](https://docs.inductiveautomation.com/display/DOC81/Tag+Alarm+Properties#TagAlarmProperties-ReferenceTable)

---

<div class="post-metadata">

**Author:** ![Nathan\_Higgins1](https://avatars.discourse-cdn.com/v4/letter/n/8797f3/32.png) [@Nathan\_Higgins1](https://forum.inductiveautomation.com/u/Nathan_Higgins1)\
**Post date:** [September 20, 2023, 3:30pm UTC](https://forum.inductiveautomation.com/t/alarm-over-time/79396/6 "2023-09-20T15:30:12Z")

</div>

My problem is that the tag is always changing, so I can't define a setpoint for the alarm. They want an alarm on a big change in a short time.

---

<div class="post-metadata">

**Author:** ![Tim\_Carlton](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/tim_carlton/32/52835_2.png) [@Tim\_Carlton](https://forum.inductiveautomation.com/u/Tim_Carlton)\
**Post date:** [September 20, 2023, 3:47pm UTC](https://forum.inductiveautomation.com/t/alarm-over-time/79396/7 "2023-09-20T15:47:58Z")

</div>

This feels like a similar problem of "how do I the the total quantity (e.g., gallons released) from a rate tag (e.g., cfm)" and the answer is always "if it matters then you need to do the calculation in the PLC and have a second tag".

Once you have a RateOfChange tag then configuring the alarm is trivial an easy for anyone coming behind you to understand.

---

<div class="post-metadata">

**Author:** ![Nathan\_Higgins1](https://avatars.discourse-cdn.com/v4/letter/n/8797f3/32.png) [@Nathan\_Higgins1](https://forum.inductiveautomation.com/u/Nathan_Higgins1)\
**Post date:** [September 20, 2023, 4:17pm UTC](https://forum.inductiveautomation.com/t/alarm-over-time/79396/8 "2023-09-20T16:17:45Z")

</div>

I could do this in a PLC very easily, but unfortunately my application does not have a PLC

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [September 20, 2023, 9:27pm UTC](https://forum.inductiveautomation.com/t/alarm-over-time/79396/9 "2023-09-20T21:27:15Z")

</div>

I have to admit that I would use my Simulation Aids module's [recorder()](https://www.automation-pros.com/simaids/site/datasets.html#recorder) function to hang onto the necessary samples in memory.

Two expression tags. First of type dataset (~10 seconds at ½ second intervals):

```auto
recorder(500, 20, 'signal', {path/to/signal/tag})

```

Second of type double/float8:

```auto
max({path/to/recording}, 'signal') - min({path/to/recording}, 'signal')

```

Set an alarm on the second expression. Make them both event driven.

If you don't need the in-memory recording for other purposes, you could combine into a single expression tag (type double/float8) with my [transform()](https://www.automation-pros.com/simaids/site/utility.html#transform) function, like so:

```auto
transform(
	recorder(500, 20, 'signal', {path/to/signal/tag}),
	max(value(), 'signal') - min(value(), 'signal')
)

```
