Battery Level Report - Want to Sort from Highest to Lowest


#1

1) Give a description of the problem
I want to sort report from highest to lowest battery level

2) What is the expected behavior?
Be able to easily identify the lowest battery levels

3) What is happening/not happening?
Don’t know how to make it happen

**4) Post a Green Snapshot of the piston!


(UPLOAD YOUR IMAGE HERE)

5) Attach any logs (From ST IDE and by turning logging level to Full)
(PASTE YOUR LOGS HERE BETWEEN THE MARKS THEN HIGHLIGHT ALL OF THE LOGS SND CLICK ON THE </> ICON TO FORMAT THEM)

REMOVE BELOW AFTER READING
If a solution is found for your question then please mark the post as the solution.


#2

I have never found a simple way to sort a list here…

You may have to add a bunch of logic to get close to what you want…

IF Battery is > 99
    Then list the highest batteries first
Else IF Battery is > 90
    Then list the next highest batteries
Else IF Battery is > 80
    Then list the next highest batteries
Else IF Battery is > 70
    Then list the next highest batteries
etc etc...

With this method, it would mostly be in descending order, but 81% could theoretically still be listed before 89%…


#3

You could load the devices names and their battery values positionally into two separate arrays. Then bubble sort the values changing the position of both the device names and their values in each respective array.

I haven’t had the need to sort anything yet but this would be a good experiment.