battery low notify - DaveL17/indigo-scripts GitHub Wiki

The Low Battery Notification Script is a simple script to send notifications to alert the user to all devices whose battery level is below a user-specified value. You must provide the value and a notification email address in order to use the script.

TARGET_LEVEL_VAR_ID = 123456  # variable that stores the target battery level (integer, 0-100)
EMAIL_ADDRESS_VAR_ID = 654321  # variable that stores the notification email address

target_level = int(indigo.variables[TARGET_LEVEL_VAR_ID].value)
email_address = indigo.variables[EMAIL_ADDRESS_VAR_ID].value

Alternatively, you can hardcode the values directly instead of pulling them from Indigo variables:

target_level = 5  # integer between 0-100
email_address = "[email protected]"  # or email string

The script then walks all devices and emails a summary of any that are at or below the target level:

email_body = ""

for dev in indigo.devices.iter():
    if dev.batteryLevel is not None:
        if dev.batteryLevel <= target_level:
            email_body += f"{dev.name} battery level: {dev.batteryLevel}\n"

if email_body != "":
    email_body = "The following Indigo devices have low battery levels:\n" + email_body
    indigo.server.sendEmailTo(email_address, subject="Indigo Low Battery Alert", body=email_body)
⚠️ **GitHub.com Fallback** ⚠️