Enable/Disable tag history according to another tag value

Hello,
I would like to configure tag to record history on condition only. Let's say I have a Motor and I need to record PLC PID Out value on change but only when the Run Feedback is "true". I noticed I can bind the "History Enabled" property, but I couldn't reference the Run FB tag from the UDT. I thought I may bind it to the OPC path of the Run FB. I need to make sure that won't badly affect the historian, because the tag will be created and retired many times.

Bindings for tag properties and UDT parameters are intended to support configuration, not runtime, and do not support references to runtime tag values. Sorry. You can write to the history enabled property from a script during runtime, though.

Thanks @pturmel. So you think the best approach is to write to the history enabled property from a value changed script in the Run FB? Wouldn't that affect the historian?

Of course. That's what you want, right?

No I mean -as I understand- that will create and retire the PID Out tag from the historian each time the Run FB change (true, false) because I enable and disable the PID Out tag history property. Wouldn't that load or bug the historian?

No, historian tag entries remain in the sqlth_te table forever. (It can be a problem sometimes when you wish you hadn't originally put the tag in that history provider but now you've moved it and it still appears as an option on things like Perspective's Power Chart tag browser.)

Enabling and disabling will only affect whether or not it records data in the sql_dtat_X_X history tables.

https://docs.inductiveautomation.com/display/DOC81/Ignition+Database+Table+Reference

Going by that documentation I would expect to see the "retired" show the time the tag's history was disabled or Null if re-enabled.

If you're going to be modifying it this much, then you should just write the history to the historian manually in a Gateway Tag Change script using system.tag.storeTagHistory(). Then you can use the other tag as a filter to store or not store changes as needed.

1 Like

Another alternative is to make a third tag that references the Run Feedback and PID Out tags like below.
The idea is to enable history on this third tag only. The values will equal PID Out when the Feedback tag is high and None (or alternatively 0) when low.