As the title says (hopefully) I'm trying to capture whilst a value transitions from being zero to anything above zero and then from a value back to zero; and store those timestamps into a metapoint/virtual datapoint.
By doing this it means I can have a user select from a drop down a chosen event (in chronological order) which will provide the starting and end timestamps for the data I need.
I've been trying to capture this in a metadata point and I'm just having no luck. I even went as far as using the JSON rest api to store data as a placeholder so once I have both the start and end of an 'above 0' period the values are stored into the datapoint.
And no prevail.
Has anyone got any ideas or what I could do to implement and ensure I obtain the desired script behaviour?
I check between two values to see the status and if there is a change and the value is zero I take a snapshot.
//Start Date
// 0 --> .>0
if( values[1].value>values[0].value && values[0].value===0 )
{
var tmp = {
title:"Commencing "+ new Date(parseInt(values[0].time)).toLocaleString("NZST"),
startTime:values[0].time,
endTime:''
};
// setJSONStore("Effluent-Pump-1","user",tmp);
events.set( JSON.stringify(tmp) );
return JSON.stringify(tmp);
}
//end date
// >0 --> 0
if( values[1].value<values[0].value && values[1].value===0 )
{
//getJSONStore("Effluent-Pump-1","user",getEventData,{}); //custom global script I threw together.
var tmp = JSON.parse(IE.value);
tmp.endTime = values[1].time;
IE.set( JSON.stringify(tmp), volume.lastValue.time );
events.set( JSON.stringify(tmp), volume.lastValue.time );
}