Count days since last recorded rainfall

1,553 views
Skip to first unread message

Robin

unread,
Aug 24, 2014, 9:29:13 AM8/24/14
to weewx...@googlegroups.com
Firstly, sorry if this is a repeat, but I have searched and can not see anything relevant.

I would like to show the number of days since the last recorded rainfall.

I'm running weewx on a Raspberry Pi and using an sqlite database.

Thanks.

Thomas Keffer

unread,
Aug 24, 2014, 11:10:42 AM8/24/14
to weewx-user
Hi, Robin

You would have to write a search list extension. If you know SQL, this would not be very hard to do. Just query the stats database for the last date date where rain is non-zero, then subtract from the present date.

-tk


--
You received this message because you are subscribed to the Google Groups "Weewx user's group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to weewx-user+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

gjr80

unread,
Aug 24, 2014, 9:54:54 PM8/24/14
to weewx...@googlegroups.com
Robin,

We use a similar SLE in Weewx-WD but return the timestamp of the last rainfall recorded in the archive database. We do this by querying the stats db as Tom suggests to find the day of last rain and but then we use this result to narrow a query on the archive db to a single day to find the archive period in which the last rain was recorded. This gave a more accurate time of last rain and was significantly quicker than querying the entire archive db for last rain. We then use the timestamp from the SLE in a template to calculate/display whatever we want (eg date and time of last rain, how many days ago was it etc).

I have attached a file containing the SLE. I have added a tag $last_rain_days to the SLE to show how you can calculate the number of days ago in the SLE. To use the SLE copy it to your $BIN_ROOT/user folder and in the skin.conf of the template in which you want to use the results enter/add user.searchX.lastRainTag to the search_list_extensions = line. Save skin.conf and you should be able to use the tags $last_rain and $last_rain_days in any template controlled by that skin.conf. For example:

this in your template:

Using last_rain timestamp from SLE
last rainfall was at $last_rain.format("%d %B %Y %H:%M")

then calculating days ago in template
#set $last_rain_days_ago = ($current.dateTime.raw - $last_rain.raw) / 86400.0
#set $last_rain_days_ago_formatted = "%.0f" % $last_rain_days_ago
last rainfall was $last_rain_days_ago_formatted days ago


Using days calculated in SLE
last rainfall was $last_rain_days_ago days ago
#set $last_rain_days_ago_formatted = "%.0f" % $last_rain_days_ago
last rainfall was $last_rain_days_ago_formatted days ago


produces this result:

Using last_rain timestamp from SLE
last rainfall was at 24 August 2014 11:20

then calculating days ago in template
last rainfall was 1 days ago


Using days calculated in SLE
last rainfall was 1.4 days ago
last rainfall was 1 days ago

I will let you work out how to programmatically change 'days' to 'day' depending on how many days ago the last rain was!

Gary
searchX.py

Andrew Milner

unread,
Aug 25, 2014, 4:56:15 AM8/25/14
to weewx...@googlegroups.com
Thanks for that extension ... just what I had been looking for also - works a treat and just been implemented on my site -   http://weather.andrewmilner.co.uk

Fantastic - now I know just how badly we need some rain .. 74 days and counting ....!!!!
Message has been deleted
Message has been deleted

Andrew Milner

unread,
Aug 26, 2014, 2:31:05 AM8/26/14
to weewx...@googlegroups.com
Did you add the search list extension (or create the line if not already present) to the File Generator section of weewx.conf just underneath the encoding line?

Check your spelling ... and recheck it!!  The instructions worked perfectly for me - although I will admit to already having some extensions present so the line existed in my skin.conf and I just had to add the additional tag seperated with a comma from the existing list.




On 26 August 2014 07:42, Robin <molyv...@gmail.com> wrote:
Thanks for the help.

I have followed your instructions exactly (I think) and it's not working.

The log says:

Aug 26 07:30:53 PWS weewx[14847]: reportengine: Unable to instantiate generator user.searchX.lastRainTag.
Aug 26 07:30:53 PWS weewx[14847]:         ****  __init__() takes exactly 2 arguments (6 given)
Aug 26 07:30:53 PWS weewx[14847]:         ****  Generator ignored...

What have I done wrong? 

On Monday, 25 August 2014 04:54:54 UTC+3, gjr80 wrote:

--
You received this message because you are subscribed to a topic in the Google Groups "Weewx user's group" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/weewx-user/1vtUflRv5ys/unsubscribe.
To unsubscribe from this group and all its topics, send an email to weewx-user+...@googlegroups.com.

Robin

unread,
Aug 26, 2014, 3:06:29 AM8/26/14
to weewx...@googlegroups.com
Andrew,

Thanks for your help. I deleted the message (but not before you had replied) as I figured out the error of my ways.

It always helps if you read the instructions properly. Once I had done this and corrected my very basic error it worked perfectly!

"more haste, less speed!"

Now messing with the format for my page. I will update when I get my 'ifs' and 'else ifs' sorted out.

Robin
Message has been deleted
Message has been deleted

Robin

unread,
Aug 26, 2014, 8:52:13 AM8/26/14
to weewx...@googlegroups.com
THANK YOU to everyone that has helped. This forum is a fabulous resource.

I modified xsearch.py to set up a yesterday tag. There are enough posts in this forum to help me do that, that's why it is a fabulous resource.

I then updated my index template using if/else if/else statements so that:

  1. # if $current.rainRate.raw > 0 it shows Rain Rate = $current.rainRate
  2. # else if $day.rain.sum.raw > 0 it shows Last Rainfall = Today at $last_rain.format("%H:%M")
  3. # else if $yesterday.rain.sum.raw > 0 it shows Last Rainfall = Yesterday at $last_rain.format("%H:%M")
  4. # else it shows Last Rainfall = $last_rain.format("%d %b") ($last_rain_days_ago_formatted days ago)

I have no generation errors so it looks like I got it right. All I need now is some rain so that I can check that my syntax is good. I can't compete with your 74+ days Andrew.

I no longer have that boring Rain Rate = 0mm !!!

Thanks again to everyone that helped (some by replying to other unrelated posts that helped me build the answer I needed).

Robin

you can see it all working (or not) at www.weather.molyvos.eu

Andrew Milner

unread,
Aug 26, 2014, 9:14:02 AM8/26/14
to weewx...@googlegroups.com
Can you post your modified xsearch.py and index template (well the rainfall section of the template anyway!!)

Please - as mine still has the day/days issue in it and your yesterday method means I can continue to stick to days all the time!!

Thanks.


On 26 August 2014 15:52, Robin <molyv...@gmail.com> wrote:

--

Robin

unread,
Aug 26, 2014, 9:30:49 AM8/26/14
to weewx...@googlegroups.com
Andrew,

I put 
#set $last_rain_days_ago = ($current.dateTime.raw - $last_rain.raw) / 86400.0
#set $last_rain_days_ago_formatted = "%.0f" % $last_rain_days_ago

first line after  <body> (just so I could easily find it again) 

then the rainfall section looks like this:
 
<tr>
        #if $current.rainRate.raw > 0
               
<td class="stats_label">Rain Rate</td>
               
<td class="stats_data">$current.rainRate</td>
        #else if $day.rain.sum.raw > 0
               
<td class="stats_label">Last Rainfall</td>
               
<td class="stats_data">Today at $last_rain.format("%H:%M")</td>
        #else if $yesterday.rain.sum.raw > 0
               
<td class="stats_label">Last Rainfall</td>
               
<td class="stats_data">Yesterday at $last_rain.format("%H:%M")</td>      
        #else      
               
<td class="stats_label">Last Rainfall</td>
               
<td class="stats_data">$last_rain.format("%d %b") ($last_rain_days_ago_formatted days ago)</td>
        #end if
             
</tr>

I renamed my search extension  newxsearch.py and left the original in place so I could quickly switch back to the original in skin.conf if my syntax was wrong.

Everything seems to work OK. I have no errors in my log. BRING ON THE RAIN!!!!!

Robin
newxsearch.py

Jan Commandeur

unread,
Aug 27, 2014, 3:58:11 AM8/27/14
to weewx...@googlegroups.com
Robin,

I like this extension, but which files in WEEWX must be changed and how to make this running without errors.

Jan

Op dinsdag 26 augustus 2014 15:30:49 UTC+2 schreef Robin:

gjr80

unread,
Aug 27, 2014, 4:15:06 AM8/27/14
to weewx...@googlegroups.com
To use the SLE copy it to your $BIN_ROOT/user folder and in the skin.conf of the template in which you want to use the results enter/add user.searchX.lastRainTag to the search_list_extensions = line. Save skin.conf and you should be able to use the tags $last_rain and $last_rain_days in any template controlled by that skin.conf.

Files that must be changed:

1. skin.conf (for the template in which you want to use the tags)
2. the template (xxxxxx.tmpl) that you wish to use the tags in

Files that must be added:
1. lastRainTag.py copied to you $BIN_ROOT/user folder (will vary depending on your install method, for me I use a deb install so it is in /usr/share/weewx/user

Follow the instructions carefully!

Robin

unread,
Aug 27, 2014, 8:39:22 AM8/27/14
to weewx...@googlegroups.com
Jan,

You need to download
  1. searchX.py (as posted by gjr80 - 3rd post in this thread)
  2. newxsearch.py (as posted above by me)
Upload these to the $BIN_ROOT/user folder ( I'm also using a Debian install so it is: /usr/share/weewx/user )

Then edit the search_list_extensions = line in your skin.conf file to

search_list_extensions = examples.newxsearch.MyXSearch, user.searchX.lastRainTag

it is in the [CheetahGenerator] section.

That should be it. You can now edit your template files as described above.

Big word of caution: Take great care with your editing. Every full stop and character is important, so check and check again.

I always monitor weewx using tail -f /var/log/syslog when I have made changes so that I can see where any errors are. 

Errors in your template files can also cause the Generator to throw up errors so also take great care with that.

Have fun.

Robin

Andrew Milner

unread,
Aug 27, 2014, 9:52:14 AM8/27/14
to weewx...@googlegroups.com
Robin - you originally said to put newxsearch in user directory but you have just given Jan a change to skin.conf where the newxsearch would appear to be in the examples directory!!

... Jan - check the directory where you put newxsearch and ensure that the search list extensions location corresponds!!

Robin

unread,
Aug 28, 2014, 12:14:44 AM8/28/14
to weewx...@googlegroups.com
Andrew,

Yes, sorry. Slip of the pen (typing finger) well spotted. As newxsearch was a modification of xsearch I left that where it was. searchX had been placed exactly in accordance with grj80's instructions so found itself in a different place.

Jan,

If searchX.py and newxsearch.py have been uploaded to the user directory, the search_list_extensions = line in your skin.conf file should look like

search_list_extensions = user.newxsearch.MyXSearch, user.searchX.lastRainTag

Robin

Jan Commandeur

unread,
Aug 29, 2014, 2:31:01 AM8/29/14
to weewx...@googlegroups.com
Robin,

I get this error in the syslog

Aug 29 06:27:02 duinzichttexel weewx[10774]: cheetahgenerator: Running report StandardReport for time period ToDate
Aug 29 06:27:02 duinzichttexel weewx[10774]: cheetahgenerator: generate failed with exception '<class 'NameMapper.NotFound'>'
Aug 29 06:27:02 duinzichttexel weewx[10774]: cheetahgenerator: **** ignoring template /etc/weewx/skins/Standard/index.html.tm$
Aug 29 06:27:02 duinzichttexel weewx[10774]: cheetahgenerator: **** reason: cannot find 'last_rain'
Aug 29 06:27:02 duinzichttexel weewx[10774]: ****  Traceback (most recent call last):
Aug 29 06:27:02 duinzichttexel weewx[10774]: ****    File "/usr/share/weewx/weewx/cheetahgenerator.py", line 274, in generate
Aug 29 06:27:02 duinzichttexel weewx[10774]: ****      print >> _file, text
Aug 29 06:27:02 duinzichttexel weewx[10774]: ****    File "/usr/lib/python2.7/dist-packages/Cheetah/Template.py", line 1005, $
Aug 29 06:27:02 duinzichttexel weewx[10774]: ****      rc = getattr(self, mainMethName)()
Aug 29 06:27:02 duinzichttexel weewx[10774]: ****    File "_etc_weewx_skins_Standard_index_html_tmpl.py", line 907, in respond
Aug 29 06:27:02 duinzichttexel weewx[10774]: ****  NotFound: cannot find 'last_rain'
Aug 29 06:27:05 duinzichttexel weewx[10774]: cheetahgenerator: generated 11 'ToDate' files for StandardReport in 3.11 seconds
Aug 29 06:27:22 duinzichttexel weewx[10774]: genimages: Generated 22 images for StandardReport in 17.08 seconds
Aug 29 06:27:22 duinzichttexel weewx[10774]: reportengine: copied 0 files to /var/www/weewx

What did i forget or wrong


Op donderdag 28 augustus 2014 06:14:44 UTC+2 schreef Robin:

Andrew Milner

unread,
Aug 29, 2014, 2:41:43 AM8/29/14
to weewx...@googlegroups.com
Did you remember to change the search list extensions, and did you make sure that the change to the extensions matched the directory where you placed searchX.py

Recheck the thread from the start - and check and recheck your changes,  The instructions are correct - apart from the mistake which Robin made in the directories.


Jan Commandeur

unread,
Aug 29, 2014, 1:24:21 PM8/29/14
to weewx...@googlegroups.com
All of you thanks for the help, It is running now.
I checked all again and found the error.

Jan


Op vrijdag 29 augustus 2014 08:41:43 UTC+2 schreef Andrew Milner:
Message has been deleted

Robin

unread,
Sep 2, 2014, 10:13:06 AM9/2/14
to weewx...@googlegroups.com
Over the past few days I noticed that the "days since last rain" incremented by one day at 16:50 each day.

The last rain was at 04:50 on 2nd August.

I was unsure of the coding, but a quick check revealed that 
#set $last_rain_days_ago_formatted = "%.0f" % $last_rain_days_ago
 returns a 'rounded' integer of
#set $last_rain_days_ago = ($current.dateTime.raw - $last_rain.raw) / 86400.0

So when  $last_rain_days_ago_formatted gets to X.5 it is rounded up to X+1.

The solution is simple.

#set $last_rain_days_ago = ($current.dateTime.raw / 86400 - $last_rain.raw / 86400)

$last_rain_days_ago now contains the correct number of whole days since it last rained.

Shaggy

unread,
Sep 4, 2014, 8:33:12 AM9/4/14
to weewx...@googlegroups.com
Worked first time, thank you very much.

Eirik Skorstad

unread,
Sep 20, 2014, 12:55:34 PM9/20/14
to weewx...@googlegroups.com
Wonderful extension :)

I would like to add this to the alltime records like: "Longest dry period" for example. How do I do that?

Steve

unread,
Sep 21, 2014, 5:54:51 AM9/21/14
to weewx...@googlegroups.com
Works like a charm for me thanks for doing the hard yards.

Although, I'm using the original xsearch.py and not the newxsearch.py and it seems to be working ok. I was already using the xsearch.py as I have a "Yesterday" table in my current html page. http://wotid.dyndns.org/weather/

Regards,

Steve.

Christian Peters

unread,
Aug 24, 2015, 4:32:40 PM8/24/15
to weewx-user
Hi,

sorry to pic up that old thread, but I would love to implement this "last rain" tag in my skin. As with V3.x the statsdb was dropped I think the extension will not work any more? As I am now using MYSQL with weewx it would be great if there is someone out there who could update the extension to work with weewx 3.x and with Myspql databse!?

Would be great if someone will take delight in doing the changes! :-)

Thank you!

Regards,


Christian 

Chris Thompstone

unread,
Aug 25, 2015, 3:04:33 AM8/25/15
to weewx-user
have to say that this 'days since last rain' option would be a good addition to the standard weewx software.
regards

Robin

unread,
Aug 25, 2015, 4:56:55 AM8/25/15
to weewx-user
This is now available as an extension for WeeWX v3.

You will find details at https://github.com/vinceskahan/vds-weewx-lastrain-extension and use wee_extension to install.

I have it running, you can see the results here Molyvos Weather Station.

Yves Martin

unread,
Aug 25, 2015, 1:17:55 PM8/25/15
to weewx-user
Great!

Thanks, I've added it on my web page (in French) : YMartin.com/meteo

Yves

Christian Peters

unread,
Aug 25, 2015, 2:33:17 PM8/25/15
to weewx-user
Great, just implementded!

Thank you very much, great users, great forum!! :-)

Yves Martin

unread,
Sep 2, 2015, 11:50:22 AM9/2/15
to weewx-user
I become to love this option ;)

How it is possible to get statistics, example for the largest Count days since last recorded rainfall this year, etc...

Yves,
YMartin.com/meteo/

Steve2Q

unread,
Sep 8, 2015, 6:40:19 PM9/8/15
to weewx-user
I would like to install this, but the stated installation procedure does not appear to follow the new extension protocol, ie...wee_extension --install extensions/basic      or         wee_extension --install basic.tar.gz

Should I just download the .py file and use that like    wee_extension --install extensions/lastrain.py      ?

Steve

vince

unread,
Sep 8, 2015, 6:48:15 PM9/8/15
to weewx-user
On Tuesday, September 8, 2015 at 3:40:19 PM UTC-7, Steve2Q wrote:
I would like to install this, but the stated installation procedure does not appear to follow the new extension protocol, ie...wee_extension --install extensions/basic      or         wee_extension --install basic.tar.gz


sigh - updated the readme to hold your hand a little more......

clone the repo or download any way you see fit
use the installer appropriately based on whether you have a directory, or a .tgz of the extension

sheesh...

Steve2Q

unread,
Sep 8, 2015, 8:59:23 PM9/8/15
to weewx-user
Thank you Vince. I appreciate the help, but not the exasperation at giving it. Some of us do not have any or an extremely limited background in computers, and I think that my question and the way I framed it is legitimate for someone with very limited knowledge of the subject. I have just started reading up on Python, and it is a chore understanding a lot of it, as most of the material seems to assume the reader has prior knowledge (yes, even the "easy" stuff). Oh, and there is nothing wrong or demeaning about "hand holding"; I have used it to successfully get some new radio amateurs going, and a few dental assistants.

sheesh...


Reply all
Reply to author
Forward
0 new messages