battery charting - DaveL17/indigo-scripts GitHub Wiki

The battery charting script is used to create an integrated bar chart of the battery levels of all installed and communicating battery-powered devices on your Indigo network.

[!NOTE] Devices that report the device state* ['batteryLevel'] are charted.

When run as written, you'll get an image that looks something like this:

Battery Test Script

The integration comes from the fact that the list of devices is updated each time it's called--so if you add or remove a battery-powered device from your network, the graphic will be updated to reflect the change the next time it's called.

Customizations

You can easily update the script to change its look and feel by adjusting the values of the display parameters. The parameters should be easy to spot (they're near the top of the code) and should be at least somewhat self-explanatory.

[!NOTE] There are two caution levels that can be configured that will change the bars for devices that meet the caution criteria. The first caution level is meant to be just that--a caution. The battery level is getting low. The second caution level is meant to be an alert that the battery will soon need to be replaced. The defaults for these levels are 10 percent and 5 percent, but you can change them to any value between 1-100 (a level of zero won't be charted.) There are also colors associated with the caution levels. The defaults are yellow for caution and red for critical.

  • Colors
    Colors can be expressed using words or hex, and should be presented as strings. For example, 'black' and '#000000' would yield the same result. Likewise for 'white' and '#FFFFFF'.

  • Output File
    This is the full path to where the image will be located, and the image name. The default is for Indigo 7 and the default filename is battery_test.png. You can change the name to taste, but it's recommended to leave the extension for a png image. Using the default will make the image available as a static image in the Indigo control page editor.

  • Show Data Labels
    This setting controls whether you will have the actual battery level value superimposed on each bar. The choices here are few: True or False.

  • Size
    Chart height and width is expressed in inches. (Technical note: there is a setting within the script for the dpi of the image which is defaulted to 100 dpi.) A height of 4.5 and a width of 6 would yield an image of 450x600. If you change the dpi, the image size parameter would need to be adjusted accordingly.

  • Titles
    There are three titles for the graphic--a chart title and titles for the axes.

[!CAUTION] There's not a lot of error-checking built into the script, and you could break it if you're not at least somewhat careful. It is recommended to adjust only one or two parameters at a time. That way, if something doesn't turn out right, you are just a few CTRL-Z's away from working again. If you change too many things at once, you may have a harder time figuring out which parameter is to blame.

Usage

It's probably overkill to update the image more than once per day. Battery levels just don't change that frequently. It is recommended to create a daily schedule (or add it to an existing daily schedule) and run the script as an Execute Action (Script and File Action).