Email Script Help

Started by mike, February 18, 2019, 08:30:43 PM

Previous topic - Next topic

mike

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?

bkenobi

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

#2
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. ;)
Please Read Topic:
General Forum Etiquette
Before you post!

Tuicemen

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.
Please Read Topic:
General Forum Etiquette
Before you post!

mike

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...

Tuicemen

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.
Please Read Topic:
General Forum Etiquette
Before you post!

mike

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...

bkenobi

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

#8
Quote from: bkenobi 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.

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    (:


mike

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.

mike

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.

bkenobi

Quote from: mike on February 19, 2019, 12:11:41 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

#12
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?

Tuicemen

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.
Please Read Topic:
General Forum Etiquette
Before you post!

mike

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