Last week to Enter the Spike Brewing 20 Gallon Sight Glass Kettle Giveaway!



Home Brew Forums > Home Brewing Beer > DIY Projects > Fermenters > How To: Setup Email Alerts on BrewPi
Reply
 
LinkBack Thread Tools
Old 01-14-2015, 02:33 PM   #1
LostPhoenix
Feedback Score: 0 reviews
Recipes 
 
Join Date: May 2014
Posts: 7
Liked 1 Times on 1 Posts
Likes Given: 2

Default How To: Setup Email Alerts on BrewPi

Hello everyone,

I recently setup a BrewPi using FuzzyWuzzy's post, and have been pretty happy with it. However, I was worried about if one of the relays failed. So I wrote a simple bash script to email me if the fermentation temp gets too high far the set point. I thought some of you might be interested in it.

First thing we need to do is setup the rPi to send emails. I decided to use SMTP Mail.

First connect to your rPi via SSH.

Loading Packages

Code:
sudo apt-get install ssmtp 
sudo apt-get install mailutils
sudo apt-get install mpack
This will take a few minutes. Answer Y to any prompts.

Setting up Default SMTP Settings
Code:
sudo nano /etc/ssmtp/ssmtp.conf
Make the following changes to the fields. If you can't find one of the fields add it to the bottom. I use GMail for this. If you don't use gmail you may need a different STMP address.
Code:
AuthUser=youruserid@gmail.com
AuthPass=userpass
FromLineOverride=YES
mailhub=smtp.gmail.com:587
UseSTARTTLS=YES
When you are finished, press control+o to save. Then control+x to close nano.

Let's test to make sure this is setup properly
In the terminal type paste this
Code:
echo "sample text" | mail -s "Subject" YourEmail@YourDomain.tld
This should take a few seconds to execute, but you should get the email pretty much instantly if you're sending to a gmail account.

Great! Email Works, let's setup alerts
Let's use nano again to setup the Bash Script we're going to use.
Code:
nano /home/pi/brewCheck.sh
Now we will paste the contents of my bash script into nano.
Code:
#!/bin/bash

#Config
YourEmail=YourUser@YourDomain.tld #Set to your email address
AlertAt=3.5 #Threshold for alert. Difference in degree of wort from set temp before alert

function jsonValue() {
KEY=$1
num=$2
awk -F"[,:}]" '{for(i=1;i<=NF;i++){if($i~/\042'$KEY'\042/){print $(i+1)}}}' | tr -d '"' | sed -n ${num}p
}

curl --data "messageType=refreshControlVariables&message=" http://127.0.0.1/socketmessage.php
Diff=$(curl --data "messageType=getControlVariables" http://127.0.0.1/socketmessage.php | jsonValue beerDiff 1)

if [[ $Diff > $AlertAt ]]; then
  echo "BrewPi Needs Help;  BeerDiff is $Diff" | mail -s "BrewPi Needs Help" $YourEmail
fi
Once again press control+O to save, and control+X to close.

Almost done! Now we just need make the script executable and setup the cronjob!

Don't forget to make the script executable!
Code:
chmod +x brewCheck.sh
Lastly, Setup the cronjob!
I have my script checking every 15 minutes. If you want to have yours check more frequently just adjust the */15 to */Number_of_Minutes_between_checks

First let's open crontab
Code:
crontab -e
Scroll down to the very bottom and add this line
Code:
*/15 * * * * /home/pi/brewCheck.sh >/dev/null 2>&1
Press control+O to save, and control+X to close.

crontab should report
Code:
crontab: installing new crontab
Congrats! You will now receive email alerts if your wort gets beyond the temp threshold!

If there are any other circumstances you might want an alter for please let me know. I am new to the fermentation chamber game, and would be happy to update the script.
__________________
LostPhoenix is offline
Mikmonken Likes This 
Reply With Quote Quick reply to this message
Old 01-14-2015, 02:34 PM   #2
LostPhoenix
Feedback Score: 0 reviews
Recipes 
 
Join Date: May 2014
Posts: 7
Liked 1 Times on 1 Posts
Likes Given: 2

Default

Reserved for change log

__________________
LostPhoenix is offline
 
Reply With Quote Quick reply to this message
Old 01-14-2015, 03:49 PM   #3
ds0oc1
Feedback Score: 0 reviews
Recipes 
 
Join Date: May 2014
Posts: 54
Liked 4 Times on 4 Posts
Likes Given: 3

Default

Great post - I'll be playing with this over the weekend.

__________________
ds0oc1 is offline
LostPhoenix Likes This 
Reply With Quote Quick reply to this message
Old 01-16-2015, 02:09 PM   #4
Mikmonken
Feedback Score: 0 reviews
Recipes 
 
Join Date: Mar 2013
Posts: 79
Liked 3 Times on 3 Posts
Likes Given: 9

Default

this is great, i had tried to follow other automated email process and couldn't get any to work, this seems to do the trick perfectly!

Just a quick issue i found, if using gmail and you have app passwords activated, the password you use is the one that is generated and not your normal login (that had me confused for a bit as kept getting this error.

"send-mail: Authorization failed (535 5.7.8 http://support.google.com/mail/bin/a...y?answer=14257 j10sm6152775wjn.23 - gsmtp)"

In terms of notifications that following would be great for me.

- brewpi profile has started - sometimes i put my beer in the fridge and then have the brewpi kick in at midnight, theres no reason really other than weird OCD
- Notification when beer temp is set to change
- Notification when a fermentation profile has ended?

I'm not sure if any of these are possible to add in though?

__________________
Mikmonken is offline
 
Reply With Quote Quick reply to this message
Old 01-18-2015, 05:40 PM   #5
LostPhoenix
Feedback Score: 0 reviews
Recipes 
 
Join Date: May 2014
Posts: 7
Liked 1 Times on 1 Posts
Likes Given: 2

Default

Quote:
Originally Posted by Mikmonken View Post
this is great, i had tried to follow other automated email process and couldn't get any to work, this seems to do the trick perfectly!

Just a quick issue i found, if using gmail and you have app passwords activated, the password you use is the one that is generated and not your normal login (that had me confused for a bit as kept getting this error.

"send-mail: Authorization failed (535 5.7.8 http://support.google.com/mail/bin/a...y?answer=14257 j10sm6152775wjn.23 - gsmtp)"

In terms of notifications that following would be great for me.

- brewpi profile has started - sometimes i put my beer in the fridge and then have the brewpi kick in at midnight, theres no reason really other than weird OCD
- Notification when beer temp is set to change
- Notification when a fermentation profile has ended?

I'm not sure if any of these are possible to add in though?
Thanks for the heads up with app specific passwords. I didn't think to include that info.

I will explore what info I can get from the brewpi from the limited APIs for the other alerts.
__________________
LostPhoenix is offline
 
Reply With Quote Quick reply to this message
Reply



Quick Reply
Message:
Options
Thread Tools


Similar Threads
Thread Thread Starter Forum Replies Last Post
How To: BrewPi LCD Add-On day_trippr Fermenters 159 02-27-2015 08:15 PM
Brewpi question Eric_S Fermenters 2 10-24-2014 10:04 PM
TeensyNet vs. BrewPi sdgenxr Fermenters 1 05-01-2014 02:47 AM
BrewPi jvp1 General Beer Discussion 8 04-14-2014 10:47 PM
Does HBT send email alerts for PMs? ISP Blocked possibly? bottle-o-jeff HomeBrewTalk Announcements & Feedback 2 02-17-2009 12:54 PM



Newest Threads

LATEST SPONSOR DEALS