-
-
Save rscott78/f534412bbd5c03dc1bc8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Text; | |
using MLS.ZWave.Service.Rules; | |
using MLS.ZWave.BusinessObjects; | |
using MLS.HA.DeviceController.Common; | |
using System.IO; | |
using MLS.HA.DeviceController.Common.Device; | |
/// <summary> | |
/// | |
/// ALWAYS MAKE COPIES OF SCRIPTS YOU INTEND TO CUSTOMIZE OR YOUR CHANGES | |
/// COULD BE LOST. | |
/// </summary> | |
public class EmailSceneStatusReport : ScriptBase, ScriptInterface { | |
public void runScript() { | |
try { | |
/*****************************************************************/ | |
/* It's safe to change these const values to match your scenario */ | |
// The amount to dim by each time | |
const byte dimAmount = 1; | |
// How long to wait between dims, in seconds | |
const int waitTimeSeconds = 2; | |
/*****************************************************************/ | |
// The actual brains of this script start here, be careful making changes | |
// beyond this point. | |
StringBuilder sbReport = new StringBuilder(); | |
// Date and name the report | |
sbReport.AppendFormat("{0} at {1}\r\n<br/>", rule == null ? "<no name>" : rule.ruleName, DateTime.Now.ToShortTimeString()); | |
List<MemoryStream> imageAttachments = new List<MemoryStream>(); | |
try { | |
if (triggerMetaData.triggeringDevice != null) { | |
var device = triggerMetaData.triggeringDevice; | |
switch (device.deviceType) { | |
case DeviceType.MotionSensor: | |
sbReport.AppendFormat(" {0} sees {1}. <br/>", device.name, device.level > 0 ? "motion" : "no motion"); | |
break; | |
case DeviceType.BinarySensor: | |
sbReport.AppendFormat(" {0} is {1}. <br/>", device.name, device.level > 0 ? "open" : "closed"); | |
break; | |
case DeviceType.IpCamera: | |
// Send a current snapshot of the camera | |
try { | |
// Request a poll of the camera to get the latest image | |
dm.pollDevice(device.deviceId); | |
var bytes = Convert.FromBase64String(((CameraDevice)device).b64Image); | |
var memStream = new MemoryStream(bytes); | |
imageAttachments.Add(memStream); | |
} catch { } | |
break; | |
default: | |
sbReport.AppendFormat(" {0} is at {1}. <br/>", device.name, device.level); | |
break; | |
} | |
} else { | |
//sbReport.AppendFormat("Device not found<br/>"); | |
} | |
sendEmail(string.Format("Status Report"), string.Format("Status report:<br/>{0}", sbReport.ToString()), imageAttachments); | |
} finally { | |
} | |
} catch (Exception ex) { | |
// Log the exception here | |
writeFileLog("EmailSceneStatusReport Error", ex); | |
} | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment