Community Tip - If community subscription notifications are filling up your inbox you can set up a daily digest and get all your notifications in a single email. X
hi community,
I want to calculate the sum of time during a variable is equal to true , we can simulate this by a lamp and we want to calculate how many hours that lamp is on;
thanks in advance
You can use the On DataChange event.
When a data change happens, the subscription receives Old and New VTQ (Value Time Quality)
this allows you to determine what state the lamp changed into and what the time delta was.
(Make sure to set the DataChange to Value so you aren't capturing unnecessary triggers)
Thank you @PaiChung ;
I don't know how to use eventData.newValue.time; or eventData.oldValue.time, to calculate delta between the start and the end.
I need more detail please,
thank you
If you look in the snippets there is a date functions library which has dateadd available.
the result returned will be milliseconds.
I am assuming your data would look something like ON, Timestamp and OFF, Timestamp. If you are storing it in a value stream and using InfluxDB as persistent provider then an approach would be to use InfluxDB API /query HTTP endpoint through a service and use its ELAPSED function(calculates the difference between subsequent timestamps) and sum it, to obtain the total uptime between a specified interval. Please note that, I have not tested this approach.
I don't think you would need InfluxDB
again you can just model what you are monitoring, add a property that tracks hours on and use the datachange event/subscription to update it.
I recommend not going the influxdb path unless you have thousands of 'Things' with a very high update rate.
Neither which in this case seem to be true.
Thank you @PaiChung and @rjanardan ,
I Have a thing with an aleatory update rate, and I don't know how to model my prb with events and subscriptions.
can you please give me any tips or some idea to develop my problem.
thank you .
A Subscription could be used to listen to the occurrence of an Event and take some action when it occurs. In your case, the Event would be the value of a Thing property changing.
So, navigate to Subscription tab in your Thing and create a new one. Enable it. Choose Me or Other entity depending on whether the property, whose value will change, belongs to the same Thing or another one. Under Input, you have to select Event as DataChange(event when a property value changes) and you will need to specify which property's DataChange Event you would listen to. Once that is done, you will write code for the action that needs to be done when your property's value changes. You could call existing services as well here.
Besides the great answer given already, for additional learning resource that is free you can go here: https://developer.thingworx.com/en
besides the official stuff here: https://www.ptcu.com/