I currently have a string item that holds a “runtime” from my APC UPS and it looks something like this…
Can anyone suggest how I could convert this into something that could be visualised on a chart? I’m guessing I’d need to convert it into some sort of hours and decimals?
Convert it to minutes and display that.
I’ve done it that way. I know I have 1600 minutes normally so can watch it reduce from that.
To elaborate on Crispin’s solution:
- Change the Item to store the total minutes or seconds
- Add a JS transformation to convert the total to the more readable hours minutes seconds
- Persist and chart the total value
Here is a transform I use to convert minutes to dd:hh:mm
if(isNaN(i)) return "NAN";
var mins = i%60
var totalhours = Math.floor(i/60)
var hours = totalhours%24
var days = Math.floor(totalhours/24)
var pad = "00";
Thanks guys, the UPS provides this data via the SNMP binding and from what I can see I can’t get the runtime in minutes… It just provides it as something like “6:02:00:00”.
And it that hours:minutes:seconds:hundreds or days:hours:minutes:seconds?
We can build a simple JS transform to change this into minutes
I’d say at full capacity it’ll be Hours, Minutes, Seconds, Ms…
But eventually the hours might drop off if it was running one batteries and there was less than an hour left…
And I guess if I added more battery capacity it could start adding days to the front?
We’ll assume that it’s HH:MM:SS:XX
We need to do the inverse on the js function that @rlkoshak provided
Save the following in upsmins.js in the transformation folder
var hours = parseInt(i.split(':'))
var mins = parseInt(i.split(':'))
var output = hours * 60 + mins
So you need another item:
And a rule
rule "Convert UPS string to minutes"
UPSmins.postUpdate(transform("JS", "upsmins.js", UPSSting.state.toString)