Low Battery Notification script

Posted on
Mon Jan 26, 2015 11:27 am
jay (support) offline
Site Admin
User avatar
Posts: 18200
Joined: Mar 19, 2008
Location: Austin, Texas

Low Battery Notification script

Low Battery Nofication.py

Get it in the File Library

Version History

v1.0 - Initial release

Description

This script will loop through all indigo devices looking for devices that report battery levels. We do this by looking at the batteryLevel property that all devices have. If a device doesn't support battery reporting, that value will be 'None'. We also check to see if the device is enabled so that an easy way to shortcut getting notifications you don't want is to just disable the device.

When the script finds one, it will use the following heuristics to decide if a notifiction should be sent for the device:

- if the battery level is below the 'batteryThreshold' OR
- if the device hasn't been updated in more than 'timeThreshold' days

There are a couple of ways to set the thresholds. The default values are:

batteryThreshold = 5%
timeThreshold = 0 days (or anything over 24 hours)

These defaults can be overridden globally by creating Indigo variables named:

lbnBatteryThreshold
lbnTimeThreshold

If either of these are set, they will be used as the global thresholds. You may also use the Global Property Manager plugin to add some properties to specific devices that will override these thresholds:

lbnBatteryThreshold
lbnTimeThreshold
lbnSkipNotification

The latter tells the script to ignore this device (true/false or yes/no). You might want to use that for a battery powered device that can also be plugged into mains power. In that case, it may or may not show battery level and may not actually report status for long periods of time. This is a convenient way to just skip those devices.

Once we've determined that a device needs a notification, then we simply look for an action group named with the device name + " low battery notification". Here's some example names given the device name:

Code: Select all
      Device Name        | Action Group Name
      -------------------+------------------------------
      Front Door Lock    | Front Door Lock low battery notification
      Hall motion sensor | Hall motion sensor low battery notification


Note that the names are case sensitive so make sure they match. If the script finds a matching Action Group, it will execute it.

There are several ways you can run this script: once a day is probably the easiest. You can get clever however and run it every hour. Add some current time conditions to the schedule and it can notify you once an hour between, say, 6pm and 10pm. Lots of options.

I contributed this script because it does what I need it to do, no more or less. There are a lot more things that this script can be expanded to do and is a great start for other kinds of notifications. Feel free to modify it as you see fit. Note, however, that it's not an officially supported script and is not shipped with Indigo. I'll certainly try to answer any questions and will update this post to clarify anything that's unclear, but treat it like any other user-contributed script.

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Posted on
Mon Feb 16, 2015 11:52 am
davinci offline

Re: Low Battery Notification script

Thanks for the script. Do I have to make an ActionGroup for every device I have or is there an easier way?

Posted on
Mon Feb 16, 2015 6:56 pm
jay (support) offline
Site Admin
User avatar
Posts: 18200
Joined: Mar 19, 2008
Location: Austin, Texas

Re: Low Battery Notification script

With this script it's a 1:1. Get one working like you want it then just duplicate it and rename.

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Posted on
Wed Mar 04, 2015 1:24 am
MarcoGT offline
Posts: 1091
Joined: Sep 11, 2014
Location: Germany

Re: Low Battery Notification script

Thanks a lot.

I have started yesterday to implement the low battery notification in my system :)

Posted on
Wed Mar 04, 2015 7:10 am
howartp offline
Posts: 4559
Joined: Jan 09, 2014
Location: West Yorkshire, UK

Re: Low Battery Notification script

If you want a mass catch-all script, have a look at viewtopic.php?t=12578#p88444

Posted on
Fri Jul 10, 2015 8:36 pm
rycardo offline
Posts: 53
Joined: Jul 10, 2015

Re: Low Battery Notification script

Hey Jay,

Very Nice!

Should this report the battery level for Insteon battery powered door sensors, mini-remotes, motion sensors, and water leak detectors?

I didn't get any low battery notifications, even though I know the battery is low on one of my motion sensors, so I modified the script by adding an else block for your top most if block:
Code: Select all
else:
      indigo.server.log(device.name + " does not support batteryLevel",  "Low Battery Notification",  0)


Every enabled device in Indigo is logged as not supporting batteryLevel, including my device types above.

Rycardo

Posted on
Sun Jul 12, 2015 11:29 am
jay (support) offline
Site Admin
User avatar
Posts: 18200
Joined: Mar 19, 2008
Location: Austin, Texas

Re: Low Battery Notification script

I believe most (all?) Insteon battery-powered devices don't actually report the battery level, they only send commands to various groups to report when the battery is low.

You could certainly modify the script to only look at a time threshold and ignore any battery specific stuff.

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Posted on
Sun Jul 12, 2015 11:36 am
rycardo offline
Posts: 53
Joined: Jul 10, 2015

Re: Low Battery Notification script

Thanks for the reply. Since I have an all Insteon set up, I tend to forget your software supports other brands.

I was anxious to try your method as I used to use a python script I found in the forums for checking battery levels on motion sensors when motion detection turned off. That script stopped working. In debugging it, I discovered that I can no longer use Indigo to send Raw Commands to Insteon devices. Whether through the menu, a script (AppleScript or Python), or manually.

Do you know if something changed?

Thanks,

Rycardo

Posted on
Sun Jul 12, 2015 11:51 am
jay (support) offline
Site Admin
User avatar
Posts: 18200
Joined: Mar 19, 2008
Location: Austin, Texas

Re: Low Battery Notification script

Nope - I have quite a few scripts sending raw Insteon commands that are working fine. What do you get/see in the event log when you try to run one?

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Posted on
Sun Jul 12, 2015 11:57 am
rycardo offline
Posts: 53
Joined: Jul 10, 2015

Re: Low Battery Notification script

I just used Indigo > Interfaces > Insteon > Set Motion Sensor Timeout...
and received this:
12 Jul, 2015, 13:52:59
Error "Front Porch Motion Sensor" raw insteon command; send failed (no acknowledgment)


That is what I always get from the menu.

If I try to run the python script to check battery levels:
12 Jul, 2015, 13:55:40
Test Raw Command 1 address is:31.D6.62
id : 1084528646
name : basementMotionSensorBatteryLevel
value : 0
Test Raw Command 3 Checking battery level.
Error "Basement Motion Sensor" raw insteon command; send failed (no acknowledgment)
Test Raw Command 3.1 0
Test Raw Command 3.2 No response, stopping


These all used to work, just one day they stopped working. Not sure what changed (if anything), or why.

Posted on
Sun Jul 12, 2015 1:09 pm
matt (support) offline
Site Admin
User avatar
Posts: 21411
Joined: Jan 27, 2003
Location: Texas

Re: Low Battery Notification script

Is the motion sensor awake? Battery operated modules can only receive commands when they are awake, so the "no ack" error you are seeing would be expected if it were asleep.

Image

Posted on
Sun Jul 12, 2015 6:04 pm
rycardo offline
Posts: 53
Joined: Jul 10, 2015

Re: Low Battery Notification script

I'm not sure what you mean by "awake", the devices are active, and responding to open / close for door sensors, and motion started / stopped for motion sensors. Is this what you meant?

The python script I used before, was triggered by the motion sensor sending a Group 1 Off, per it's author's documentation.

Here is some new debugging, I sent the Menu Item "Set Motion Sensor LED Brightness", but the same happens on any of the menu items, for any of my motion sensors.
12 Jul, 2015, 19:59:05
Error "Family Room Motion Sensor" raw insteon command; send failed (no acknowledgment)

12 Jul, 2015, 19:59:38
Received INSTEON "Family Room Motion Sensor" on (button 1)
Trigger Family Room Sensor - Motion Started
Error "Family Room Motion Sensor" raw insteon command; send failed (no acknowledgment)

12 Jul, 2015, 20:00:48
Received INSTEON "Family Room Motion Sensor" off (button 1)
Trigger Family Room Sensor - Motion Stopped

12 Jul, 2015, 20:01:09
Error "Family Room Motion Sensor" raw insteon command; send failed (no acknowledgment)

Posted on
Mon Jul 13, 2015 2:20 am
howartp offline
Posts: 4559
Joined: Jan 09, 2014
Location: West Yorkshire, UK

Re: Low Battery Notification script

rycardo wrote:
I'm not sure what you mean by "awake"

Have a look at my reply in this thread re 'awake':

viewtopic.php?t=14297


Sent from my iPhone using Tapatalk

Posted on
Mon Nov 02, 2015 11:07 am
wideglidejrp offline
User avatar
Posts: 555
Joined: Jan 15, 2012
Location: Danbury, CT

Re: Low Battery Notification script

Can non-Insteon devices be part of this? I have Kwikset door locks with batteries controlled by Vera and a Multisensor controlled by z-stick. I would love to include them.

John R Patrick
Author of
Home Attitude

Posted on
Mon Nov 02, 2015 12:40 pm
jay (support) offline
Site Admin
User avatar
Posts: 18200
Joined: Mar 19, 2008
Location: Austin, Texas

Re: Low Battery Notification script

Sure.

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Who is online

Users browsing this forum: No registered users and 3 guests