Is there an easy way to setup low battery alerts for sensors that use batteries?
Low Battery Alert
- 150 Views
- Last Post 04 March 2015
Oooh..Oooh..I get to answer a question!
This is completely thanks to someone else but it works awesome so google a string in the code to see who you should be thanking!
1) Create devices for your battery management
2) Create a scene and call it something meaningful (I called it "Battery Alerts")
a) add each battery device to this scene
b) my trigger for this scene is 5am every morning
c) I have a pre-script that someone else wrote and posted somewhere that checks all devices associated with this scene and sends me an email when it gets below a configurable %
Here's the pre-script you can copy/paste it into a new file in your scripts directory for the inControl install:
[code]
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MLS.ZWave.Service.Rules;
using MLS.ZWave.BusinessObjects;
using MLS.HA.DeviceController.Common.Device.ZWave;
///
/// This script will send an email when battery powered devices in the scene device list report battery level <=>=>
///
public class BatteryMonitor : ScriptBase, ScriptInterface {
public void runScript() {
try {
bool sendMailNeeded = false;
var subject = "Battery level alert";
var bodyLine = "Device '{0}' reports battery level of {1}%.
";
var body = "";
// Before the for-each loop, make sure sceneDevices is not null
if (base.sceneDevices == null) {
return;
}
foreach (var sd in base.sceneDevices) {
var device = getNode((Guid)sd.deviceId);
if (device != null && device.level <= 10)="" {="">=><===battery reporting="" percent="" here.="" 100="" for="">===battery>
sendMailNeeded = true;
body = body + string.Format(bodyLine, device.deviceName, device.level);
}
}
if (sendMailNeeded) {
sendEmail(string.Format(subject), string.Format(body));
}
} catch (Exception ex) {
// Log the exception here
var message = ex.Message;
writeLog(message);
}
}
}
[/code]
3) enjoy the alerts when one or more batteries are low!
Steve
Thanks Steve, that's a great help and works perfectly!