I have a motor tag that tells me if it is "On" or "Off". I am trying to make a "Starts and Stops" counter tag based on this.
So, when it goes from "Off" to "On", this will then count as 1 to the "Starts and Stops" counter tag. This counter tag will then go up by 1 each time the motor goes from "Off" to "On". So a basic cumulative tag.
I am a bit unsure how to create this using Asset Analytics since I am mainly work in visualization.
What I've done so far is to use the "HasValueChanged" function, which checks if the motor tag has changed from 0 to 1 or 1 to 0. I've saved this to a variable for each state.
My current Calculation:
(Variable: AF Calculation)
MotorStatus: 'Motor Running'
MotorValue: HasValueChanged('Motor Running')
MotorOff: If (MotorStatus = 0 and MotorValue = True) THEN "Motor is OFF" Else NoOutput()
MotorOn: If (MotorStatus = 1 and MotorValue = True) THEN "Motor is On" Else NoOutput()
My next part of the calculation will basically be: If the motor was 0 and the current value is 1, then add +1 value to the "Starts and Stops" Counter Tag, and keep doing this each time to motor goes from 0 to 1 adding +1 to the "Starts and stops" counter.
My problem is I am a bit unsure how to do this and wondering here if any AF analytics experts can help!
Something along the lines of:
If PreviousValue('Motor Running') = 0 and CurrentValue('Motor Running') = 1 then 'Starts&Stops' + 1 else NoOutPut
But AF does not have any Previous or CurrentValue functions :/
I'm stuck thinking I have to use something like:
If ('MotorStatus' = 1) then 'Starts&Stops' + 1 else NoOutput()
But I need to find a way to get my AF calculation to check the previous history of 'MotorStatus' and only run the above command is the previous value was < 1, and not run the above command if it has already run with that value.