Implement Hour Meter function from Modbus Inputs
I would like to implement a hour counter functionality to my project.
More specifically, I have 4 digital inputs (modbus RTU) which will have to be monitored of how many hours they are "on".
I suppose a script with a timer to add "1" to a data point after the passing of 1 hour is the way to go, any ideas?
phildunlap last edited by
Hi fylarxos, welcome to the forum!
A script is definitely the way to go. Regardless of the script logic, I would do this with four meta points.
Then I would wonder how exacting you're looking to be. Yes, a script on a timer totaling the elapsed time since last run is one perfectly valid solution, that is responsive at the rate you set the cron pattern. That might look like a meta point like this,
var stats = di.past(MINUTE, 6).getStartsAndRuntime(); if(my.value === null) return stats.containsKey(true) ? stats.get(true).runtime/3600000 : 0; return my.value + (stats.containsKey(true) ? stats.get(true).runtime/3600000 : 0);
on a cron like
0 0/6 * * * ?or perhaps six minutes is not a frequent enough update (your counter would go up by
.1if it didn't go false. You could change this to update as soon as the point went false, but we'll simplify the first value. In this next script, the context point
diupdates the context...
if(my.value === null) return 0; //if(my.time > CONTEXT.getTimestamp()) // throw "Timestamps are backward, something is off."; //Possible, but would take some action by user var stats = di.getStats(my.time, CONTEXT.getTimestamp()).getStartsAndRuntime(); return my.value + (stats.containsKey(true) ? stats.get(true).runtime/3600000 : 0);
Which we could also run on the six minute cron to ensure it gets some sort of update even if the point stays true.
I am going to resolve the discrepancies and post in this and perhaps that thread when I do.
Thank you for your reply, I will try out your proposed solution.
phildunlap last edited by phildunlap
We resolved after some discussion to bring back the
.get()function as used on the help page linked to in my last post. Thanks again for bringing this to the fore! This will be the case in the production 3.5 release.