Stop History for a tag when tag data is invalid

Hello

In some condition the value comes form OPC which is not valid and should not to be logged, otherwise the report would be totally wrong. For example sensor wire open for AI card and AI card send overflow value to SCADA.
I try to use system.tag.editTag(tagPath=“Folder/Tag”,attributes={“HistoryEnabled”:True}) to stop history for the tag, but then I can’t reach even the valid history data which is recorded before in chart until I enable it again.
So I wander how I can temporary prevent Tag History from logging data. I want similar behavior like when the tag quality is BAD and there is no data in that duration. I try to overwrite the quality to BAD but it over written by system immediately.
what is the workaround for this kind of situation? How I can prevent logging invalid data?

1 Like

Try making an expression tag that uses the forceQuality() expression function to pass the value but substitute your own quality code. That substitution can look at some other signal to decide whether to make the result good or bad. Record the expression tag instead of the original tag.

Thanks
Which one has higher performance?

  1. Using your method with expression tag or
  2. Same idea but trigger in tag changed event

from com.inductiveautomation.ignition.common.model.values import BasicQualifiedValue
from com.inductiveautomation.ignition.common.sqltags.model.types import TagQuality
timestamp = system.date.now()
bqv = BasicQualifiedValue(2, TagQuality.BAD, timestamp)
system.tag.write('Kansar/FL1/val1', bqv)

Expression vs tag changed event script?

I have no idea. As a general maintainability policy, I avoid event scripts when a simple expression or binding will suffice.

2 Likes

Also Nader, you should be using preformatted text characters ` or ``` to quote your code rather than quote blocks

Edit: I did it again… I need to start looking at the post dates!

2 Likes