This code...
case "runtime":
sendEvent( [
name: 'batteryRuntimeMinutes',
value: Integer.parseInt(value) / 60,
unit: "min",
descriptionText: "Remaining runtime is ${Integer.parseInt(value)} minutes"
])
break;
converts seconds to minutes but I need to round that to the nearest whole number. How do I accomplish that ?
I had no luck using .round() as that gave errors I can't get past.
I've used:. minutes = Math.round(minutes)
2 Likes
Would you mind sharing the errors? I have used .round() in the past and it has worked for me
Wrapping .ceil() should accomplish what you need I think
https://www.tutorialspoint.com/groovy/groovy_ceil.htm
Not sure what the syntax would be putting inside that string though, groovy isnβt my thing
value: ((Integer.parseInt(value) / 60).round()),
produces
java.lang.NullPointerException: null on line 123 (parseVAR)
Perfect !! Worked exactly what I wanted..
case "runtime":
min = (Integer.parseInt(value) / 60)
minutes = Math.round(min)
sendEvent( [
name: 'batteryRuntimeMinutes',
unit: "min",
descriptionText: "Remaining runtime is ${minutes} minutes"
])
break;
1 Like