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