I can't seem to get the right combination of settings to create this simple functionality with a transaction group:
Monitor an OPC tag
When it transitions high, start an hour meter
Increment the hour meter value until the monitored OPC tag transitions to low
Write the incremented value to the DB as a new entry, only once, when the OPC tag transitions LOW
Any subsequent execution starts the hour meter count from zero again
Doesn't sound like a normal use of a transaction group. Consider recording timestamps and tag value whenever the tag value changes. Then your DB can tell you the duration with a lead() or lag() expression.
I would probably have an event on the tag for value changed and when it goes high it writes to another tag and records the datetime then when it goes back low it takes the difference in between now() and the datetime tag then writes it to the database.
Jordan, I have implemented this as you suggested, but it seems it always writes a zero to db. Somehow, mine is resetting the hour meter before it can write the value to the DB. But I do see that your implementation does not. What could I be missing? Only thing I see different is that my first OPC tag in the group is the trigger, and the retentive hour meter one is second. Could this affect it?
You can try swapping them, but it should be logging the latched value of the hour meter.
Try it with a memory tag. If it works as it should, and not with the OPC tag, then you may have a bouncing signal.
Otherwise you can use the method outlined by others (especially @pturmel). It would be easier to maintain, in any case, as you can see how much of a pain this can be.