How to make counter based on Boolean status

Hi I am using ignition 7.9, I would like to make a counter base on the Boolean status
we have a tank filter and I want to capture how many times per day is ON and OFF
I create an expression tag and used an if statement like: if ( x!=0, y=y+1,z=z+1)
which is x is OPC tag, y and z is memory tag
then I like to show the value of y

Regards

You could use a tag change script to create you counter

if newValue.getValue() > 0:
	tagPath = event.getTagPath().getItemName()
	totalTag = "[TagProvider]TotalTag"
	count = system.tag.read(totalTag).value
	count = count + 1
	system.tag.write(totalTag, count)

You would also need to zero the counter tag, which ive done by creating a expression tag that is set to true when you want to perform the zeroing. This is the expression i used to zero at midnight:

getHour24(now()) = 00 && getMinute(now()) = 0

I then created another tag change script that set my tag back to zero when the reset tag is true.

1 Like