I found this approach worked but I am putting all of my operational code in the Startup Code section.
It seems like I should be putting some of this in the Program Code section.
However, I guess if it works, it works.
I originally had the email sending portion of the code below in the Program Code section but I couldn't get it to run - ever.
I even added the Program.Run() command to the Startup Code but it would not seem to invoke the Program Code section.
So, anyway, for what it's worth, here you go and I hope it is helpful to you.
You can just replace the email section with whatever it is you want to do.
In my case it was email me when a switch changed status to "1" (open).
Good luck!
When.ModuleParameterChanged( (module, parameter) =>
{
if (module.Is("Test Sensor") && parameter.Is("Status.Level")) // If my Test Sensor had a status change...
{
if( module.Parameter("Status.Level").Value == "1" ) // and if it changed to a "1" meaning it opened...
{
Program.Notify("Test Sensor", "Triggered"); // then do all this stuff.... pop up a msg and send an email
string smtpserver = "smtp.your_email_server.com";
Net.MailService(smtpserver,587,false).WithCredentials("
your_email@your_site.com", "your_email_password")
.SendMessage("your_email_address", //from
"email_recipient_address", // recipients
"Your_subject_for_the_msg", // subject
"Message_text"); // message text
Program.Run(); // I tried to use this to run the Program Code section of this program - but it didn't seem to work - a notification I had there never ran
return false; // I'm not sure what returning false vs. true does for you. It didn't seem to make any difference in this code.
}
return true;
}
return true;
});