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 = int(indigo.variables[123].value)  # 123 = Indigo variable ID

# or

target_level = 5  # integer between 0-100

and:

email_address = indigo.variables[123].value  # 123 = Indigo variable ID

# or

email_address = "[email protected]"  #  or email string

So:

target_level = int(indigo.variables[123].value)
email_address = indigo.variables[123].value
email_body = ""

for dev in indigo.devices.itervalues():
    if dev.batteryLevel:
        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)