# variable locks reading

**URL:** <https://forum.inductiveautomation.com/t/variable-locks-reading/77728>\
**Category:** Ignition\
**Tags:** ignition81\
**Created:** [August 11, 2023, 1:09am UTC](https://forum.inductiveautomation.com/t/variable-locks-reading/77728 "2023-08-11T01:09:11Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![Elton\_Azambuja](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/elton_azambuja/32/50965_2.png) [@Elton\_Azambuja](https://forum.inductiveautomation.com/u/Elton_Azambuja)\
**Post date:** [August 11, 2023, 1:09am UTC](https://forum.inductiveautomation.com/t/variable-locks-reading/77728/1 "2023-08-11T01:09:11Z")

</div>

I have a problem with a variable that I need to monitor, it simply stops reading, I want to create an event that triggers an email if it stops for more than 5 minutes, does anyone know how to generate this event?

---

<div class="post-metadata">

**Author:** ![ryan.white](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/ryan.white/32/73193_2.png) [@ryan.white](https://forum.inductiveautomation.com/u/ryan.white)\
**Post date:** [August 11, 2023, 1:15am UTC](https://forum.inductiveautomation.com/t/variable-locks-reading/77728/2 "2023-08-11T01:15:07Z")

</div>

How do you normally tell that the variable stops reading? Does the value stop changing? Does the value go to bad quality?

You could possibly set up a gateway timer event at 30s or 1 minute intervals to inspect the timestamp of the offending tag and if the last timestamp was \>5 minutes ago, send an email. You would also have to make sure to check if you sent an email already, so you don't spam emails every time the script fires after the tag stopped reading.

I can't remember if timestamps still update even if value did not change, I believe they do change on tag quality change.

---

<div class="post-metadata">

**Author:** ![Elton\_Azambuja](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/elton_azambuja/32/50965_2.png) [@Elton\_Azambuja](https://forum.inductiveautomation.com/u/Elton_Azambuja)\
**Post date:** [August 11, 2023, 2:21am UTC](https://forum.inductiveautomation.com/t/variable-locks-reading/77728/3 "2023-08-11T02:21:52Z")

</div>

in this case, I know that the problem is in the hardware, which generates the signal, in this case a temperature, the hardware locks the temperature value, therefore in the ignition, the tag maintains the status of a good signal, it does not go to a bad signal, where do I generate this event? do you have any example?

---

<div class="post-metadata">

**Author:** ![lrose](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/lrose/32/62724_2.png) [@lrose](https://forum.inductiveautomation.com/u/lrose)\
**Post date:** [August 11, 2023, 2:52am UTC](https://forum.inductiveautomation.com/t/variable-locks-reading/77728/4 "2023-08-11T02:52:28Z")

</div>

You would configure a Gateway Timer Event in the project under the Scripting Section.

[https://docs.inductiveautomation.com/display/DOC81/Gateway+Event+Scripts](https://docs.inductiveautomation.com/display/DOC81/Gateway+Event+Scripts)

---

<div class="post-metadata">

**Author:** ![Elton\_Azambuja](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/elton_azambuja/32/50965_2.png) [@Elton\_Azambuja](https://forum.inductiveautomation.com/u/Elton_Azambuja)\
**Post date:** [August 11, 2023, 3:43am UTC](https://forum.inductiveautomation.com/t/variable-locks-reading/77728/6 "2023-08-11T03:43:59Z")

</div>

in this case, the timestap value varies, as the ignition keeps reading and writing the variable, it happens that the value is locked, because the hardware freezes the generation of the value, due to some error, so it can't be by timestamp

---

<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:** [August 11, 2023, 12:34pm UTC](https://forum.inductiveautomation.com/t/variable-locks-reading/77728/7 "2023-08-11T12:34:01Z")

</div>

There's nothing built into Ignition that will do this. You can cobble something together with scripting as follows:

- Make a memory tag alongside the temperature tag to hold a `LastChange` datetime.
- Make a valueChange script on the temperature tag like so:

```auto
def valueChange(.....):
	if not initialChange and previousValue.value != currentValue.value:
		system.tag.writeBlocking(['[.]LastChange'], [system.date.now()])

```

- Make a boolean expression tag alongside these, named `StuckValue`:

```auto
dateDiff({[.]LastChange}, now(500), "minute") >= 5.0

```

- Display or alarm on `StuckValue`

---

<div class="post-metadata">

**Author:** ![Elton\_Azambuja](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/elton_azambuja/32/50965_2.png) [@Elton\_Azambuja](https://forum.inductiveautomation.com/u/Elton_Azambuja)\
**Post date:** [August 11, 2023, 5:01pm UTC](https://forum.inductiveautomation.com/t/variable-locks-reading/77728/8 "2023-08-11T17:01:51Z")

</div>

Perfect! thanks!!

---

<div class="post-metadata">

**Author:** ![Elton\_Azambuja](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/elton_azambuja/32/50965_2.png) [@Elton\_Azambuja](https://forum.inductiveautomation.com/u/Elton_Azambuja)\
**Post date:** [August 11, 2023, 8:13pm UTC](https://forum.inductiveautomation.com/t/variable-locks-reading/77728/9 "2023-08-11T20:13:41Z")

</div>

I created a time event to check the difference, it's not working, you can see what I did wrong???

```auto
if dateDiff("[default]Manutencao SMART/Utilidades/UPS/UPS1/LastChange", now(0), "minute") >= 5.0:
	system.tag.write("[default]Manutencao SMART/Utilidades/UPS/UPS1/StuckValue",True)
else:
	system.tag.write("[default]Manutencao SMART/Utilidades/UPS/UPS1/StuckValue",False)
	

```

---

<div class="post-metadata">

**Author:** ![Transistor](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/transistor/32/3380_2.png) [@Transistor](https://forum.inductiveautomation.com/u/Transistor)\
**Post date:** [August 11, 2023, 8:19pm UTC](https://forum.inductiveautomation.com/t/variable-locks-reading/77728/10 "2023-08-11T20:19:43Z")

</div>

`dateDiff` is an expression language function. You can't use it in Python.

For scripting you would need to use `system.date.minutesBetween()`.  
[https://docs.inductiveautomation.com/display/DOC81/system.date.\*Between](https://docs.inductiveautomation.com/display/DOC81/system.date.*Between)

Tip: "_it's not working_" is not an adequate description of the problem. Describe what you expect and what you got - especially any error messages.

---

<div class="post-metadata">

**Author:** ![lrose](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/lrose/32/62724_2.png) [@lrose](https://forum.inductiveautomation.com/u/lrose)\
**Post date:** [August 11, 2023, 8:21pm UTC](https://forum.inductiveautomation.com/t/variable-locks-reading/77728/11 "2023-08-11T20:21:21Z")

</div>

Couple of things.

- The expression language is not python and doesn't work in that way.
- What you have is not what @pturmel recommended.
- Just putting a tagPath in as a string does not get a value, you must explicitly read the values.
- The `system.tag.*` functions take a list of tag paths and return a list of Qualified values. Do a search on the forum about how to correctly do that.

Look up "Expression Tags" in the manual.
