Using a wired rain gauge with WeeWx

270 views
Skip to first unread message

Seth Ratner

unread,
Oct 19, 2021, 5:18:37 PM10/19/21
to weewx-user
Hello, my searching thus far has been fruitless.

I'd like to hook a Rainwise RAINEW 111 wired rain gauge up to WeeWx running on a Raspberry Pi Zero W. Does anyone have any experience with this?


I know I can just write my own program in Python to monitor, count, and log the bucket tips, but I suspect there's a better way to do it using WeeWx, since the exact rain gauge is shown in the supported hardware list at the end under one-wire. 

I think the OWFS might be the right direction, but I have no idea how it applies. Is the bucket simply hooked up to a GPIO pin and GND? How do I get WeeWx to monitor the pin and log the bucket tips as rainfall?

Thanks!
Seth

Glenn McKechnie

unread,
Oct 19, 2021, 8:06:55 PM10/19/21
to weewx...@googlegroups.com
Regarding the Rainwise rain gauge and OWFS.

Yes and No.

It is NOT hooked up directly to the Pi, certainly not for the OWFs driver.
I see there are various HowTos about interfacing a reed switch rain
gauge to a Pi using that method but until you find one that's proven
and tested (bug free), or are willing to do the possible hard yards
yourself then... ??

With OWFS the raingauge requires a 1-wire counter module to replace
the digital counter - LCD - supplied with it.

The 1-wire counter detects the pulse from a magnet / reed-switch
combination on the bucket arm of the raingauge
If you are up to modifying the internals ( it might even be done
already? I forget) and able to source and configure a 1-wire counter
(maybe 4-5 on a 1-10 complexity scale, depending on your 1-wire
knowledge) then you can use the OWFS driver to get the data.

I use a hobby-boards (that distributor is now defunct) counter. I'm
familiar with that gear and it works well; providing you keep moisture
out of the electronics of course!

There appears to be an alternative available at Sheepwalk Electronics,
the "SWE6 Multifunction I/O Module" which mentions a counter. I have
no idea of its capabilities so you would need to discuss it with them.
You'd also need one of their host adapters if you don't have something
suitable already.

https://www.sheepwalkelectronics.co.uk/
> --
> 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/b2b32e20-e407-43ea-8e0f-037e54d918d6n%40googlegroups.com.
>


--


Cheers
Glenn

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

Seth Ratner

unread,
Oct 19, 2021, 11:32:02 PM10/19/21
to weewx-user
Thanks Glenn,

I'm not sure the OWFS solution is much simpler than just programming a counter for the gauge. What I don't know is how you take that count and insert it into WeeWx. This is partly because I'm not sure how WeeWx processes data from rain gauges, and I don't know how to get into the SQLite DB to dig around and figure it out. 

It would be pretty easy to write a Python script to count the bucket flips of the Rain Gauge, but how to get that process to then report to WeeWx, I'm not sure where to learn that.

p q

unread,
Oct 19, 2021, 11:39:35 PM10/19/21
to weewx...@googlegroups.com
You're probably going to need to write or modify a driver. The great thing about Weewx is that it's python and you have all the code. Check out the docs here: https://weewx.com/docs/customizing.htm#Implement_the_driver



--
Peter Quinn
(415)794-2264

Seth Ratner

unread,
Oct 21, 2021, 2:42:52 PM10/21/21
to weewx-user
Ok, I think I have it close, but the GPIO isn't registering.

**** CODE****
import syslog
import weewx
from weewx.wxengine import StdService
from gpiozero import Button
import datetime
import time

DRIVER_NAME = "RW111GPIOTest"
DRIVER_VERSION = "0.1"

class Rw111GpioService(StdService):
    def __init__(self, engine, config_dict):
        super(Rw111GpioService, self).__init__(engine, config_dict)      
        d = config_dict.get('Rw111GpioService', {})
        # Read from config which pin to use on the RPI GPIO
        # Defaults to 6
        # Use the loop packet event as that allows data to still get into the WeeWX database
        # as well as supporting a OLED module on the RPI
        self.rw111 = Rw111(**d)
        self.bind(weewx.NEW_LOOP_PACKET, self.load_data)
       
   
    def load_data(self, event):
        try:
            self.get_rain(event)
        except Exception as e:
            syslog.syslog(syslog.LOG_ERR, "rw111gpio: cannot read value: %s" % e)

    # Get Rainfall data
    def get_rain(self, event):
        rainfall = self.rw111.get_rainfall()
        syslog.syslog(syslog.LOG_DEBUG, "rw111gpio: found rain value of %s cm" % rainfall)
        event.packet['rain'] = float(rainfall)
   
   
class Rw111(object):
    """ Object that represents a RainWise Wired Rain Gauge. """

    def __init__(self, **d):
        """ Initialize Object. """
        # Read from config the bucket size
        self.bucket_size = d.get("bucket_size", 0.1)  # in mm
        self.rain_count = 0
        # Read from config which pin to use on the RPI GPIO
        self.rain_sensor = Button(d.get("rw111_pin", 6))
        self.rain_sensor.when_pressed = self.bucket_tipped()
        syslog.syslog(syslog.LOG_DEBUG, "rw111gpio: Button Initialized")

    def bucket_tipped(self):
        self.rain_count = self.rain_count + 1
        syslog.syslog(syslog.LOG_DEBUG, "rw111gpio: Button Pressed, count %s" % self.rain_count)

    def get_rainfall(self):
        """ Returns rainfall in cm. """
        rainfall = (self.rain_count * self.bucket_size) / 10.0
        self.reset_rainfall()
        syslog.syslog(syslog.LOG_DEBUG, "rw111gpio: Rainfall got, count: %s" % self.rain_count)
        return rainfall

    def reset_rainfall(self):
        self.rain_count = 0  

**************************

It's running, but always returning 0.0.  

I've confirmed the button works and is wired correctly. But within this service, it doesn't seem to be registering. 

Thoughts?

Seth Ratner

unread,
Oct 21, 2021, 3:27:14 PM10/21/21
to weewx-user
Ok, nevermind I got it working. The only thing I can't figure out is how to add variables into weewx.conf such as GPIO pin and bucket_size and have them pass into the service. How are variables in weewx.conf referenced?

Karen K

unread,
Oct 21, 2021, 3:39:32 PM10/21/21
to weewx-user
Seth Ratner schrieb am Donnerstag, 21. Oktober 2021 um 21:27:14 UTC+2:
How are variables in weewx.conf referenced?

By the variable config_dict you find in __init__. It is a dictionary the represents weewx.conf. For Example the section [Station] you find as config_dict['Station']. The entry "location" in the [Station] section you find as config_dict['Station']['location'].

If you need your own entries, define a section and put your values there. Then you can access them via config_dict.
 

Seth Ratner

unread,
Oct 22, 2021, 9:17:23 AM10/22/21
to weewx-user
Fantastic, Thank you! That's exactly what I needed. 

Seth Ratner

unread,
Oct 22, 2021, 10:22:05 AM10/22/21
to weewx-user
Got it working!

This allows you to add a wired rain gauge to WeeWx via the GPIO pins on a Raspberry Pi. Thanks for the help!

vince

unread,
Oct 22, 2021, 1:32:02 PM10/22/21
to weewx-user
Pretty cool.  Dumb questions follow.....
  • how'd you wire it up ?
  • did you not use the little display that comes with the gauge ?
  • their manual says 'wire cannot be buried' - any idea why ?   What if it was in a PVC conduit ?
  • what does your zeroW setup look like for powering it, keeping it dry, etc. ????
  • add photos and a nice writeup to your github page perhaps ?
Reason I'm asking is that this seems like a pretty nice way for folks to add a rain gauge to stations like WeatherFlow that have notoriously inaccurate readings, assuming they are already running the nice WF UDP driver for that gear...



Seth Ratner

unread,
Oct 24, 2021, 9:55:18 PM10/24/21
to weewx-user
One wire to the chosen GPIO pin (set in weewx.conf) and one to GND. 

Nope. I might keep it for a future project, but not used here

Yeah I'm guessing it's just because the wire is not direct burial rated. I'll be routing mine through PVC

I keep it in a shed in the orchard. All components are mounted to a piece of plywood. For power I have a 20w solar panel with a Renogy Wanderer solar charge controller and a 6Ah battery. I may increase the battery size, as the system also powers an OpenSprinkler controller and 16 zone extender. The Pi serves as a WeeWx host, MQTT bridge with my HomeAssistant server and reverse proxy to serve the Open Sprinkler. I'll add an Ecowitt HS80 and GW1100 soon to complete the station. 

I may once I finish things up, but there's not much to see with the GPIO Rain Gauge since literally the only setup is connecting the two wires to the two RPi pins. 

vince

unread,
Oct 25, 2021, 12:00:50 PM10/25/21
to weewx-user
Helps a lot, thanks.   I kinda figured you had other power that you're just piggybacking the pi onto.   Cool project.

DrTron

unread,
Dec 27, 2022, 10:22:18 AM12/27/22
to weewx-user
Seth,
Reviving this thread since I currently run a very similar setup. However, I have a rather el-cheapo rain gauge and was looking into replacing it with something more accurate, like the Rainwise RAINEW 111.

Supposing you did calibrate the gauge, what bucket size did you arrive at? Like, how many mm of rain per bucket tip?

I already suspected that the wire from the gauge just contains the button-like signal from the reed switch, as does my current gauge, so I can directly swap it out.

Thanks!

Seth Ratner

unread,
Dec 27, 2022, 10:49:38 AM12/27/22
to weewx...@googlegroups.com
The Rain wise bucket is .01" / .254mm, and in testing it that has been accurate. It's more a matter of leveling the buckets once mounted, but it's not a difficult procedure. 

And yes, it just acts as a button/switch. I used the gpio library because it easily allows for treating the bucket like a button and assigning a function to it. You just want to make sure you only trigger the function when the reed switch closes, not on state change (which would give double the triggers per bucket tip, open and close). You can also change the settings to avoid bouncing. 


--
You received this message because you are subscribed to a topic in the Google Groups "weewx-user" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/weewx-user/K30GuHsZoE4/unsubscribe.
To unsubscribe from this group and all its topics, send an email to weewx-user+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/weewx-user/a063befb-f4df-4e15-acc7-37ed7af991c7n%40googlegroups.com.

DrTron

unread,
Dec 27, 2022, 12:42:54 PM12/27/22
to weewx-user
Thanks a lot, Seth!
I do it similarly in python: from gpiozero import Button
That button routine in the gpiozero library already has a debounce function and I only count on "close" and just ignore the "open". So far it works well, but my current gauge only has a 5 * 11 cm opening (=55cm2), whereas the Rainwise probably has 5-6 times that.
Mine tips every 0.387mm of rain (calibrated to my best abilities), so I guess I would benefit from the Rainwise gauge.

Seth Ratner

unread,
Dec 27, 2022, 3:46:21 PM12/27/22
to weewx...@googlegroups.com
I've been happy with mine. Ecowitt sells a bird spike kit that fits it very well. 

The only downside is making the bucket play nice with whatever driver you're using for the main weather station. I created a service to accomplish this, which is linked in this thread. Come to think of it, I'll probably try to get Tom to take a quick look at the service, make sure I'm following the weewx best practices. He was incredibly helpful in getting my chill hours xtype to work.

Make sure if you're using a service to count the bucket tips that you have a function to disconnect the pin from gpiozero. If something goes wrong and the weewx engine restarts, if your service hasn't released the pin when it exited then it will throw an error trying to reassign the pin. Took me a while to figure that one out..

DrTron

unread,
Dec 27, 2022, 3:53:20 PM12/27/22
to weewx-user
Good to know. The RPi where the bucket is connected to is actually not the machine I run weewx on. I run MQTT to feed the (collective) rain amount into weewx every time the bucket tips. My "main" weather station, if you want to call it that, is a Ecowitt GW1100 with an outside temperature sensor. At least that's what's configured as the weather station in weewx.
But yes, I wrote a simple systemd service script that restarts the python script if necessary.

Seth Ratner

unread,
Dec 27, 2022, 6:03:45 PM12/27/22
to weewx...@googlegroups.com
Could you share the programming for that? Maybe you have it on Github? Right now I have everything running on an RPi because the weather station is remote. But eventually I'd like to have Weewx running in a virtual machine, and the bucket will get connected to a RPi Pico and report the tips via MQTT as you have set up. I'd like to see what you're using to subscribe to the MQTT topic and feed it into the WeeWx loop.

Thanks!

DrTron

unread,
Dec 27, 2022, 6:26:18 PM12/27/22
to weewx-user
Seth,
that's actually pretty easy to set up. My python script on the RPi runs in an endless loop, waits for a bucket tip and only writes the cumulative number of tips (ever) to a file and calculates the rain amount (total, cumulative) by multiplying it with the bucket size. Before that, it reads the current bucket count from that file. I don't have that on Github, it's probably pretty ugly and simple, but works for me.

raincount = open("raincount.txt","rt")
count = int(raincount.read())
raincount.close()

On a bucket tip, or rather "button press", that "count" variable is incremented by one and both count and rainfall mm written to the file:

   count = count + 1
   mm = count * bucketsize
   f = open("raincount.txt", "w")
   f.write(str(count))
   f.close()     

   f = open("rainmm.txt", "w")
   f.write(str(mm))
   f.close()    

As I have a bash script running every 5 minutes that takes care of the MQTT of the rainfall and other sensor data from other sensors connected to the Pi, along with writing the values to an influxdb, I just use that script to read from rainmm.txt and publish that to MQTT.

To get the data into Weewx, I use this extension:


With that, you can have Weewx subscribe to any topic and push that data into a Weewx variable. This is from weewx.conf:

    [[topics]]
       # Units for MQTT payloads without unit value.
       # Valid values: US, METRIC, METRICWX
       # Default is: US
       unit_system = METRIC
        
       [[[raspi1/rainmm]]]
           # The WeeWX name.
           # Default is the name from MQTT.
           name = rain
            
           # True if the incoming data should not be processed into WeeWX.
           # Valid values: True, False
           # Default is False
           ignore = False
            
           # True if the incoming data is cumulative.
           # Valid values: True, False
           # Default is False
           contains_total = True
            
           # The conversion type necessary for WeeWX compatibility
           # Valid values: bool, float, int, none
           # Default is float
           conversion_type = float
            
           # The units of the incoming data.
           # Useful if this field's units differ from the topic's unit_system's units.
           # Valid values: see, http://www.weewx.com/docs/customizing.htm#units
           # Default is not set
           units = mm

Hope that helps.
Reply all
Reply to author
Forward
0 new messages