Rules vs Scene

  • 54 Views
  • Last Post 03 May 2014
NickTT posted this 02 May 2014

Since rules are going away, how do you do an email notification with the triggered device names like you can with rules? I tried to have a scene trigger when my kids door opens at night to warn me that they are roaming around but nothing ever happened. I did the same thing with a rule and it worked perfect every time. We just moved one to a toddler bed and we don't think she is going to stay in her room.


This is the script:
[code]

using System;
using System.Collections.Generic;
using System.Text;
using MLS.ZWave.Service.Rules;
using MLS.ZWave.BusinessObjects;

///


/// This script will send an email about the device's current state.
///
/// ALWAYS MAKE COPIES OF SCRIPTS YOU INTEND TO CUSTOMIZE OR YOUR CHANGES
/// COULD BE LOST.
///

public class EmailCurrentDeviceState : ScriptBase, ScriptInterface {

public void runScript() {
try {

/******************
* These are safe to change.
* {0} will be the node name.
* {1} will be either off/on
* {2} will be the level
*****************/
var subject = "Warning: {0} is {1}";
var body = "{0} is open. Possible jailbrake in progress!";

/
*****************
* Don't make changes beyond this point unless you are
* comfortable with programming.
******************/
if (targetNodes == null || targetNodes.Count == 0) {
writeLog("NodeIds is required Rule Data. Rule will not run.");
return;
}

// Get all devices supplied in NodeIds rule data
var devices = getNodes(targetNodes);

// All nodes will trigger an email
foreach (var d in devices) {
sendEmail(string.Format(subject, d.deviceName, d.level == 0 ? "closed" : "open", d.level), string.Format(body, d.deviceName, d.level == 0 ? "closed" : "open", d.level));
}

} catch (Exception ex) {
// Log the exception here
var message = ex.Message;
writeLog(message);
}
}
}

[/code]

Order By: Standard | Newest | Votes
Ryan-Scott posted this 03 May 2014

Since rules are going away, how do you do an email notification with the triggered device names like you can with rules? I tried to have a scene trigger when my kids door opens at night to warn me that they are roaming around but nothing ever happened. I did the same thing with a rule and it worked perfect every time. We just moved one to a toddler bed and we don't think she is going to stay in her room.


You could use the "EmailSceneStatusReport" script. Be sure to add the device to your scene then click the "Gear" and specify "No Change" (otherwise InControl will attempt to change the status of the device as part of the scene activation.)

Optionally, you could create a script that simply sends you a custom message with no device status:


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 EmailAMessage : ScriptBase, ScriptInterface {
public void runScript() {
try {
try {
sendEmail("Opened", "The door has been opened");
} finally {

}
} catch (Exception ex) {
// Log the exception here
}
}
}

NickTT posted this 03 May 2014

You could use the "EmailSceneStatusReport" script. Be sure to add the device to your scene then click the "Gear" and specify "No Change" (otherwise InControl will attempt to change the status of the device as part of the scene activation.)


Do you then call the script in a Post script? I [b]want[/b] device notifications to work as a token like they do in a rule. I also have a virtual device lock called "In Bed". I use a condition to only trigger the alert if this is set to "Locked". If I then click "Activate" for the scene should it work as a "Test" and send an email so I know it's working correctly?

Ryan-Scott posted this 03 May 2014


Do you then call the script in a Post script? I [b]want[/b] device notifications to work as a token like they do in a rule. I also have a virtual device lock called "In Bed". I use a condition to only trigger the alert if this is set to "Locked". If I then click "Activate" for the scene should it work as a "Test" and send an email so I know it's working correctly?


Yeah, manually activating a scene will send you an email. If you put the script in "Pre" then it will run before any of the scene device changes run. If you put it in post, it'll run after the scene devices do their thing.

NickTT posted this 03 May 2014

Ok... so say I want to know if a door or window is left open at 10PM. I would create a new Scene, schedule it to run every day at 10pm, Put all the door and window sensors in the device list, configure them all to not change state with the little gear, set the email script (with tokens) to run at "Pre"... now this is where I get confused. How do I have it email me only if 1 of 10 windows are left open?

Ryan-Scott posted this 03 May 2014

You can add them as conditions to your scene. Take a look at the Garage Door tutorial for a good idea of how it would work.

Close