email updates

Anyone have software already written to send temperature monitor updates to an email address when it falls outside a specific temperature range? (I could write this myself but would love it if someone else already has a solution and can save me some time)

There is a smtp presentation in src/presentations/smtp. The comments explain using a transform device to create a conditional value for sending the email.

"The generic intention of the email presentation is to be used with the
transform device. Use the transform device to perform a calculation or a group
of comparisons. For example:

expr = ‘(condition1) and (condition2) and (condition3)’

If those three conditions are met, the transform device channel will be
evaluated as true and an email message will be queued, provided the SMTP
presentation was configured to monitor the transform device."

Of course, you can’t just use the condition “If temperature is greater than 32.0 Deg C, send email” since this condition will be true repeatedly. So if you read the temperature every 5 minutes, you’ll need a method to not resend the email every 5 minutes.

Just working on a method to allow first alert to fire email then stop. Is it possible to access a ‘last email sent’ timestamp or (as I’m using a pin change detect event to drive it) a ‘last sample timestamp’ that is held in the channel that can be used to evaluate against?
Or maybe I should be creating a log and parsing through it?
Any help or pointers much appreciated.

Personally, I would just create a simple custom 'device" instead of using a transform. You can learn about “channel subscriptions” here:
http://www.digi.com/wiki/developer/index.php/Subscribing_to_a_Channel

Then subscribe to the Digital event (the output channel). Your code runs EVERY TIME the digital event is updated - literally, your callback runs as a ‘subroutine’ of the act of updating the subscribed channel.

Then it is trivial to add your own logic - for example only allow 1 email per hour. An output from your custom driver would then trigger the email. Your code could even be smart enough to trigger different email on weekends vs weekday and so on.

If you want to add “cyclic time sense” you could make it a thread, or just use my “Tick-Tock” device, which can cause your device to run once per minute or hour or day etc by subscribing to a channel.
http://www.digi.com/wiki/developer/index.php/Dia_Device_-_Alarm_Clock
Or edit my tick-tock to be your email sender & you gain a thread.

Looks perfect. I have run through the code example but running into a problem with the subscriber code (and my python is poor but improving!)
I have tried to adapt the template_device code to include your subscriber code but not happening - could you include the counter_device.py file in the download link on the http://www.digi.com/wiki/developer/index.php/Subscribing_to_a_Channel page?
Many thanks.

I have too many custom objects in there - it is part of a concept of stacked blocks to handle scaling, alarms, averaging etc in a data flow system. You could send me an email - use your imagination as to how to send an email to me if I were at digi.com :slight_smile:

I would start playing with this on a PC, so remove any Xbee device and get my alarm clock to run on a PC and print out the “time is now” messages by adding the settings to your alarm clock
settings:
printf: minute

Then try to have your email routine triggered once per minute - it could just say “I am triggered”. So get your system to send an email from a PC once per minute before your try to get it working on a gateway. That is the beauty of this Dia/Python system; keep your gateway dependent code (the xbee_device modules) as simple as possible and then you can test the rest of your code on a PC.

Another hint in working with Python - one should document, right? So I just put a nice “print” statement into every if/the/else clause, then just comment it out once that code section works. If needed I can restore the print later, but it acts as documentation & debug help.