# Button to increment a OPCUA tag

**URL:** <https://forum.inductiveautomation.com/t/button-to-increment-a-opcua-tag/65260>\
**Category:** Maker\
**Created:** [October 15, 2022, 9:34pm UTC](https://forum.inductiveautomation.com/t/button-to-increment-a-opcua-tag/65260 "2022-10-15T21:34:19Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![Vidar\_Hetlelid1](https://avatars.discourse-cdn.com/v4/letter/v/53a042/32.png) [@Vidar\_Hetlelid1](https://forum.inductiveautomation.com/u/Vidar_Hetlelid1)\
**Post date:** [October 15, 2022, 9:34pm UTC](https://forum.inductiveautomation.com/t/button-to-increment-a-opcua-tag/65260/1 "2022-10-15T21:34:19Z")

</div>

Hi, is it possible to get a push button to increment an OPCUA tag with 10 each time the button is pressed?

Thanks

---

<div class="post-metadata">

**Author:** ![craigb](https://avatars.discourse-cdn.com/v4/letter/c/9f8e36/32.png) [@craigb](https://forum.inductiveautomation.com/u/craigb)\
**Post date:** [October 15, 2022, 10:40pm UTC](https://forum.inductiveautomation.com/t/button-to-increment-a-opcua-tag/65260/2 "2022-10-15T22:40:43Z")

</div>

I dont have a live OPC tag to test on so set up a memory tag to test..

On action performed on the button, create a script..... assuming perspective use.

```auto
value = system.tag.readBlocking(["Testing Tags/Your Tag"])[0].value
system.tag.writeBlocking(["Testing Tags/Your Tag"],[value + 10])

```

Edited to say, you may need to specify the provider depending how your tags are set up..

```auto
system.tag.readBlocking(["[default]My/Tag/Path"])

```

[https://docs.inductiveautomation.com/display/DOC80/Reading+and+Writing+to+Tags](https://docs.inductiveautomation.com/display/DOC80/Reading+and+Writing+to+Tags)

---

<div class="post-metadata">

**Author:** ![Vidar\_Hetlelid](https://avatars.discourse-cdn.com/v4/letter/v/dfb087/32.png) [@Vidar\_Hetlelid](https://forum.inductiveautomation.com/u/Vidar_Hetlelid)\
**Post date:** [October 16, 2022, 12:03am UTC](https://forum.inductiveautomation.com/t/button-to-increment-a-opcua-tag/65260/3 "2022-10-16T00:03:54Z")

</div>

Thank you! This works. But it does take a few seconds to update though, is there any way to speed this up?

---

<div class="post-metadata">

**Author:** ![craigb](https://avatars.discourse-cdn.com/v4/letter/c/9f8e36/32.png) [@craigb](https://forum.inductiveautomation.com/u/craigb)\
**Post date:** [October 16, 2022, 12:08am UTC](https://forum.inductiveautomation.com/t/button-to-increment-a-opcua-tag/65260/4 "2022-10-16T00:08:52Z")

</div>

I'm not sure to be honest, On a memory tag its instant. One for the more qualified folks on here..

Since its a OPC tag, it may have something to do with the speed in which the tag updates, assuming the OPC tag is from a PLC or sensor or something ?

---

<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:** [October 16, 2022, 12:27pm UTC](https://forum.inductiveautomation.com/t/button-to-increment-a-opcua-tag/65260/5 "2022-10-16T12:27:21Z")

</div>

In general, values in OPC tags only come from the OPC subscription at the designated pace. Writes "pass through" to the device, and the tag's value is only updated when the next report comes from the OPC subscription.

---

<div class="post-metadata">

**Author:** ![jlandwerlen](https://avatars.discourse-cdn.com/v4/letter/j/bc8723/32.png) [@jlandwerlen](https://forum.inductiveautomation.com/u/jlandwerlen)\
**Post date:** [October 16, 2022, 2:54pm UTC](https://forum.inductiveautomation.com/t/button-to-increment-a-opcua-tag/65260/6 "2022-10-16T14:54:04Z")

</div>

A read/write directly to OPC is also an option,  
[https://docs.inductiveautomation.com/display/DOC81/system.opc.writeValue](https://docs.inductiveautomation.com/display/DOC81/system.opc.writeValue)

---

<div class="post-metadata">

**Author:** ![cmallonee](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/cmallonee/32/6416_2.png) [@cmallonee](https://forum.inductiveautomation.com/u/cmallonee)\
**Post date:** [October 16, 2022, 3:57pm UTC](https://forum.inductiveautomation.com/t/button-to-increment-a-opcua-tag/65260/7 "2022-10-16T15:57:45Z")

</div>

Would this be easier if you bidirectionally bound a custom property to the Tag value and just incremented the custom property by 10 as needed? I don't know how much of a factor the read/write calls are in the execution time, and it really sounds like you're more at the mercy of the subscription rate.

---

<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:** [October 16, 2022, 5:37pm UTC](https://forum.inductiveautomation.com/t/button-to-increment-a-opcua-tag/65260/8 "2022-10-16T17:37:38Z")

</div>

> [@cmallonee](#):
>
> bidirectionally bound a custom property to the Tag value and just incremented the custom property by 10 as needed?

That greatly simplifies the script but doesn't change the overall functionality significantly. If the write fails, the next subscription report after the write timeout will change the value back. You will also get the "write pending" overlay, which may or may not be helpful.

---

<div class="post-metadata">

**Author:** ![craigb](https://avatars.discourse-cdn.com/v4/letter/c/9f8e36/32.png) [@craigb](https://forum.inductiveautomation.com/u/craigb)\
**Post date:** [October 16, 2022, 6:14pm UTC](https://forum.inductiveautomation.com/t/button-to-increment-a-opcua-tag/65260/9 "2022-10-16T18:14:00Z")

</div>

Not sure if the attached video will work. I VPN'd into one of my machines so I could test on a live OPC tag. No matter which way you do it, the result is still the same.

[https://us1.discourse-cdn.com/inductiveautomation/original/3X/5/0/50302e8017b1880dbaf1e0adaaba0c47033973e1.mp4](https://us1.discourse-cdn.com/inductiveautomation/original/3X/5/0/50302e8017b1880dbaf1e0adaaba0c47033973e1.mp4)

Tag Write..

```auto
	value = system.tag.readBlocking(["[edge]New Tag"])[0].value
	system.tag.writeBlocking(["[edge]New Tag"],[value + 10])

```

OPC Write

```auto
	server = "PLC"
	path = "nsu=http://PU-2C-001;i=843"
	oldQualifiedValue = system.opc.readValue(server, path)
	newValue = oldQualifiedValue.getValue() + 10
	returnQuality = system.opc.writeValue(server, path, newValue)

```

Bi-Directional

```auto
    self.custom.Tag = self.custom.Tag + 10

```

---

<div class="post-metadata">

**Author:** ![nminchin](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/nminchin/32/6911_2.png) [@nminchin](https://forum.inductiveautomation.com/u/nminchin)\
**Post date:** [October 17, 2022, 12:46pm UTC](https://forum.inductiveautomation.com/t/button-to-increment-a-opcua-tag/65260/10 "2022-10-17T12:46:59Z")

</div>

What're the Tag Group settings that your tag is part of?  
You could turn on read after writing or optimistic writes to force it to immediately assume the write went through and use the write value.
