Tag change oldvalue

Hello I have a problem with the tag change event scritp.
I have a opc tag that is giving me the controller state of one inverter in a solar plant.
I need to register this states on the table of event. The problem is that the direfent states are given in one bit of the INT2, every bit on the word have a state. So i have made a script that check the value.

That working good, the problem is that with that when the int2 tag value change just in one bit, the rest of states are save in the event table too coz you can have more of one state in the same time. So in every single change in this tag, print this state and the rest of states that are still on. and making a lot of new rows in the event table that are repeat

[color=#008000]nuevo=newValue.value

if nuevo & (1 << 0):
accion=‘Deactivation from Radio Signal’
target=‘Inverter 9 - LOCAL MVL9’
system.db.runUpdateQuery(“INSERT INTO audit_events (EVENT_TIMESTAMP, ACTOR, ACTION, ACTION_TARGET, ACTION_VALUE, STATUS_CODE,ORIGINATING_SYSTEM, ORIGINATING_CONTEXT) VALUES (NOW(),‘system info’,’%s’,’%s’,%d,0,‘project=solar_plant’,2)” % (accion,target,nuevo))

if nuevo & (1 << 1):
accion=‘Deactivation caused by Overvoltage during limitation from power reduction’
target=‘Inverter 9 - LOCAL MVL9’
system.db.runUpdateQuery(“INSERT INTO audit_events (EVENT_TIMESTAMP, ACTOR, ACTION, ACTION_TARGET, ACTION_VALUE, STATUS_CODE,ORIGINATING_SYSTEM, ORIGINATING_CONTEXT) VALUES (NOW(),‘system info’,’%s’,’%s’,%d,0,‘project=solar_plant’,2)” % (accion,target,nuevo))
.
.
.
.[/color]

I would like to do something like that:

[color=#008000]nuevo=newValue.value
viejo=oldValue.value

if nuevo & (1 << 0) and not viejo & (1 << 0):
accion=‘Deactivation from Radio Signal’
target=‘Inverter 9 - LOCAL MVL9’
system.db.runUpdateQuery(“INSERT INTO audit_events (EVENT_TIMESTAMP, ACTOR, ACTION, ACTION_TARGET, ACTION_VALUE, STATUS_CODE,ORIGINATING_SYSTEM, ORIGINATING_CONTEXT) VALUES (NOW(),‘system info’,’%s’,’%s’,%d,0,‘project=solar_plant’,2)” % (accion,target,nuevo))

if nuevo & (1 << 1) and not viejo & (1 << 1):
accion=‘Deactivation caused by Overvoltage during limitation from power reduction’
target=‘Inverter 9 - LOCAL MVL9’
system.db.runUpdateQuery(“INSERT INTO audit_events (EVENT_TIMESTAMP, ACTOR, ACTION, ACTION_TARGET, ACTION_VALUE, STATUS_CODE,ORIGINATING_SYSTEM, ORIGINATING_CONTEXT) VALUES (NOW(),‘system info’,’%s’,’%s’,%d,0,‘project=solar_plant’,2)” % (accion,target,nuevo))

if nuevo & (1 << 2) and not viejo & (1 << 2):
accion=‘Voltage level to high for activation’
target=‘Inverter 9 - LOCAL MVL9’
system.db.runUpdateQuery(“INSERT INTO audit_events (EVENT_TIMESTAMP, ACTOR, ACTION, ACTION_TARGET, ACTION_VALUE, STATUS_CODE,ORIGINATING_SYSTEM, ORIGINATING_CONTEXT) VALUES (NOW(),‘system info’,’%s’,’%s’,%d,0,‘project=solar_plant’,2)” % (accion,target,nuevo))

if nuevo & (1 << 3) and not viejo & (1 << 3):
accion=‘AC Power Limitation caused by over frequency’
target=‘Inverter 9 - LOCAL MVL9’
system.db.runUpdateQuery(“INSERT INTO audit_events (EVENT_TIMESTAMP, ACTOR, ACTION, ACTION_TARGET, ACTION_VALUE, STATUS_CODE,ORIGINATING_SYSTEM, ORIGINATING_CONTEXT) VALUES (NOW(),‘system info’,’%s’,’%s’,%d,0,‘project=solar_plant’,2)” % (accion,target,nuevo))
.
.
.
.
[/color]

But i can not find the property that give me the old value.

PD: sorry for my english

Unfortunately, we don’t have the old value in tag change scripts. We only have the new one. You can always store the old value in the database or another memory tag.

Yes i already used that

[color=#008000]nuevo=newValue.value
viejo=int(system.db.runScalarQuery(“SELECT ACTION_VALUE FROM audit_events WHERE ACTION_TARGET =‘Inverter 9 - LOCAL MVL9’ ORDER BY EVENT_TIMESTAMP DESC LIMIT 1”))[/color]

But i think its nicer with one property oldValue. Anyway I would like to propose that for next generation of ignition your team programmer add one option to the tags for auto-create a event, not only Auditing.

Like when you configure the alarm to one tag but for auto made one event.
Its a very powerfull tool for check the states of the systems, and right now i have to use every time the tag change event script that takes a lot of time.

Thanks a lot!