Momentary Button Write Tag on Turnoff

Hi there,
Is it possible to have a script that writes a value from another tag to a memory tag based on a momentary button changing state to off?

I have a momentary button that is set to remain on for 300 seconds. On initial click I am able to write a “Start Value” tag based on a mouse click script. However I also need to write an “End Value” when the 300 seconds is over.

I have memory tags set up for the place holders but am not fluent with scripting code. Is there a better way to do something like this?


Yes, there’s a better way. Use a normal button instead of a momentary button. In its actionPerformed event or action script, write the current date/time ( to a datetime tag that holds your “start” timestamp. Create a boolean expression tag with the following expression:

dateDiff({path/to/start/timestamp/tag}, now(0), "second") < 300

Your expression tag will be “on” for 300 seconds after the button is clicked.

Use the expression tag to style the button or show other indication that timing is in progress. If you don’t want the time extended by additional clicks, bind the enable of the button to the inversion of the tag.

FWIW, you generally cannot rely on momentary buttons’ off event even happening… Search this forum for “momentary” and look at the scary titles.

Thank you, I will take a look at this. Will this still work if I am trying to control a piece of equipment?

I am trying to automate a draw down test for specific capacity for a well. My flow sequence will be .

  1. User presses button (currently momentary 300 second timer to start Well Pump)
  2. Well level needs to be written to memory tag (Start Level)
  3. Flow rate needs to be written to memory tag (Flow Rate)
  4. Test continues for 300 seconds
  5. Momentary button transitions the Well Pump to an off state
    6.Well level needs to be written to memory tag (End Level)
  6. Specific Capacity expression tag (Flow rate/(Start Level - End Level))

Would a standard button still work in this case? I assumed the momentary would act as the On/Off switch for the well pump for operator control.

That would only be true if you didn’t have a 300 second minimum hold time. A momentary button is pretty much always the wrong choice. If there is any situation where you might need to abort, then you probably need to write PLC code for your sequence, not rely on a SCADA system.