Reporting the lowest battery level

variables

#1

Hey guys,
I have a piston that I can run from a routine which will report to me any sensors below a set battery level or any sensors that are offline. I’m trying to program in a line that will tell me what device has the lowest battery level and what that battery level is.

Line 64. It is returning the lowest sensor battery level of 52% but I don’t know how to make it say what sensor has that battery level. My attempt is still in there which doesn’t work, it just reports “The lowest battery is at 52”. If you were wondering what I was trying to do, I was trying to match a device that had the same battery level as LowestBatt

Ideally I’d like it to report, “The lowest battery is Sensor 17 at 52%” and I’d like to save the device name with the lowest battery to the LowestBatt variable.

Cheers.


Using a variable to define a variable / routine
#2

Thanks to Eric 182 who sent me this piece of code I’ve been messing around with. This piston now reports all of the sensors and their associated battery levels. I happy to go with this method if anyone knows a way I can sort it into battery level ascending order.


#3

The easy way is:

  • PUSH Notification #1 lists devices under 16%…
  • PUSH Notification #2 lists devices 16% - 30%…
  • PUSH Notification #3 lists devices 31% - 45%…

If you want only a single notification, you can dump the three lists into variables, and then send a single PUSH with all 3 variables


#4

Sounds great but can I do the same thing using PUSH notifications? I’m in Australia and I was just reading something this morning that mentioned SMS is no longer available outside of US


#5

Oh sorry, yes PUSH should work. Editing my last post now


#6

Okay. I managed to got Post #2 working something like that and I don’t mind it, however it bunches up all of the text.
So as far as your aware there is no way to just grab the stats of the lowest sensor?

Alternatively, if I could space out the report post #2 puts out I could work with it. At the moment it just looks like:
Sensor 1 10%, sensor 2
43%, Sensor 3 17%,
Sensor 4 94% etc…

I was reading another post about adding line breaks SMS Notification - Line break?
But unsure if it would work and where to put the \n or “line” in the second example, unless you would have an idea?


#7

Here is how I split mine into separate lines like this:

temp


By the way, that method works for SMS… I don’t think I tested this with PUSH notifications. Notifications are quite limited, and might not display carriage returns… Furthur testing is required.


#8

That works perfectly! Thank you very much. I know I may be pushing my luck here but is it possible to put the battery levels in ascending order? So at a quick glance you can easily find the lowest battery level?


#9

I just tested this Expression using PUSH notifications, and it split into two lines, as hoped.

pic

For clarification… It appears as a single line in my notification tray, but with two fingers, I can expand the notification a bit. At that point, it displays on separate lines, as intended.


The easiest method I mentioned earlier
Essentially, segregate by blocks, then combine blocks into a single notification.

Note, it is not perfect, since it may look like this:

12% = Bathroom   ¯¯\
 8% = Hallway       Really Low Batteries (< 16%)
15% = Rec Room   __/
26% = Kitchen      \
18% = Dining Room   Low Batteries (16-30%)
21% = Garage     __/
38% = Bedroom      \
32% = Porch         Kinda Low Batteries (31-45%)
43% = Theater    __/

… but at least the really low ones are mentioned first.


#10

Okay no worries. Sorry I didn’t understand that’s what you meant.

I do have another idea of how to do it but I don’t know if it’s possible. What I would like to know is, If I have a variable that already contains information, can I add more information to that variable?
For instance;
this IF finds AVGTemp and stores it to report
this IF finds battery levels and adds it to report
this IF finds $status and adds it to report

PUSH {Report}

displays as:
Average Temp 25 degrees
Contact 12%
Motion 2 45%
Motion 7 68%
Water Cooler OFFLINE


#11

Usually the way this is tackled is lowering your variable {lowBatteryLevel} to something like 25-30 so it only lists the really low devices…

But be careful with this… I have many devices where the battery dies at about 70% (as seen in SmartThings)


#12

Yes. You can refer to the variable in any line, like this:

pic

Each line adds more data to the end of the string variable

In this case, the final variable was:
At 7:25 A.M. on Saturday in November


Pro Tip:

Usually we want to use a STRING variable when doing this, because using boolean, numbers, time or devices can return strange results.


#13

may I ask, what does the ’ symbol signify? I’m just trying to figure out how to apply this method to my piston:

Set Variable {HealthReport} = {NotOnline + " is offline"}
Set Variable {HealthReport} = {BadBatt + " battery is low"}
Set Variable {HealthReport} = {"The average temp is " + {AvgTemp}

I tried this

Set Variable {HealthReport} = {'NotOnline + " 'is offline"}
Set Variable {HealthReport} = {‘BadBatt’ + " 'battery is low"}
Set Variable {HealthReport} = {"'The average temp is " + {'AvgTemp}


#14

I often use single quotes instead of double quotes… Either will work, just be consistent.


Pro Tip:

If your phrase has an apostrophe like the word IT’S, then use double quotes for your quotation marks.


#15

Your last post overwrites the variable each and every line… You have to refer to the variable name {HealthReport} if you want to keep the old data when adding the new data.

Maybe something like this:

Set Variable {HealthReport} = 'something.'
Set Variable {HealthReport} = HealthReport' something else.'
Set Variable {HealthReport} = HealthReport' even more data.'

(these examples are using an Expression box)

Final results for this example:
something. something else. even more data.


#16

Fantastic! Thank you soo much for all of your help. :smiley:


#17

I figured I would post my piston here just in case anyone else would like to use it.

that will give you this:


#18

It looks good…

One observation though… If you have an event where {Sensors}'s $status are ONLINE, or where {NotOnline} is empty… then line 42 will not execute. (this is good). The problem will be in the next Set variable (line 55, 59, 68, 70, 73 or 75). Whichever one runs first, will add the new data to the end of the old (previous) data…

You can avoid seeing outdated info by adding a new command at the beginning of the first THEN: (right before line 32)

Set variable {HealthReport) = ''
(that is two quotes)

This effectively “clears” the variable at the beginning of each execution, so all of the old data is wiped away…


Alternatively, you can add this line to the ELSE block between lines 33-44:

Set variable {HealthReport) = '*** System Check *** Everything is online'

So the old data is removed when {Sensors}'s $status is not OFFLINE.


Basically, you must ensure that the FIRSTSet Variable” that executes does NOT have “HealthReport” written in the Expression box.


#19

Good spot. :+1:
Totally missed that, as I always have some sort of sensor that is offline.
Would editing the variable and setting a value to it do the same thing? As it does mention:
“By assigning an initial value to the variable, you are instructing the piston to initialize the variable on every run to that initial value.”
So if I just put ’ ’ in there it should do the same?


#20

Oh no, that breaks the piston. Nevermind, i’ll do Set variable {HealthReport) = '' like you suggested.:grinning: