cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - Stay updated on what is happening on the PTC Community by subscribing to PTC Community Announcements. X

Stopwatch to calculate operating hours

JC_10453657
4-Participant

Stopwatch to calculate operating hours

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 by using QueryPropertyHistory + dateDifference.

Any help is appreciated!

ACCEPTED SOLUTION

Accepted Solutions

Try to use Thing Subscriptions with data change event of  Thing Property.

 

  • Create a new property "MotorRunTime"
  • Create a subscription with Data Change event
  • Every data change event take the difference if ON, then update into "MotorRunTime"

View solution in original post

2 REPLIES 2

Try to use Thing Subscriptions with data change event of  Thing Property.

 

  • Create a new property "MotorRunTime"
  • Create a subscription with Data Change event
  • Every data change event take the difference if ON, then update into "MotorRunTime"

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.
}

Announcements


Top Tags