How to get the daily rain sum

229 views
Skip to first unread message

Invisible Man

unread,
Aug 28, 2023, 3:24:04 PM8/28/23
to weewx-user
I am using the Mastodon extension for Weewx. https://github.com/glennmckechnie/weewx-mastodon.
I believe my question is however not strictly related to this extension, see below.

It is possible to format the message which is tooted regularly and supply a specific format.
One of the default formats is:

```
format = '{station:%s} ' \
         '\n Windspeed: {windSpeed:%.1f} ' \
         '\n Winddir: {windDir:%03.0f} ' \
         '\n Windgust: {windGust:%.1f} ' \
         '\n outTemp: {outTemp:%.1f} ' \
         '\n outHumidity: {outHumidity:%.2f} ' \
         '\n Pressure: {barometer:%.3f} ' \
         '\n Rain: {rain:%.3f} ' \
         '\n Date Time: {dateTime:%d %b %Y %H:%M}'
```

The value of the rain does not work well for me, because, to my understanding, it's the current rain, and I seldom have rain, so I rather want to have at least the daily sum of rain. I thought I could perhaps change the format to {day.rain.sum:%.3f}, but it is not understood...

So, how can I get this daily sum?

The code imports the following modules.

```python
import weewx
import weewx.restx
import weewx.units
from weeutil.weeutil import to_bool
```

-- Axelle.

Glenn McKechnie

unread,
Aug 28, 2023, 10:35:22 PM8/28/23
to weewx...@googlegroups.com
Short answer, when using the inbuilt FORMAT strings - no.
Long answer - see the templates - which are lacking instruction but
follow standard weewx methods - I believe.

Despite being the author / maintainer of weewx-mastodon I had to go
back and check on the code.

It gets its units directly from the raw data, the archive values.

day.rain.sum is generated at a later stage of the weewx cycle by the
StdReport engine.

If however you use the template method, whereby you generate a
StdReport in your skins DATA directory - eg:-
skins/Seasons/DATA/mastodon.txt.tmpl then you should be able to do
what you are asking.

It's been a long while since I've looked at it, but I believe that will do it .
The README notes for 24th Jan 2023 v0.04 outline one hiccup when
testing the templates but it should be straight forward.
Use the default as is then start tweaking it.
> --
> You received this message because you are subscribed to the Google Groups
> "weewx-user" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to weewx-user+...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/weewx-user/6d7873c7-f325-414a-9471-d9387b469802n%40googlegroups.com.
>


--


Cheers
Glenn

rorpi - read only raspberry pi & various weewx addons
https://github.com/glennmckechnie

Greg from Oz

unread,
Aug 29, 2023, 12:22:22 AM8/29/23
to weewx-user
I used since.py and time_since.py
Check my page:
If you check the week month year for the cumulative rain is that what you are looking for?

<tr>
                        <td>Today's Rain since 12am</td>
                        <td>$day.rain.sum</td>
                      </tr>
                      <tr>
                        <td>Today's Rain since 9am</td>
                        <td>$since($hour=9).rain.sum</td>
                      </tr>
                      <tr>
                      <td>Last rain was:</td>
                        <td>$time_at('rain>0')<br>$time_since('rain>0').long_form ago</td>
                      </tr>

    search_list_extensions = user.aussearch.ausutils,user.historygenerator.MyXSearch,user.xstats.ExtendedStatistics,user.time_since.TimeSince,user.since.Since

Here are the files for python3
rain.zip

Invisible Man

unread,
Aug 29, 2023, 4:48:02 PM8/29/23
to weewx-user
Thanks to both of you for your replies.

- since.py etc are in /usr/share/weewx/user already so indeed I can try and use them. I tried to directly use since in the format line of weewx-mastodon, but haven't succeeded yet: `{since($hour=24).rain.sum:%.3f}` , `{since(hour=24).rain.sum:%.3f}`... not sure I can do it like that.
- I'll look in the template file.
- final option is that I directly tweak wxtoot.py ...

I'll investigate and post back if I have a question... or with my solution if I succeed :)

Glenn McKechnie

unread,
Aug 29, 2023, 6:07:00 PM8/29/23
to weewx...@googlegroups.com
On 30/08/2023, Invisible Man <axelle....@gmail.com> wrote:
> Thanks to both of you for your replies.
>
> - since.py etc are in /usr/share/weewx/user already so indeed I can try and

since.py is part of the weewx-mastodon install.

> use them. I tried to directly use since in the format line of
> weewx-mastodon, but haven't succeeded yet:
> `{since($hour=24).rain.sum:%.3f}` , `{since(hour=24).rain.sum:%.3f}`... not
> sure I can do it like that.

As you found, these won't work on the raw (archive) data.

> - I'll look in the template file.

The example template I mentioned already uses since.py to format the
rain value as ...
$since($hour=9).rain.sum (Australian reporting times)

According to the weewx manual at
http://www.weewx.com/docs.html/latest/customizing.htm#Formatting_examples
A format method to use for your example could be...
$since($hour=9).rain.sum.format("%.3f")
I just tested that method and it works. Apparently we've had 7.429 mm of rain!

> - final option is that I directly tweak wxtoot.py ...
> I'll investigate and post back if I have a question... or with my solution
> if I succeed :)

Done :)

Invisible Man

unread,
Aug 30, 2023, 1:00:17 PM8/30/23
to weewx-user
Ok, so I'm switching to templates, but I'm doing something wrong, because I can't get that rain sum. In my case it just prints "$since($hour=0).rain.sum.format("%.3f")" instead of showing the value.
How did you do it?
This is my `mastodon.txt.tmpl` (there are a few errors in my template e.g I shouldn't add &#x2103;C etc, but nevermind) :

```
#errorCatcher Echo
## Template file for providing data to weewx-mastodon
## https://github.com/glennmckechnie/weewx-mastodon
##
## Tag information at...
## https://weewx.com/docs/customizing.htm#Tags

Temp&eacute;rature: $current.outTemp&#x2103;C (min: $day.outTemp.min, max: $day.outTemp.max)<br>
Humidex: $current.heatindex (min: $day.heatindex.min, max: $day.heatindex.max)<br>
Humidit&eacute;: $current.outHumidity % (min: $day.outHumidity.min, max: $day.outHumidity.max)<br>
Pression: $current.barometer<br>
Pluie
- Aujourd'hui: $since($hour=0).rain.sum.format("%.3f")<br>
- Ann&eacute;e: $year.rain.sum<br>
Vent:<br>
- Direction: $current.windDir.ordinal_compass ($current.windDir deg)<br>
-Vitesse: $current.windSpeed (moyenne), $current.windGust (rafale)<br>
<br>
$current.dateTime.format("%d-%b-%Y %H:%M")
``

This is the generated mastodon.txt : 

Temp&eacute;rature: 23.2C&#x2103;C (min: 16.0C, max: 27.0C)<br>
Humidex: 23.4C (min: 15.6C, max: 27.9C)<br>
Humidit&eacute;: 70% % (min: 48%, max: 78%)<br>
Pression: 1008.9 hPa<br>
Pluie
- Aujourd'hui: $since($hour=0).rain.sum.format("%.3f")<br>
- Ann&eacute;e: 201.3 mm<br>
Vent:<br>
- Direction: E (97 deg)<br>
- Vitesse: 0 km/h (moyenne), 4 km/h (rafale)<br>
<br>
30-Aug-2023 18:50

Invisible Man

unread,
Aug 30, 2023, 4:34:49 PM8/30/23
to weewx-user
Ah, it looks like $day.rain.sum works in a template... :)

Invisible Man

unread,
Aug 31, 2023, 3:59:45 PM8/31/23
to weewx-user
Glenn,
How am I meant to publish images on Mastodon?
I have this in weewx.conf for the Mastodon extension:

```
# comma separated list of up to 4 images
images = '/home/weewx/external_html/daytempdew.png,/home/weewx/external_html/dayrain.png,/home/weewx/external_html/dayuv.png'
```

Those paths lead to graphs. I thought they would be appended to the toot, like in the image of the README.md of https://github.com/glennmckechnie/weewx-mastodon, but that's not the case. So, how does it work?

This is my mastodon account: https://piaille.fr/@biotmeteo

Thanks,
Axelle

Glenn McKechnie

unread,
Aug 31, 2023, 7:17:59 PM8/31/23
to weewx...@googlegroups.com
On 01/09/2023, Invisible Man <axelle....@gmail.com> wrote:
> Glenn,
> How am I meant to publish images on Mastodon?
> I have this in weewx.conf for the Mastodon extension:
>
> ```
> # comma separated list of up to 4 images
> images =
> '/home/weewx/external_html/daytempdew.png,/home/weewx/external_html/dayrain.png,/home/weewx/external_html/dayuv.png'
> ```
>
> Those paths lead to graphs. I thought they would be appended to the toot,
> like in the image of the README.md
> of https://github.com/glennmckechnie/weewx-mastodon, but that's not the
> case. So, how does it work?

paths and images are declared separately.

In the weewx.conf section, [[Mastodon]] , there are 3 lines relating to images.
In your example, you want these 2.

# complete if uploading images from a local directory
image_directory = /home/weewx/external_html
# comma separated list of up to 4 images
images = daytempdew.png, dayrain.png, dayuv.png

That should work for you, and if it doesn't then review the log for
wxtoot specific messages and include them in a reply.

> This is my mastodon account: https://piaille.fr/@biotmeteo
>
> Thanks,
> Axelle

Invisible Man

unread,
Sep 2, 2023, 9:24:15 AM9/2/23
to weewx-user
Ok ! I hadn't understood that at all.
So, that's what I did, but my toot has no image. Though the logs mention 1 upload of image... ?


Sep  2 14:42:51 vegan weewx[12010] DEBUG weewx.engine: Loading service user.wxtoot.Toot
Sep  2 14:42:52 vegan weewx[12010] INFO user.wxtoot: service version is 0.04
Sep  2 14:42:52 vegan weewx[12010] INFO user.wxtoot: unit system is metric
Sep  2 14:42:52 vegan weewx[12010] DEBUG user.wxtoot: site_dict is : {'station': 'biotmeteo', 'key_access_token': 'EDITED :))', 'server_url_mastodon': 'https://piaille.fr', 'post_interval': '14400', 'cardinal': 'true', 'image_directory': '/home/weewx/external_html', 'images': 'daytempdew.png,dayrain.png,dayuv.png', 'template_file': '/home/weewx/external_html/mastodon.txt', 'format_choice': 'template', 'dev_mode': False, 'log_success': True, 'log_failure': True, 'unit_system': 16, 'format_ordinal': True, 'format': 'Missing template file path', 'server_url_image': '', 'template_last_file': '', 'format_None': '-', 'format_utc': False, 'ordinals': ['N', 'NNE', 'NE', 'ENE', 'E', 'ESE', 'SE', 'SSE', 'S', 'SSW', 'SW', 'WSW', 'W', 'WNW', 'NW', 'NNW', 'N', '-'], 'visibility': 'unlisted'}
Sep  2 14:42:52 vegan weewx[12010] INFO user.wxtoot: toot visibility is unlisted
Sep  2 14:42:52 vegan weewx[12010] INFO user.wxtoot: binding is archive
Sep  2 14:42:52 vegan weewx[12010] INFO user.wxtoot: Data will be tooted for biotmeteo
Sep  2 14:42:52 vegan weewx[12010] DEBUG weewx.engine: Finished loading service user.wxtoot.Toot
Sep  2 14:46:13 vegan weewx[12010] DEBUG user.wxtoot: number of images for upload 1

The images are accessible. Example:

$ ls -al /home/weewx/external_html/daytempdew.png
-rw-r--r-- 1 weewx axelle 8161 Sep  2 15:20 /home/weewx/external_html/daytempdew.png

This is weewx.conf:

[StdRESTful]
    [[Mastodon]]
station = biotmeteo
        # from your account under preferences/development/application
        key_access_token = EDITED :)
        server_url_mastodon = https://piaille.fr
        # Mastodon will rate limit when excessive requests are made
        post_interval = 14400
        # convert from numeric degrees to Cardinal points - true or false
        cardinal = true
        # complete if fetching images via a webserver
        #server_url_image = ''

        # complete if uploading images from a local directory
        image_directory = '/home/weewx/external_html'
        # comma separated list of up to 4 images
        images = 'daytempdew.png,dayrain.png,dayuv.png'
        # example: /var/www/html/weewx/DATA/mastodon.txt
        template_file = '/home/weewx/external_html/mastodon.txt'
        #template_last_file = '/var/www/html/weewx/DATA/mastsummary.txt'
        # post formats - simple, full, template
format_choice = template
dev_mode = False

Invisible Man

unread,
Sep 2, 2023, 9:42:38 AM9/2/23
to weewx-user
Ok, I enabled dev mode, and it helped me spot the error : it was treating my 4 images as a single file. In weewx.conf, we should not put the 4 images between ' ... '.
And now it works :))
Thanks for this great extension, and your help!

Sep 02 15:30:55 vegan python3[13958]: weewx[13958] DEBUG user.wxtoot: number of images for upload 1
Sep 02 15:30:55 vegan python3[13958]: weewx[13958] INFO user.wxtoot: media is /home/weewx/external_html/daytempdew.png,dayrain.png,dayuv.png
Sep 02 15:30:55 vegan python3[13958]: weewx[13958] INFO user.wxtoot: media is not a file /home/weewx/external_html/daytempdew.png,dayrain.png,dayuv.png and of type <class 'str'>
Sep 02 15:30:55 vegan python3[13958]: weewx[13958] INFO user.wxtoot: our media_list images are 0 : []

Glenn McKechnie

unread,
Sep 2, 2023, 7:01:56 PM9/2/23
to weewx...@googlegroups.com
Hi Axelle,

Good to see it's working, and that dev_mode helped.

On 02/09/2023, Invisible Man <axelle....@gmail.com> wrote:
> Ok, I enabled dev mode, and it helped me spot the error : it was treating
> my 4 images as a single file. In weewx.conf, we should not put the 4 images
>
> between ' ... '.

Indeed. We are expecting a list (of images) and I really shouldn't
have put quotes in the example.

I've edited the repo to reflect that ...
install.py: Update install.py with image notes

> And now it works :))
> Thanks for this great extension, and your help!

And for the feed back.
Reply all
Reply to author
Forward
0 new messages