rszimm / sprinklers_pi

Sprinkling System Control Program for the Raspberry Pi
GNU General Public License v2.0
310 stars 100 forks source link

Cycle Complete Notification #140

Closed jefedeestado closed 5 years ago

jefedeestado commented 5 years ago

First, a huge thanks to all those that keep supporting this! @nhorvath for getting the new weather providers up and running!

But here's a feature I'd love to see. An on/off option to add an email address to receive notification email when a cycle has completed with a quick summary of which zones ran and for how long and the weather adjustment.

Heres why: Last summer was really dry and really hot where I live. I knew the water bill was going to be high. I just let the pi keep chugging and do its thing without even thinking about it. But it wasn't until late fall that I found out something had gone wrong as my water bills were crazy high. I only get a bill every other month so I didn't know what the real water usage was. After a bit of digging I figured out that the power supply for my pi was going bad. It put out enough current to keep the pi running, but not enough to get the USB wireless dongle powered up. It kept trying to get on the wifi but would drop and wouldn't connect to the internet. So when the sprinklers ran it wouldn't get weather data and (I believe) it defaulted to running the full cycle. In Seattle it's only really hot for a couple weeks, so I don't hit 100% very often and assumed it was still running normal only to find out that I was overwatering for months.

So wondering if it would be possible to have it send me a quick note to say that it ran and how long so I can keep an eye on things like that. I'm sure not everyone would like to get daily notifications, so make it optional.

I'm pretty code illiterate, but I might maybe be able to add a couple lines of code without the front end option. But I have no idea which file it should be added to. Any help would be appreciated.

nhorvath commented 5 years ago

Take a look at https://github.com/rszimm/sprinklers_pi/blob/master/scripts/report.sh I have that as a cron job on my mom's sprinkler system because she likes to have a summary.

jefedeestado commented 5 years ago

Awesome, I think that will do the trick. I think I'd rather that it gets called right after the sprinkler cycle is complete rather than a cron, but I know just enough make this run in cron. THANKS!

nhorvath commented 5 years ago

If you know approximately when your cycle should end just schedule cron to run it like an hour after that.

On Wed, May 8, 2019 at 4:10 PM jefedeestado notifications@github.com wrote:

Awesome, I think that will do the trick. I think I'd rather that it gets called right after the sprinkler cycle is complete rather than a cron, but I know just enough make this run in cron. THANKS!

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/rszimm/sprinklers_pi/issues/140#issuecomment-490632701, or mute the thread https://github.com/notifications/unsubscribe-auth/AABIJXE2THZH3ABWFH4AXD3PUMXSVANCNFSM4HLTBXVQ .

jefedeestado commented 5 years ago

Yeah, that should work just fine for me. I just ran it and it said 'mail program required to send email'. What's the preferred program?

nhorvath commented 5 years ago

sudo apt-get install heirloom-mailx ssmtp

to configure ssmtp to send mail with a gmail account your /etc/ssmtp/ssmtp.conf should look like this:

#
# Config file for sSMTP sendmail
#
# The person who gets all mail for userids < 1000
# Make this empty to disable rewriting.
root=yourusername@gmail.com

# The place where the mail goes. The actual machine name is required no
# MX records are consulted. Commonly mailhosts are named mail.domain.com
mailhub=smtp.gmail.com:587

# Where will the mail seem to come from?
#rewriteDomain=

# The full hostname
hostname=raspberrypi.local

# Are users allowed to set their own From: address?
# YES - Allow the user to specify their own From: address
# NO - Use the system generated From: address
FromLineOverride=YES

AuthUser=yourusername@gmail.com
AuthPass=redacted
UseSTARTTLS=YES

If you've got 2 factor auth enabled in your google account (and you should) you will need to generate an application password to use for AuthPass https://support.google.com/accounts/answer/185833?hl=en

jefedeestado commented 5 years ago

Fantastic, I'll give that a go tonight! Thanks again for keeping this (and my grass) alive!

jefedeestado commented 5 years ago

Got it working, but ran into a few hang ups. First it was giving me an error, sqlite3 command not found. So had to run

sudo apt-get install sqlite3

Thought that was a bit strange as I thought it was already installed considering everything else runs fine.

Then it was telling me that mail was not a good command. Did some digging and ran this:

sudo apt-get install ssmtp mailutils mpack

After setting up 2 factor and adding app passcode, I'm in business.

The last thing, how to get it to report in minutes rather than seconds? All my simple edits of adding /60 to the LOG variable didn't seem to work. Any hints?

nhorvath commented 5 years ago

Right above where it echos the log statement use calc like I do with the date stuff.

poiuztr123 commented 5 years ago

Great idea to get an email sent automatically.

Tried to implement it as well using the report.sh file. I had to install heirloom-mailx, bc, and sqlite3:

sudo apt-get install heirloom-mailx ssmtp sudo apt-get install bc
sudo apt-get install sqlite3

Running the report.sh file results in the follwing:

pi@sprinkler_pi:~/sprinklers_pi-1.4.0/scripts $ ./report.sh 96
(standard_in) 1: syntax error
(standard_in) 1: syntax error
(standard_in) 2: syntax error
Error: near " ": syntax error
./report.sh: line 54: [: -gt: unary operator expected
Sprinkler Report for 96 hours preceeding Thu 9 May 15:44:32 CEST 2019
No zones active for this time period.

My coding experience is limited. Any idea what that is? Thanks in advance.

nhorvath commented 5 years ago

sounds like something went wrong getting $ROWS from the database try adding echo $ROWS right after it is set to see what is in there. and echo $TIME right before it to make sure the time variable is set properly.

poiuztr123 commented 5 years ago

Ok. I have added two lines:

check if any zones ran

echo $TIME ROWS=sqlite3 $DB "SELECT COUNT(*) FROM zonelog WHERE date > $TIME" | tr -d '\n' echo $ROWS

Running report.sh results in:

pi@sprinkler_pi:~/sprinklers_pi-1.4.0/scripts $ ./report.sh 96
(standard_in) 1: syntax error
(standard_in) 1: syntax error
(standard_in) 2: syntax error

Error: near " ": syntax error

./report.sh: line 57: [: -gt: unary operator expected
Sprinkler Report for 96 hours preceeding Thu 9 May 16:12:59 CEST 2019
No zones active for this time period.

Looks like the variables are empty?

nhorvath commented 5 years ago

Yeah seems so. Ok I guess just give me the output of each of these on the command line: date +%s date +%z bc <<< "$(date +%z) / 100"

I'm thinking it has something to do with CEST being a + timezone causing a syntax error with bc.

On Thu, May 9, 2019 at 10:15 AM poiuztr123 notifications@github.com wrote:

Ok. I have added two lines:

check if any zones ran

echo $TIME ROWS=sqlite3 $DB "SELECT COUNT(*) FROM zonelog WHERE date > $TIME" | tr -d '\n' echo $ROWS

Running report.sh results in:

pi@sprinkler_pi:~/sprinklers_pi-1.4.0/scripts $ ./report.sh 96 (standard_in) 1: syntax error (standard_in) 1: syntax error (standard_in) 2: syntax error

Error: near " ": syntax error

./report.sh: line 57: [: -gt: unary operator expected Sprinkler Report for 96 hours preceeding Thu 9 May 16:12:59 CEST 2019 No zones active for this time period.

Looks like the variables are empty?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/rszimm/sprinklers_pi/issues/140#issuecomment-490923150, or mute the thread https://github.com/notifications/unsubscribe-auth/AABIJXGTVI62DBIUP2EQ3CTPUQWZNANCNFSM4HLTBXVQ .

poiuztr123 commented 5 years ago

The output is:

pi@sprinkler_pi:~/sprinklers_pi-1.4.0/scripts $ date +%s
1557412419                                                                                                                                                                             
pi@sprinkler_pi:~/sprinklers_pi-1.4.0/scripts $ date +%z
+0200                                                                                                                                                                                  
pi@sprinkler_pi:~/sprinklers_pi-1.4.0/scripts $ bc <<< "$(date +%z) / 100"
(standard_in) 1: syntax error
nhorvath commented 5 years ago

yeah. that's got to be the problem try changing

TIMEZONE=`calc $TIMEZONE / 100

to

TIMEZONE=`calc ${TIMEZONE/+/} / 100`

If it works i'll make the change permanent.

poiuztr123 commented 5 years ago

I think it worked. Perfect. Thanks. here is the output:

pi@sprinkler_pi:~/sprinklers_pi-1.4.0/scripts $ ./report.sh 96 1557074366
8
Sprinkler Report for 96 hours preceeding Thu 9 May 16:39:26 CEST 2019
Seasonal Adjustment: 100.0%
Weather Adjustment: 100.0%
Zone 1: 1407 seconds.
Zone 7: 1920 seconds.

nhorvath commented 5 years ago

Fixed the report file for + timezones and added some additional error checking for dependancies in https://github.com/rszimm/sprinklers_pi/releases/tag/v1.5.1 Also I switched the report to minutes by default, but if you prefer seconds you can set the variable at the top to 0.

ThomasDtz commented 2 years ago

I tried to install heirloom-mailx (sudo apt-get install heirloom-mailx) to use report.sh but got error message that that package is not available but referenced by another package. Any idea what to do? Thanks for any tip. Thomas

nhorvath commented 2 years ago

did you try the alternat instructions from report.sh?

sudo apt-get install ssmtp mailutils mpack

ThomasDtz commented 2 years ago

Yes - I installed mailutils and mpack without problem. During installation of ssmtp I got this errors: Fehl:1 http://raspbian.raspberrypi.org/raspbian buster/main armhf libgnutls30 armhf 3.6.7-4+deb10u6 404 Not Found [IP: 2a00:1098:0:80:1000:75:0:3 80] Fehl:2 http://raspbian.raspberrypi.org/raspbian buster/main armhf libgnutls-openssl27 armhf 3.6.7-4+deb10u6 404 Not Found [IP: 2a00:1098:0:80:1000:75:0:3 80]

nhorvath commented 2 years ago

This is not a sprinklerpi issue. you have a problem with your package manager.

On Tue, Sep 28, 2021 at 3:00 PM ThomasDtz @.***> wrote:

Yes - I installed mailutils and mpack without problem. During installation of ssmtp I got this errors: Fehl:1 http://raspbian.raspberrypi.org/raspbian buster/main armhf libgnutls30 armhf 3.6.7-4+deb10u6 404 Not Found [IP: 2a00:1098:0:80:1000:75:0:3 80] Fehl:2 http://raspbian.raspberrypi.org/raspbian buster/main armhf libgnutls-openssl27 armhf 3.6.7-4+deb10u6 404 Not Found [IP: 2a00:1098:0:80:1000:75:0:3 80]

— You are receiving this because you modified the open/close state. Reply to this email directly, view it on GitHub https://github.com/rszimm/sprinklers_pi/issues/140#issuecomment-929538520, or unsubscribe https://github.com/notifications/unsubscribe-auth/AABIJXADQIO34Y3R2AC3FFLUEIGFFANCNFSM4HLTBXVQ . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.