TagHistory and History Enabled storing duplicate values

Hi,
I am reading the data from restAPI and storing the data with timestamp which is coming from API with storeTagHistory.
and when last data is recieved I write to the tag,
As I write to the tag the value gets stored in database with current time.

But the last value I had already saved using storeTagHistory and I am having a duplicate values with current time.

I am trying to restrict the last value getting saved after writing it to the tag.
As this tag have read and write option I cannot put large deadband and leave it.

Do you have sample code?

I don't recall anyone succeeding with an arrangement like this. You have two likely paths:

  • Always and only store with storeTagHistory().

  • When receiving data from the API, query past history and prune recent values already present before calling storeTagHistory().

I had tried couple of steps like.
before writing the last value to the tag I disabled the history of the tag and value is written to the tag then I enabled the history.
But somewhere the value is stored and as soon the history gets enabled value gets written to the database with current timestamp.