more G-Labs products

Author Topic: Aeon Door/Window sensor - Trigger code [Solved]  (Read 3376 times)

February 07, 2014, 05:23:41 PM
Read 3376 times

duch

  • *
  • Information
  • Newbie
  • Posts: 20
Hello,

First of all, I am not familiar at all with C# and have no time to spend to understand how it works.

Here is my problem :

I want to receive an email when my Aeon Door/window sensor equals 255 (when the door is opened)

I have found an exemple of the Code to run in the Sourceforge Homegenie forum

Code: [Select]
// send email
string smtpserver = "smtp.myserver.com";   
Net.MailService(smtpserver).WithCredentials("myuser", "mypass")
    .SendMessage("[email protected]",           //from
    "[email protected];[email protected]",   // recipients
    "Warning",                          // subject
    "Security Alarm Triggered");        // message text

Could you help me for writting the trigger code please ?

Thank you for your help
« Last Edit: April 08, 2014, 05:23:04 PM by duch »

February 08, 2014, 01:38:17 AM
Reply #1

Gene

  • *****
  • Information
  • Administrator
  • Posts: 1472
  • Tangible is the future!
    • Yet Another Programmer
Code: [Select]

// trigger code
return Modules.InGroup("Living Room")
             .WithName("Door Sensor").Get() // get reference to the selected module
             .Parameter("Sensor.DoorWindow").DecimalValue == 255;


just change the group and the module name.

Though I would encourage you in using the built-in Security Alarm System feature:

http://www.homegenie.it/docs/alarmsystem.php

The first screenshot is from an older HG release and the e-mail configuration has been moved to the Configure->Automation->Messaging and Social section.

If you still want to use a custom C# app and you configured e-mail from Messaging and Social, you can simplify the email send command to:

Code: [Select]

// send email
Net.SendMessage("[email protected];[email protected]",   // recipients
                "Warning",                          // subject
                "Security Alarm Triggered");        // message text


« Last Edit: February 08, 2014, 02:03:07 PM by Gene »

February 08, 2014, 12:38:48 PM
Reply #2

duch

  • *
  • Information
  • Newbie
  • Posts: 20
Thank U for your help and I will try the built-in Security Alarm System feature as soon as possible.

I've tried the trigger code you wrote. But unfortunately, I have got that message (in french) when I've tried to compile ...

Quote
Errors:
1. Line 4, Column 15 'HomeGenie.Automation.Scripting.ModulesManager' ne contient pas une definition pour 'Parameter' et aucune methode d'extension 'Parameter' acceptant un premier argument de type 'HomeGenie.Automation.Scripting.ModulesManager' n'a ete trouvee (une directive using ou une reference d'assembly est-elle manquante ?) (CS1061) (Condition)
Program disabled, fix errors first.

Here is the code I change with my parameters :

Code: [Select]
// trigger code
return Modules.InGroup("Salle de technologie")
             .WithName("Porte")
             .Parameter("Sensor.DoorWindow").DecimalValue == 255;

Do I miss something ?

Merci

February 08, 2014, 02:01:59 PM
Reply #3

Gene

  • *****
  • Information
  • Administrator
  • Posts: 1472
  • Tangible is the future!
    • Yet Another Programmer
Sorry!! it was me missing something  ;D

Code: [Select]

// trigger code
return Modules.InGroup("Salle de technologie")
             .WithName("Porte").Get()                         // <--- get reference to the selected module
             .Parameter("Sensor.DoorWindow").DecimalValue == 255;


or to make it more readable

Code: [Select]

var doorsensor = Modules.InGroup("Salle de technologie").WithName("Porte").Get();
return doorsensor.Parameter("Sensor.DoorWindow").DecimalValue == 255;


« Last Edit: February 08, 2014, 02:14:47 PM by Gene »

February 08, 2014, 03:59:33 PM
Reply #4

duch

  • *
  • Information
  • Newbie
  • Posts: 20
Wonderfull ...  :)

It's working fine now !

Thank you for your fantastic job....

March 05, 2014, 11:34:05 AM
Reply #5

duch

  • *
  • Information
  • Newbie
  • Posts: 20
Hello,

I've updated HG with r345

Since, I have a problem for sendig an email.

In the "Code to run" window, i have now to fix some errors ...

Quote
Errors:
1. La reference d'objet n'est pas definie e une instance d'un objet.
2. e HomeGenie.Automation.Scripting.ScriptingInstance.EvaluateConditionScript()
3. e HomeGenie.Automation.Scripting.ScriptingInstance.EvaluateCondition()
Program disabled, fix errors first.

Can you Help me ?

Thank you


Solved :  :) I have done a new installation, and it works now
« Last Edit: April 08, 2014, 05:24:35 PM by duch »