Hi folks,
Question:
How can I calculate the operating hours of a machine? The data that I have is a timestamp for every data change of boolean values. The data comes from a Kepware tag and is stored in a Value Stream.
Context:
I am logging the tag as a property "is the motor on?" of a machine in a ValueStream.
By calling the service QueryPropertyHistory I have two columns: timestamp and "is the motor on" (boolean). The Value Stream stores every data change.
I want to sum the elapsed time every time my data change from true to false. Something like a stopwatch / time counter to measure the operating hours.
The furthest I came so far getting the time difference between the first timestamp and the last one
Any help is appreciated!
Solved! Go to Solution.
Try to use Thing Subscriptions with data change event of Thing Property.
Try to use Thing Subscriptions with data change event of Thing Property.
Thank you Sathishkumar_C,
Since I think it could be helpful for other users (in special the beginners) to see the code, I decided to add it here for reference.
It took me a while to get it right as a beginner.
Subscription:
Based on Data Change event of the boolean variable "is the motor on".
if(eventData.newValue.value == false) {
me.MotorRunTime = me.MotorRunTime + ((eventData.newValue.time - eventData.oldValue.time)/60000/60); // datetime difference in Javascript returns result in miliseconds. Here we convert to hours.
}