Please login or register.

Login with username, password and session length
Pages: [1] 2 3 ... 5

Author Topic: Email Script Help  (Read 13719 times)

mike

  • Hero Member
  • *****
  • Helpful Post Rating: 14
  • Posts: 1057
Email Script Help
« on: February 18, 2019, 08:30:43 PM »

Can I ask for help here or should I ask in another spot?

sending email when sensor triggers fails - says it is old HG C+ code:

//Parameters
Program.Setup(()=>
{             
    Program.AddInputField("Sensor", "garage", "Sensors to alert on (comma separated)"); //e.g.: garage,window1
    Program.AddInputField("Email.Recipients", "a@a.com", "Email recipients");         //e.g.: a@a.com,b@a.com
}); 

//Code that executes on sensor changes:
When.ModuleParameterChanged((module, parameter)=> {
  if( parameter.Name == "Sensor.Generic")
  {
   if(Program.InputField("Sensor").Value.Contains(module.Instance.Name))
    {     
      Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US");
      DateTime time = DateTime.Now;
     string format = "HH:mm MMM ddd d";
     
      var openClosed = parameter.DecimalValue == 0 ? "closed":"open";
      var messagetext = module.Instance.Name + " " + openClosed + time.ToString(format);
      //Program.Notify("debug", "sending email " + messagetext); //uncomment for debugging
      var subject = "HomeGenie: Open/Closed" + messagetext;
      var recipients = Program.InputField("Email.Recipients").Value;
      if (recipients != "")
      {
        Program.RunAsyncTask(()=>{
          Net.SendMessage(recipients, subject, messagetext);
        });
      }
   }
  }
  return true;
});


Error says:

CR,4,13: `HomeGenie.Automation.Scripting.ProgramHelper.AddInputField(string, string, string)' is obsolete: `use 'Program.AddOption(<field>, <defaultValue>, <description>, <type>)' instead'
200 /hg/html/pages/control/widgets/homegenie/generic/doorwindow.html [OPEN]
CR,5,13: `HomeGenie.Automation.Scripting.ProgramHelper.AddInputField(string, string, string)' is obsolete: `use 'Program.AddOption(<field>, <defaultValue>, <description>, <type>)' instead'
CR,12,13: `HomeGenie.Automation.Scripting.ProgramHelper.InputField(string)' is obsolete: `use 'Program.Option' instead'
CR,22,32: `HomeGenie.Automation.Scripting.ProgramHelper.InputField(string)' is obsolete: `use 'Program.Option' instead'


I've tried replacing but it is still missing something...   If someone can update this for me I would post it back as exmple for HG?
Logged

bkenobi

  • PI Expert
  • Hero Member
  • ******
  • Helpful Post Rating: 24
  • Posts: 2082
Re: Email Script Help
« Reply #1 on: February 18, 2019, 10:29:37 PM »

When I have programming questions, I always start with the documentation on the function.  Hopefully the link will work...

https://genielabs.github.io/HomeGenie/api/ape/a00010.html#a77342214dc230ce4eab47ffc4c10bd7f

Tuicemen

  • Administrator
  • Hero Member
  • ****
  • Helpful Post Rating: 283
  • Posts: 10509
  • I don't work for X10, I use it successfuly!
Re: Email Script Help
« Reply #2 on: February 19, 2019, 07:18:05 AM »

It is always best when going off topic with a Question to start another thread with a topic header that reflects your question. That way your question is less likely to be ignored or over looked. ;)
« Last Edit: February 19, 2019, 07:21:03 AM by Tuicemen »
Logged
Please Read Topic:
General Forum Etiquette
Before you post!

Tuicemen

  • Administrator
  • Hero Member
  • ****
  • Helpful Post Rating: 283
  • Posts: 10509
  • I don't work for X10, I use it successfuly!
Re: Email Script Help
« Reply #3 on: February 19, 2019, 08:49:39 AM »

This code is simular to what is included in the release versions of the PiX10Hub (E-mail GarageDoor Notification) I thought I had posted it in the beta section But can't seem to locate it.
The difference is I don't have it watching specific modules and don't add a date stamp to the email.
I get warnings but no errors on compiling.
Logged
Please Read Topic:
General Forum Etiquette
Before you post!

mike

  • Hero Member
  • *****
  • Helpful Post Rating: 14
  • Posts: 1057
Re: Email Script Help
« Reply #4 on: February 19, 2019, 09:46:26 AM »

If you get a moment, would  you mind posting a copy of your code for email notification?  I can compare the two, study bkenobi's github link on help below, and get a working model maybe...
Logged

Tuicemen

  • Administrator
  • Hero Member
  • ****
  • Helpful Post Rating: 283
  • Posts: 10509
  • I don't work for X10, I use it successfuly!
Re: Email Script Help
« Reply #5 on: February 19, 2019, 10:24:16 AM »

Here is the GarageDoor e-mail sample that is included in the piX10Hub image
Rename to 1004-E-Mail_GarageDoor_Notification.hgx then import to the messaging and social programs section you can then open and edit it  how you see fit.
Logged
Please Read Topic:
General Forum Etiquette
Before you post!

mike

  • Hero Member
  • *****
  • Helpful Post Rating: 14
  • Posts: 1057
Re: Email Script Help
« Reply #6 on: February 19, 2019, 11:02:17 AM »

Thanks.  I got my version maybe fixed;  when it compiles it says successful now.  but I am not sure how to run it!  haha!  double clicking on it in programs list just opens it to edit it...  maybe I need to find it in the list of modules and add it to a page...
Logged

bkenobi

  • PI Expert
  • Hero Member
  • ******
  • Helpful Post Rating: 24
  • Posts: 2082
Re: Email Script Help
« Reply #7 on: February 19, 2019, 11:16:13 AM »

You need to set up the app before it will work. You need to define the sensor and email.recipients fields and also make sure the app is enabled (green or yellow icon).  If it has a bright red or dark red icon, the app is not going to work as it has a problem.

mike

  • Hero Member
  • *****
  • Helpful Post Rating: 14
  • Posts: 1057
Re: Email Script Help
« Reply #8 on: February 19, 2019, 11:37:08 AM »

You need to set up the app before it will work. You need to define the sensor and email.recipients fields and also make sure the app is enabled (green or yellow icon).  If it has a bright red or dark red icon, the app is not going to work as it has a problem.

Tuicemens indeed ran (yell went green for 1 second) and HG said missing email recipient...

Mine goes yell to green 0.1sec and no report from HG...

I knew I had to give address but youtube showed entering it by clicking on the program;  that does not work. 

I just found a little 'options' button in the program summary page on Tuicemens...  bingo!  that is where to enter the AddInputField

Mine does not give such an option box for my AddOption    (:

« Last Edit: February 19, 2019, 11:38:52 AM by mike »
Logged

mike

  • Hero Member
  • *****
  • Helpful Post Rating: 14
  • Posts: 1057
Re: Email Script Help
« Reply #9 on: February 19, 2019, 11:52:10 AM »

why can Tuicemn use 'obsolete' program fields but I cannot??

My program would not compile using the SAME fields he used!@#@!$#GR!

// CR,5,13: `HomeGenie.Automation.Scripting.ProgramHelper.AddInputField(string, string, string)' is obsolete: `use 'Program.AddOption(<field>, <defaultValue>, <description>, <type>)' instead'
// CR,12,13: `HomeGenie.Automation.Scripting.ProgramHelper.InputField(string)' is obsolete: `use 'Program.Option' instead'
// CR,22,32: `HomeGenie.Automation.Scripting.ProgramHelper.InputField(string)' is obsolete: `use 'Program.Option' instead'

bottomline:  his works, mine does not.
Logged

mike

  • Hero Member
  • *****
  • Helpful Post Rating: 14
  • Posts: 1057
Re: Email Script Help
« Reply #10 on: February 19, 2019, 12:11:41 PM »

so.  more studying on http://genielabs.github.io/HomeGenie/#/develop/programs

makes me keep my options instead of inputfields, but move the AddOptions to Startup tab in program instead...  add tuicemens widget line...  Now I too get Options choice in programs summary page screen.  I can enter email and which sensors to trigger on... 

doesn't work but at least I am making progress.
Logged

bkenobi

  • PI Expert
  • Hero Member
  • ******
  • Helpful Post Rating: 24
  • Posts: 2082
Re: Email Script Help
« Reply #11 on: February 19, 2019, 12:25:33 PM »

doesn't work but at least I am making progress.

What does the log say?  What do you mean "doesn't work"?  For the email to succeed, you must have your mono certificates up to date.  If you don't keep it up to date, the email notifications will stop working after a couple months from my experience.  Best practice may be to use a cron event to run update/upgrade regularly so that things keep working.  I have not done this, but it would be something to try.

mike

  • Hero Member
  • *****
  • Helpful Post Rating: 14
  • Posts: 1057
Re: Email Script Help
« Reply #12 on: February 19, 2019, 01:16:29 PM »

doesn't work meant it did nothing.  no yel to green flash.  Now they do that for .2 sec each but no email.  I am frustrated not being able to see the log file;  it is up to 25mb and downloads now in about 2 hours!  Ridiculously slow!

copying log file to my harddrive:  2kb/sec

Frustrating also that the locked up HG windows delays are back.  Have to refresh web browser about every 5th window change...

Wireshark shows little traffic from the pi so it is not something using all the bandwidth.

I am going to delete the log file and see if it starts a new small one...    nope.   copied small log file back to directory, try that..  ya, it downloads it now but it is still empty.  guess one is not allowed to delete the homegenie.log file.  oh well, seems I broke my system;  guess I am going to have to plug in my AHP cm15 again.

meanwhile, perhaps my SD card is dying causing the super slowness?
« Last Edit: February 19, 2019, 01:52:52 PM by mike »
Logged

Tuicemen

  • Administrator
  • Hero Member
  • ****
  • Helpful Post Rating: 283
  • Posts: 10509
  • I don't work for X10, I use it successfuly!
Re: Email Script Help
« Reply #13 on: February 19, 2019, 01:56:59 PM »

To flush your log file turn it off then after a bit turn it back on.
Also when creating a program if it is messed up and you activate it it will slow things down considerably as it tries to implement things in the code.
Logged
Please Read Topic:
General Forum Etiquette
Before you post!

mike

  • Hero Member
  • *****
  • Helpful Post Rating: 14
  • Posts: 1057
Re: Email Script Help
« Reply #14 on: February 19, 2019, 02:00:10 PM »

thanks for the log off then back on, I did not think of that.  I am restoring from yesterday's backup...  It may be Kenobi's activity monitor as I imported it but it does not show up anywhere...  if my restore from yesterday gets me speeded up again, I will try once more to build email programs...   thanks
Logged
Pages: [1] 2 3 ... 5
 

X10.com | About X10 | X10 Security Systems | Cameras| Package Deals
© Copyright 2014-2016 X10.com All rights reserved.