# How to use value of a tag some seconds ago in an alarm?

**URL:** <https://forum.inductiveautomation.com/t/how-to-use-value-of-a-tag-some-seconds-ago-in-an-alarm/8570>\
**Category:** Ignition\
**Created:** [June 14, 2014, 12:27am UTC](https://forum.inductiveautomation.com/t/how-to-use-value-of-a-tag-some-seconds-ago-in-an-alarm/8570 "2014-06-14T00:27:47Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![shreyaslimaye](https://avatars.discourse-cdn.com/v4/letter/s/f19dbf/32.png) [@shreyaslimaye](https://forum.inductiveautomation.com/u/shreyaslimaye)\
**Post date:** [June 14, 2014, 12:27am UTC](https://forum.inductiveautomation.com/t/how-to-use-value-of-a-tag-some-seconds-ago-in-an-alarm/8570/1 "2014-06-14T00:27:47Z")

</div>

This is my problem:

1. I have tag A created. I want to check whether value of tag A is smaller or equal to the value of tag A ‘n’ seconds/samples ago.

2. I have tag B. I want to check whether tag B’s value is between 200 and 1000 for more than 30 seconds.

3. I plan to create a boolean tag C as an expression tag whose value will become 1 if both the above conditions become true.

4. If the tag C value becomes 1, I want to issue an alarm.

However, I am having problem creating the first condition with tag A. How can I write an expression for tag C that will check if current value of tag A is smaller or equal to the the value of tag A 5 seconds/data samples ago?

Thanks,

Shreyas

---

<div class="post-metadata">

**Author:** ![adamaustin](https://avatars.discourse-cdn.com/v4/letter/a/5f8ce5/32.png) [@adamaustin](https://forum.inductiveautomation.com/u/adamaustin)\
**Post date:** [June 16, 2014, 9:29pm UTC](https://forum.inductiveautomation.com/t/how-to-use-value-of-a-tag-some-seconds-ago-in-an-alarm/8570/2 "2014-06-16T21:29:40Z")

</div>

I think you’ll have to write some scripting to pull out this value using something like [system.tag.queryTagHistory](http://inductiveautomation.com/support/usermanuals/ignition/system_tag_querytaghistory.htm) and then use [runScript](http://inductiveautomation.com/support/usermanuals/ignition/gen_advanced_runscript.htm) to get its value.
