more G-Labs products

Author Topic: How to triger notification vie email.  (Read 2554 times)

October 15, 2014, 01:26:08 PM
Read 2554 times

genieman

  • *
  • Information
  • Newbie
  • Posts: 3
Hello again. I would like to know how to configure send email when my sensor DHT-11 notice temperature over 38 degrees ? Any instruction ?

October 17, 2014, 12:08:48 AM
Reply #1

gustavoringler

  • *
  • Information
  • Newbie
  • Posts: 8
I am a Home Automation "enthusiast"...but not a programmer.. :-(
I have the same need as the one expressed in the previous post...
It would be great if somebody could bring together a brief set of instructions on what has to be done in order to have HG send an email when some condition happens...
Thanks in advance !

October 17, 2014, 10:24:26 AM
Reply #2

mvdarend

  • *****
  • Information
  • Hero Member
  • Posts: 431
Hi,

Here's an example in C#, You might need to change some things here, but the basics should work, I hope... :)

Put this in your trigger code:

Code: [Select]
// Remember to Change 'SensorName' to the correct name of your sensor
var mySensor = Modules.WithName("SensorName").Get();

// Debug code
//Program.Notify("Debug", mySensor.Parameter("Sensor.Generic").DecimalValue.ToString())

// Returns 'True' if the value of the sensor is 38 or higher
return (mySensor.WasFound && mySensor.Parameter("Sensor.Generic").DecimalValue >= 38);

And this in the 'Code to run'

Code: [Select]
var mySensorValue = Modules.WithName("SensorName").Get().Parameter("Sensor.Generic").DecimalValue.ToString();

Net.SendMessage("[email protected]", "Sensor", "Sensor value is " + mySensorValue );

Edit: Don't forget to set the trigger to "When condition evaluation switches to 'true'" or you'll get a lot of mail as bkenobi mentions below.

HTH, Marcel.
« Last Edit: October 18, 2014, 07:39:37 AM by mvdarend »

October 17, 2014, 07:19:04 PM
Reply #3

bkenobi

  • *****
  • Information
  • Global Moderator
  • Posts: 1525
Two comments.

1) This code will run constantly when the temperature on the sensor is above 38.  That will result in sending countless emails.  Be careful if you use this code without adding a delay in the trigger section like "pause(60)" for 60 second intervals.

2) In order for email to send, you must set up the email setup code.  That requires you to enter an SMTP server location and necessary login details.  I'd recommend sending a test email prior to setting up and running the previous code so you know that email itself works.

October 17, 2014, 07:24:40 PM
Reply #4

mvdarend

  • *****
  • Information
  • Hero Member
  • Posts: 431
Quote
This code will run constantly when the temperature on the sensor is above 38
That depends on the 'Trigger'. If you leave it at 'When condition evaluation returns 'true'" it will run continuously, but if you set it to "When condition evaluation switches to 'true'" it will run once.

October 17, 2014, 11:21:08 PM
Reply #5

bkenobi

  • *****
  • Information
  • Global Moderator
  • Posts: 1525
That depends on the 'Trigger'. If you leave it at 'When condition evaluation returns 'true'" it will run continuously, but if you set it to "When condition evaluation switches to 'true'" it will run once.
Good point.

November 19, 2014, 08:51:46 PM
Reply #6

Bitcraze

  • ***
  • Information
  • Full Member
  • Posts: 73
Hi,

Where would I find the exact name to replace for "SensorName"?

I would like to use my DS18B20 that is called "Main Bedroom" in the Dashboard.

Thanks,

Eugene

November 19, 2014, 08:57:28 PM
Reply #7

mvdarend

  • *****
  • Information
  • Hero Member
  • Posts: 431
'SensorName' needs to replaced with the name you gave to the module, so in your case, replace it with 'Main Bedroom'.

(Name is case-sensitive I think)
« Last Edit: November 19, 2014, 09:14:58 PM by mvdarend »