Battery Reporting, a LLLLLOOOOOTTT of decimal places, Intermittently

Hey All,

Any advice on what to do when the decimal places are way too many and screw up my Dashboard? When it reports so many decimal places it pushes over the battery icon and it's no longer visible. The device is a laptop running Fully Kiosk Browser. It doesn't do it all the time, just every so often one of the battery levels have a long list of digits after the decimal, lol. Even if the device is reporting a pile of decimal places shouldn't the Dashboard tile only report max 3 digits so it doesn't screw up it's formatting? I managed to capture this today so you can see what I am talking about a little better.


Battery 1
image

And here it is back to normal again....

What is the Device Driver that is producing the excessive decimal places? If custom code, I would modify it to truncate to only 1 decimal place (or none.) If this is a built-in Hubitat driver, then you should report it to the Hubitat team.

1 Like

Well thanks for that @ogiewon, it's the "Fully Kiosk Browser Controller" Driver. Great Idea!! Just have to find that part of the code and figure out how to do it, lol.
Maybe the developer will hear my sad story and help me @gavincampbell

Just curious, If you don't mind me asking..... What is "Garage Scent"? Is that like "ode de gear oil"?

2 Likes

Assuming this is the code you're using...

Looks like lines 184 and 423 are the ones that issue the sendEvent() calls for the battery attribute. You'll just need to do a little formatting on the 'value' to make sure the excess decimal places are removed.

1 Like

@JohnRob Hahahaha, I wish!!!! WAF, Scentsy to make the Garage smell nice. Doesn't really work when I am tuning up the chainsaw though :rofl: :rofl: :rofl: :rofl: :rofl:

@ogiewon yep that's exactly it! Thanks for the advice!!

@ogiewon I added the .round() function. See how that goes over the next few days.

1 Like

Hi @ogiewon , I never did get this to work properly. I tried Round, Trunc and mess with a couple big decimal and Math things. They just keep coming back with an error. I am sure I am not doing it correctly with the syntax and still get the bigggggg long decimal and my battery indicator shifts out of the tile. I am certainly no programmer, but I try. Would you be so kind and have a look at what needs to be done to fix this? I tried reaching out to the original developer, but sadly no response.

I'm no programmer at all, but if you want to restrict it to a specific number of decimal places doesn't that have to be specified in .round()?

For S&G, perhaps you could try this modification to line 423 to get two decimal places.

sendEvent([name:"battery",value:(response.json.batteryLevel).round(2)])

1 Like

I would try a slight modification, if the above does not work.

@chad.andrews - give the following a try. Report back any errors that appear in the logs.

float tmpValue = Float.parseFloat(response.json.batteryLevel)
tmpValue = tmpValue.round(1)
sendEvent(name: "battery", value: tmpValue)
2 Likes

Thanks Guys! No luck though.

Gives me this error

And using this one,

produces this error,

Something I am doing wrong?

@chad.andrews
This is how I have been doing rounding and it seems to work good for any variable type, as it converts to a double first. Change the number to be how many decimals you want.

VARIABLENAME.doubleValue().round(2)

2 Likes

@jtp10181 , this looks promising. I hit refresh and no errors, and the battery level jumped to no decimal places, like I want. I will keep an eye and see how it goes. Thanks

Awe dang it....

Maybe i need to change it on line 184 too?
image

I changed the 184 to this, no errors. see how that runs.
image

2 Likes

I would make that .round(0) instead of .round().

1 Like

Seems to be working.... :smiley:

2 Likes

Oh if you want no decimals then actually this is a simpler way of doing it.
Math.round(VARIABLE)

But the way I suggested before that you got working using round(0) for no decimals is probably fine also.

2 Likes