A tu jeszcze przykłądowy skrypt w Pytonie do testowania stanu baterii a także sprawdzania czy urządzenie bateryjne w ciągu ostatnich 24h sie meldowało - jeśli nie to oznacza że bateria siadła
Wykorzystałem standardowy skrypt z Indigo i dopasowałem go do swoich potrzeb.Wysyła powiadomienia oraz ustawia alert na panelu. Jak widać można dobrać się do wszystkich właściwości urządzeń:
try:
import indigo
except ImportError:
print "Indigo control scripts can only be used from within Indigo"
raise ImportError
from datetime import datetime, timedelta
## Convenience log function
def log(msg):
indigo.server.log(msg, type="Low Battery Notification Script")
## Constants and global variables
kTrueStringValues = ['true', '1', 't', 'y', 'yes']
notifications = 0
## Get default overrides from variables
# Battery Threshold
v = indigo.variables.get("lbnBatteryThreshold", None)
try:
batteryThreshold = int(v.value)
except:
# default to 5%
batteryThreshold = 5
# Time Threshold
v = indigo.variables.get("lbnTimeThreshold", None)
try:
timeThreshold = int(v.value)
except:
# default to anything older than 24 hours
timeThreshold = 0
lowBatteryDevices = '' #RS
## Start main part of script
log("Skrypt sprawdzania baterii dla stanu minimum %i%% i braku raportowania przez %i dni" % (batteryThreshold, timeThreshold))
## Loop through devices looking for devices that have battery levels
for device in indigo.devices:
if device.batteryLevel != None and device.enabled:
skipNotification = False
days_since_last_update = (datetime.now() - device.lastChanged).days
# get any device specific props added using the Global Property Manager plugin
deviceSpecificProps = device.globalProps.get("com.indigodomo.indigoserver", None)
if deviceSpecificProps:
# if there were some props there, get the ones we care about or just use the defaults
try: batteryThreshold = int(deviceSpecificProps.get("lbnBatteryThreshold", batteryThreshold))
except: pass
try: timeThreshold = int(deviceSpecificProps.get("lbnTimeThreshold", timeThreshold))
except: pass
skipNotificationString = deviceSpecificProps.get("lbnSkipNotification", "false")
# We're trying to be forgiving in terms of what's entered for the skip field, so we lowercase
# it and test it against the list defined above.
if skipNotificationString.lower() in kTrueStringValues:
skipNotification = True
# Here's the meat: if the battery crosses the threshold or the last update does and we didn't find a skip flag
if (device.batteryLevel < batteryThreshold or days_since_last_update > timeThreshold) and not skipNotification:
log("Slaba bateria w '%s' = %i%% nie raportuje od %i dni..." % (device.name, device.batteryLevel, timeThreshold))
notifications += 1
lowBatteryDevices = lowBatteryDevices + device.name + '=' + str(device.batteryLevel) + '% ' #RS
if notifications == 0:
log("Nie ma slabych baterii")
indigo.variable.updateValue(1412296796, value = 'false') #RS "alert_baterie"
else:
indigo.server.sendEmailTo("admin@mac.com", subject='Raport słabych baterii', body=lowBatteryDevices) #RS
indigo.variable.updateValue(1412296796, value = 'true') #RS "alert_baterie"