Email What Triggered Alarm?

  • 112 Views
  • Last Post 24 March 2015
joe6602 posted this 20 February 2015

By the way, with this new version you sent me a link for on Saturday, I am getting the following error repeatedly in the logfile:

3/24/2015 4:02:50 PM: MC: Unprocessed command: 37, 3, 0

Is this something I can turn off, or do I need to adjust something?

Thanks,

Joe

Order By: Standard | Newest | Votes
Ryan-Scott posted this 22 February 2015

Is this what you are looking for about device trigger?

joe6602 posted this 23 February 2015

Thanks Ryan,

Yes, I think so. You say that it works in version 3.145 up. I am running 3.126.5305.30731, which I just installed about a month ago. Do I need to upgrade? If so, once I do, do I just incorporate the "trigger" code in the script rather than calling devices?

Joe

joe6602 posted this 18 March 2015

Hi Ryan,

I upgraded to the latest version, then modified the script to include the triggering devices everywhere I thought appropriate, monitoring the logfile for errors as I went. I have not been able to figure out how to get rid of the final error. I was hoping you could take a look.

Here is the modified script:

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;

///


///
/// ALWAYS MAKE COPIES OF SCRIPTS YOU INTEND TO CUSTOMIZE OR YOUR CHANGES
/// COULD BE LOST.
///

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
", rule == null ? "" : rule.ruleName, DateTime.Now.ToShortTimeString());

List imageAttachments = new List();

try {
// Get all the devices specified in the rule data node list


var devices = triggerMetaData.triggeringDevice.deviceName;
foreach (var sd in devices) {
if (triggerMetaData.triggeringDevice.commandType == MLS.Common.SceneCommandType.Device && triggerMetaData.triggeringDevice.deviceId != null) {
var device = getNode((Guid)triggerMetaData.triggeringDevice.deviceId);
if (device != null) {
switch (device.deviceType) {
case DeviceType.MotionSensor:
sbReport.AppendFormat(" {0} sees {1}.
", device.name, device.level > 0 ? "motion" : "no motion");
break;
case DeviceType.BinarySensor:
sbReport.AppendFormat(" {0} is {1}.
", 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;

joe6602 posted this 19 March 2015

Also,

Since I installed the latest version, I have been getting this error related to the Weather device:

3/18/2015 3:46:40 PM: Weather: Error polling - System.Net.WebException
The remote server returned an error: (429) Too Many Requests.

at System.Net.WebClient.DownloadDataInternal(Uri address, WebRequest& request)
at System.Net.WebClient.DownloadString(Uri address)
at WeatherDevice.WeatherDevicePlugin.pollWeather()

Thanks,

Joe

Ryan-Scott posted this 19 March 2015

Maybe I missed it, but what's the final error you are trying to debug?

The weather device... it's a problem with our weather provider. InControl will continue to attempt a connection (once her hour). We do plan on switching to someone new soon so we don't have the downtime that we have now.

joe6602 posted this 19 March 2015

Sorry, it looks like the error did not make it in the post for some reason.

Here is the error from the logfile:

3/18/2015 3:54:05 PM: Script failed to compile with error: 'MLS.HA.DeviceController.Common.Device.HaDevice' does not contain a definition for 'commandType' and no extension method 'commandType' accepting a first argument of type 'MLS.HA.DeviceController.Common.Device.HaDevice' could be found (are you missing a using directive or an assembly reference?) on line 45.

Ryan-Scott posted this 19 March 2015

If you are wanting your scene to only email you about the device which triggered the scene, then this script will work:

https://gist.github.com/rscott78/f534412bbd5c03dc1bc8

joe6602 posted this 19 March 2015

Ryan,

I will give that a shot.

Thanks,

Joe

Ryan-Scott posted this 19 March 2015

Ryan,

I followed the link, and it looks like it goes to a copy of the standard EmailSceneStatusReport script. I was hoping to modify that, based on what you had told me, to email the list of triggering devices to me.

Thanks,

Joe


It's subtle, but there's a change to the standard script. In this one I added a check to make sure the device in the loop matched the device that did the triggering. So when you get the email, the only device it mentions is the one that triggered the scene.

joe6602 posted this 19 March 2015

Yeah,

Sorry, I did not scroll over to the right far enough. I see the difference now.

Thanks so much.

Joe

joe6602 posted this 20 March 2015

Ryan,

I tried the script out last night, and it is not evaluating the if statement that compares the devices as true. I have two binary sensors as triggers in the particular scene, but it does not seem to capture them when it evaluates the if statement.

Here is an example of the email it sends:

(Status Report) Status report: Alarm at X:XX PM

As you can see, the sbReport is being left off of the message.

I put some writeFileLog commands into the script to check program flow, and it did not write on I placed immediately after the if statement.

That is as far as I was able to get last night. I will put in more writeFileLog commands to see exactly what is happening, but it appears that the logic on the if statement is off.

I was wondering what you thought of this.

Thanks,

Joe

Ryan-Scott posted this 20 March 2015

Ryan,

I tried the script out last night, and it is not evaluating the if statement that compares the devices as true. I have two binary sensors as triggers in the particular scene, but it does not seem to capture them when it evaluates the if statement.

Here is an example of the email it sends:

(Status Report) Status report: Alarm at X:XX PM

As you can see, the sbReport is being left off of the message.

I put some writeFileLog commands into the script to check program flow, and it did not write on I placed immediately after the if statement.

That is as far as I was able to get last night. I will put in more writeFileLog commands to see exactly what is happening, but it appears that the logic on the if statement is off.

I was wondering what you thought of this.

Thanks,

Joe


Hmm, I'm not sure what to think of it... I tested this in 4.0.5544 - perhaps if you are on an older version of InControl it might be missing something.

joe6602 posted this 20 March 2015

I'm running the 3.157 experimental version. Should I download the one you linked?

joe6602 posted this 21 March 2015

Hi Ryan,

I downloaded the 4.0 version you linked here and it still delivers a message without any device names. I uncommented the two lines at the bottom of the script to allow it to append to the end of the message, and it is appending the "Skipped command" to the end, so the if statement is false.

At the beginning of the script where the variable "devices" is declared, shouldn't it be collecting the triggering rather than scene devices - this script should not care about scene devices, right?

Thanks,

Joe

Ryan-Scott posted this 21 March 2015

Hi Ryan,

I downloaded the 4.0 version you linked here and it still delivers a message without any device names. I uncommented the two lines at the bottom of the script to allow it to append to the end of the message, and it is appending the "Skipped command" to the end, so the if statement is false.

At the beginning of the script where the variable "devices" is declared, shouldn't it be collecting the triggering rather than scene devices - this script should not care about scene devices, right?

Thanks,

Joe


The way the script works, is that it loops through all scene devices. If the scene device being looped over is the one that did the trigger (triggerMetaData.triggeringDevice.deviceId), then it'll print out information about it. Really though, there will only ever be a single device that triggers a scene, so the loop is just extra work... I've modified the prior gist script to remove the loop.

Since you are not seeing any message, maybe it's something related to your triggers. Can you provide a screen shot or a detail explanation of how they are setup?

joe6602 posted this 21 March 2015

Oh, I didn't realize that sceneDevices included ALL devices. This new script works, BUT strangely, it does not pick up a DeviceType, and therefore takes the default path on the switch command.

joe6602 posted this 23 March 2015

Ryan,

I have an Aeon Labs recessed door sensor as my trigger. I previously was using a virtual device, but I included/associated the sensor to use as an actual input device. I have the scene triggered on the door open of the sensor. I then have the script declared in the pre-script of one device, a light on my garage, to emulate a "siren". The light actuates when the scene runs, but I am just getting the weird behavior of the two scripts you provided.

The first script, provided by you, is the one that loops through all devices. The if statement is false, and the script goes to the "skipped command" report line.

The other script you provided was reporting the triggering device, but not the actual device state, only the binary representation thereof. Now that I have an actual input device, it does declare it to be "Open". I guess that's a success, but I would like to solve the mystery of the first script. I know you are busy, however. If you think of anything else, let me know.

Thanks again for all the effort.

Joe

Ryan-Scott posted this 23 March 2015

Thinking more on this it occurs to me that the first script requires you add your triggering device to the list of devices in your scene, then use the "gear" icon to make sure it's not getting changed with the scene activation.

joe6602 posted this 24 March 2015

Ryan,

Yep, that was it. It works correctly now. Thanks for the support!

Joe

joe6602 posted this 24 March 2015

By the way, with this new version you sent me a link for on Saturday, I am getting the following error repeatedly in the logfile:

3/24/2015 4:02:50 PM: MC: Unprocessed command: 37, 3, 0

Is this something I can turn off, or do I need to adjust something?

Thanks,

Joe

Close