# MemoryTag - valueChange does not trigger

**URL:** <https://forum.inductiveautomation.com/t/memorytag-valuechange-does-not-trigger/88503>\
**Category:** Ignition\
**Tags:** ignition81\
**Created:** [April 8, 2024, 9:52am UTC](https://forum.inductiveautomation.com/t/memorytag-valuechange-does-not-trigger/88503 "2024-04-08T09:52:10Z")\
**Posts on this page:** 16\
**Page:** 1

<div class="post-metadata">

**Author:** ![Miguel\_Cimildoro](https://avatars.discourse-cdn.com/v4/letter/m/53a042/32.png) [@Miguel\_Cimildoro](https://forum.inductiveautomation.com/u/Miguel_Cimildoro)\
**Post date:** [April 8, 2024, 9:52am UTC](https://forum.inductiveautomation.com/t/memorytag-valuechange-does-not-trigger/88503/1 "2024-04-08T09:52:10Z")

</div>

I have a counter that increments the tag "Counter" one by one, and a `valueChange` function associated to the same tag that performs a series of actions (although they do not come to the case, I will mention them anyway). The problem is that, while the counter increments, the `valueChange` script is not executed at any time.

```auto
def valueChanged(tag, tagPath, previousValue, currentValue, initialChange, missedEvents):
	limit_counter = system.tag.readBlocking("[BALEN]System/Button_Saved_States/PCS_Comms_Enable_Disable/Rack_level/rack_prueba/Max_Counter")[0].value
	print limit_counter
	if currentValue.value >= limit_counter:
		print "first condition"
	 	Old_controlValue = system.tag.readBlocking("[BALEN]System/Button_Saved_States/PCS_Comms_Enable_Disable/Rack_level/rack_prueba/Old_controlValue")[0].value
	 	New_controlValue = system.tag.readBlocking("[BALEN]System/Button_Saved_States/PCS_Comms_Enable_Disable/Rack_level/rack_prueba/New_controlValue")[0].value
	 	controlValue_path = str(system.tag.readBlocking("[BALEN]System/Button_Saved_States/PCS_Comms_Enable_Disable/Rack_level/rack_prueba/controlValue_path")[0].value)
		if Old_controlValue != New_controlValue:
			print "second condition"
			system.tag.writeBlocking(controlValue_path, Old_controlValue)   
			system.tag.writeBlocking("[BALEN]System/Button_Saved_States/PCS_Comms_Enable_Disable/Rack_level/rack_prueba/Counter_Start", False)
			system.tag.writeBlocking("[BALEN]System/Button_Saved_States/PCS_Comms_Enable_Disable/Rack_level/rack_prueba/Fail", True)
		
			if Old_controlValue == 2:
				print Old_controlValue
				system.tag.writeBlocking("[BALEN]System/TEST/TagTest_RTU/word/tag_test", 2)
			elif Old_controlValue == 1:
				print Old_controlValue 
				system.tag.writeBlocking("[BALEN]System/TEST/TagTest_RTU/word/tag_test", 1)

```

What am I doing wrong? or what is the correct way for the valueChange to be executed as the counter increments?

many regards.

---

<div class="post-metadata">

**Author:** ![bkarabinchak.psi](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bkarabinchak.psi/32/83567_2.png) [@bkarabinchak.psi](https://forum.inductiveautomation.com/u/bkarabinchak.psi)\
**Post date:** [April 8, 2024, 11:48am UTC](https://forum.inductiveautomation.com/t/memorytag-valuechange-does-not-trigger/88503/2 "2024-04-08T11:48:17Z")

</div>

Prints are never going to be viewable. Use [system.util.getLogger | Ignition User Manual](https://www.docs.inductiveautomation.com/docs/7.9/appendix/scripting-functions/system-util/system-util-getLogger) , log your statements. I would also log your limitcount and currentValue.value just to be sure you are getting what you expected. Check your gateway logs after trying it again to see what logs come through.

Not that you can't do this on a tag's valueChange event either but there is a lot of info on the forum why it is preferential to create a Gateway Tag Change vent and then monitor the appropriate tag(s), instead of making the valueChanged on the tag directly. Though I don't see this being your issue right now.

---

<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:** [April 8, 2024, 12:00pm UTC](https://forum.inductiveautomation.com/t/memorytag-valuechange-does-not-trigger/88503/3 "2024-04-08T12:00:45Z")

</div>

> [@bkarabinchak.psi](#):
>
> Prints are never going to be viewable.

They're viewable you just have to know where to look.

> [@Event Configuration Print Out to debug](https://forum.inductiveautomation.com/t/event-configuration-print-out-to-debug/60091/5):
>
> It's complicated slight_smile Starting from most local to least... In the script console, print will log directly to the output buffer on the right hand side. system.util.getLogger() will log to the named 'Output Console' Designer window. Bonus: A script invoked from here using system.util.invokeAsync will print to the regular output console, not the buffer on the right hand side. Anywhere else in the designer (except Perspective), print and system.util.getLogger will log to the 'Outpu…

> [@bkarabinchak.psi](#):
>
> instead of making the valueChanged on the tag directly

This point can not be overstated here. This script, particularly with the number of blocking calls, is inappropriate as a tag valueChanged event script.

All of that being said, I see nothing syntactically incorrect about this script, which leads me to what information leads you to believe the script isn't executing?

---

<div class="post-metadata">

**Author:** ![bkarabinchak.psi](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bkarabinchak.psi/32/83567_2.png) [@bkarabinchak.psi](https://forum.inductiveautomation.com/u/bkarabinchak.psi)\
**Post date:** [April 8, 2024, 12:07pm UTC](https://forum.inductiveautomation.com/t/memorytag-valuechange-does-not-trigger/88503/4 "2024-04-08T12:07:33Z")

</div>

Oh interesting, I still would say logger is best practice as you can label the logger and define priority levels. But good to know!

---

<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:** [April 8, 2024, 12:39pm UTC](https://forum.inductiveautomation.com/t/memorytag-valuechange-does-not-trigger/88503/5 "2024-04-08T12:39:00Z")

</div>

Also, read/writeBlocking functions expect **lists** of tags and values so they should be in `[]`.

---

<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:** [April 8, 2024, 12:44pm UTC](https://forum.inductiveautomation.com/t/memorytag-valuechange-does-not-trigger/88503/6 "2024-04-08T12:44:46Z")

</div>

Technically, `readBlocking()` is now documented as accepting either a single string or a list of strings.

Write blocking on the other hand, isn't documented, but I believe it will accept it.

---

<div class="post-metadata">

**Author:** ![Miguel\_Cimildoro](https://avatars.discourse-cdn.com/v4/letter/m/53a042/32.png) [@Miguel\_Cimildoro](https://forum.inductiveautomation.com/u/Miguel_Cimildoro)\
**Post date:** [April 8, 2024, 2:04pm UTC](https://forum.inductiveautomation.com/t/memorytag-valuechange-does-not-trigger/88503/7 "2024-04-08T14:04:22Z")

</div>

What I am trying to do is that after certain seconds, if the value of `controlValue` has not changed, then I assign the value of `oldValue`. However, this is not happening, so I am placing the `print` every time a condition is met to debug the code.

---

<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:** [April 8, 2024, 2:14pm UTC](https://forum.inductiveautomation.com/t/memorytag-valuechange-does-not-trigger/88503/8 "2024-04-08T14:14:31Z")

</div>

You are expecting a `valueChanged()` event when the value _ **hasn't** _ changed? Why would you think that would happen?

If you want to monitor for stale/old/unchanged values, you need a **separate** event, typically a **timer** event.

---

<div class="post-metadata">

**Author:** ![Miguel\_Cimildoro](https://avatars.discourse-cdn.com/v4/letter/m/53a042/32.png) [@Miguel\_Cimildoro](https://forum.inductiveautomation.com/u/Miguel_Cimildoro)\
**Post date:** [April 8, 2024, 2:21pm UTC](https://forum.inductiveautomation.com/t/memorytag-valuechange-does-not-trigger/88503/9 "2024-04-08T14:21:49Z")

</div>

hi Phil

If in this case I have a gateway timer event that is triggered when I click on the button, it is then when I activate the counter with a limit of 110 seconds. What I try to do is the following: if, after 110 seconds, the current value (currentValue.value) is greater or equal to the limit of the counter (limit\_counter) and the value of the control (controlValue) is different from the value of the indicator (indicatorValue), then I write the previous value (oldValue) in the tag that communicates with the RTU. Previously, I already get both the oldValue and the newValue in the button.

Is that what you mean by separating the events?

---

<div class="post-metadata">

**Author:** ![amarks](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/amarks/32/45610_2.png) [@amarks](https://forum.inductiveautomation.com/u/amarks)\
**Post date:** [April 8, 2024, 2:25pm UTC](https://forum.inductiveautomation.com/t/memorytag-valuechange-does-not-trigger/88503/10 "2024-04-08T14:25:25Z")

</div>

Not sure that this is something that should be handled with Ignition. Sounds like PLC work.

That said, seems like a project library script with `system.util.invokeLater()` to delay the execution would be what you want to use.

Also note that reads and writes _ **should** _ be combined. Just do all of your reads right away at the beginning.

```auto
def valueChanged(tag, tagPath, previousValue, currentValue, initialChange, missedEvents):
    limit_counter, Old_controlValue, New_controlValue, controlValue_path = [tag.value for tag in system.tag.readBlocking("[BALEN]System/Button_Saved_States/PCS_Comms_Enable_Disable/Rack_level/rack_prueba/Max_Counter","[BALEN]System/Button_Saved_States/PCS_Comms_Enable_Disable/Rack_level/rack_prueba/Old_controlValue","[BALEN]System/Button_Saved_States/PCS_Comms_Enable_Disable/Rack_level/rack_prueba/New_controlValue","[BALEN]System/Button_Saved_States/PCS_Comms_Enable_Disable/Rack_level/rack_prueba/controlValue_path")]
	print limit_counter
	if currentValue.value >= limit_counter:
        writePaths = []
        writeVals = []
		print "first condition"
		if Old_controlValue != New_controlValue:
			print "second condition"
            writePaths += [str(controlValue_path), "[BALEN]System/Button_Saved_States/PCS_Comms_Enable_Disable/Rack_level/rack_prueba/Counter_Start", "[BALEN]System/Button_Saved_States/PCS_Comms_Enable_Disable/Rack_level/rack_prueba/Fail"]
            writeVals += [Old_controlValue, False, True]
		
			if Old_controlValue == 2:
				print Old_controlValue
                writePaths += ["[BALEN]System/TEST/TagTest_RTU/word/tag_test"]
                writeVals += [2]
			elif Old_controlValue == 1:
				print Old_controlValue 
                writePaths += ["[BALEN]System/TEST/TagTest_RTU/word/tag_test"]
                writeVals += [1]
                
            system.tag.writeBlocking(writePaths,writeVals)

```

---

<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:** [April 8, 2024, 3:03pm UTC](https://forum.inductiveautomation.com/t/memorytag-valuechange-does-not-trigger/88503/11 "2024-04-08T15:03:59Z")

</div>

> [@Miguel\_Cimildoro](#):
>
> gateway timer event that is triggered when I click on the button

This makes no sense. Gateway timer events trigger themselves on a set pace. How are you trying to get a 110 second time?

---

<div class="post-metadata">

**Author:** ![Miguel\_Cimildoro](https://avatars.discourse-cdn.com/v4/letter/m/53a042/32.png) [@Miguel\_Cimildoro](https://forum.inductiveautomation.com/u/Miguel_Cimildoro)\
**Post date:** [April 8, 2024, 3:06pm UTC](https://forum.inductiveautomation.com/t/memorytag-valuechange-does-not-trigger/88503/12 "2024-04-08T15:06:32Z")

</div>

![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/b/1/b14bc308d02744a15a8a1f06ee24cf203fa2fa41.png)

the Counter tag increments by 1, when it is greater than the Max\_limit , then it will execute the valueChange logic

---

<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:** [April 8, 2024, 3:45pm UTC](https://forum.inductiveautomation.com/t/memorytag-valuechange-does-not-trigger/88503/13 "2024-04-08T15:45:18Z")

</div>

What is the _ **real** _ problem you are trying to solve? There is probably a much better way of doing it.

---

<div class="post-metadata">

**Author:** ![Miguel\_Cimildoro](https://avatars.discourse-cdn.com/v4/letter/m/53a042/32.png) [@Miguel\_Cimildoro](https://forum.inductiveautomation.com/u/Miguel_Cimildoro)\
**Post date:** [April 9, 2024, 7:52am UTC](https://forum.inductiveautomation.com/t/memorytag-valuechange-does-not-trigger/88503/14 "2024-04-09T07:52:40Z")

</div>

what I am looking for, is that if within 110 seconds, the required value (1 or 2) does not arrive, then we send again the value in which it was before, for example. 1 enable 2 disable, if I want to disable it and in the course of 110 seconds, I do not receive a response from the RTU/PLC then I return to the previous state which is the 1.

---

<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:** [April 9, 2024, 8:14am UTC](https://forum.inductiveautomation.com/t/memorytag-valuechange-does-not-trigger/88503/15 "2024-04-09T08:14:34Z")

</div>

I still don't understand what this control system is trying to do.

Instead of creating Max\_Counter,

- Create a memory tag of type DateTime. Call it `timeoutStart` or similar. Update this at the start of the timeout period.
- Create an expression tag `timeout` of type Boolean. Set the expression to  
`now() - {[timeoutStart]} > 110000`  
Use the tag change event to call a gateway script when this changes. The first line should check if it has turned false and return. Otherwise do what has to be done.

---

<div class="post-metadata">

**Author:** ![Miguel\_Cimildoro](https://avatars.discourse-cdn.com/v4/letter/m/53a042/32.png) [@Miguel\_Cimildoro](https://forum.inductiveautomation.com/u/Miguel_Cimildoro)\
**Post date:** [April 9, 2024, 1:00pm UTC](https://forum.inductiveautomation.com/t/memorytag-valuechange-does-not-trigger/88503/16 "2024-04-09T13:00:37Z")

</div>

I have realized that I was sending a string to an integrer tag and that is why the change was not being made....

I still thank everyone for their comments and suggestions that I have learned in this post.

many regards
