Use case: Build a reliable & low-cost Rain Gauge with an IKEA parasoll door contact

I wanted to add a rain gauge to my smarthome installation. But the ones I found were either too expensive (> € 100 from Homematic) or they relied on yet another proprietary gateway which I wanted to avoid just for one additional piece of hardware (e.g. this one from Netatmo).

So the idea was born to build one myself, especially since the hardware for the actual “translating rain into pulses”-piece (e.g. the WH-SP-RG rain gauge, which is a spare part for an expensive weather station) is fairly cheap (~ € 20). What this rain gauge basically does: It translates a certain amount of raindrops (–> weight) via a seesaw into pulses: Whenever the seesaw flips (if enough water is in it), a magnet in the seesaw passes a reed switch in the base of the gauge, that causes a pulse. And if you know how much water triggers the seesaw, you can calculate how much rain has fallen in a certain time intervall.

To hook up the WH-SP-RG to openHAB, the idea was to replace the reed switch (which just ends on a cable) with an IKEA parasoll door contact, to do the “pulse capturing” and "transmitting the pulses wirelessly to openHAB) after being inspired by this solution. So whenever the seesaw flips, the parasoll door contact is triggered and sends a pulse to openHAB.

Using an IKEA parasoll door contact offers a couple of advantages:

  • The parasolls are extremely reliable (since they were designed for a security-relevant application). Phantom pulses or missed pulses are unlikely.
  • The parasolls are well-protected against moisture (rubber sealings around the battery compartment). My sensor has been “open in the wet” for 6 months now without any problems at all.
  • The battery management comes out-of-the-box and can easily be monitored in openHAB. Replacing the battery easy.
  • Since the parasoll relies on zigbee, the network coverage can cheaply be expanded for just € 8 via the IKEA Tretakt via the integrated repeater function and thus be placed far away from buildings (to avoid false rain readings in case of wind)

My rationale for not using an ESP (instead of the parasoll) can be found at the very bottom.

Step 1: Prepare the WH-SP-RG rain gauge

Open the hood of the rain gauge, open the lid that hosts the PCB (that hosts the reed switch) and remove the PCB and the cable completely (only sticked inside).

Before:


After:

In order for the Parasoll to pick up the magnetic field, the magnet on the seesaw has to point towards the other side of the gauge (where the parasoll will be placed). So gently remove the pin, turn the seesaw by 180°, and turn the pin back in. Afterwards the gauge should look like this: The magnet points towards the other side than before.

Step 2: Attach the Parasoll to the WH-SP-RG rain gauge

This part is tricky. The magnet in the WH-SP-RG is not super strong, and the “detection range” of the parasoll is not super large. Plus the magnet only travels ~ 1 cm with each “seesaw flip”, so the parasoll’s hall sensor has to be placed “close enough” to the magnet to the magnet’s magnetic field, but “far enough” to be able to distinguish a change between the seesaw’s position. After some trial and error the following position detects each seesaw flip reliably. The sticky tape that comes with the parasoll is also fairly strong, so it sticks firmly.

Step 3: Re-assemble the WH-SP-RG rain gauge

Pair the parasoll to openHAB (press the button four times to bring it into pairing mode), add all channels as things (for now) and close the WH-SP-RG’s cover.

Step 4: If needed: Expand the Zibgee-Range

As mentioned, the rain gauge has to be placed away from buildings to measure the rain correctly. Therefore, the main advantage of using Zigbee (being able to extend the network easily) comes into play: To extend the Zigbee network, I used the € 8 IKEA Zigbee plug Tretakt to have full coverage in my yard. In my case, I placed it midway between the rain gauge and an existing Zigbee device, which resulted in a super stable signal.

Step 5: Create items in openHAB

After pairing the parasoll, I use the first three default channels of the parasoll (see picture below) for battery management (channel 1 - 3) and the fourth channel for the actual calculation (channel “Contact”):
image.
The last six items were created manually and are not linked to any channel but will be filled later via a rule (example code for one of the six items):

label: Rain - Today (in l/m²)
type: Number
category: rain
groupNames:
  - Regenmengen_Sensor_Parasoll
tags:
  - Point

Step 6: Translate pulses into rain (l/m2)

What’s now important to know is the amount of rain that is represented by one “seesaw-flip”. I’ve done some reading online and done some geometric calculation, and came across the number 0,303 l/m² per seesaw-flip. If someone finds out that another value is more precise, let me know.

The translation is now done via a rule that is triggered by two actions: “Seesaw-flip” and “full hour”.

  • Seesaw-flip: When it rains and the seesaw flips, the amount of rain (per hour, day, etc) should be updated. To avoid unintended calculations in case of openHAB reboots etc, the rule is only triggered by changing from ON to OFF or from OFF to ON.

  • Full hour: To be able to calculate “rain in current hour”, “rain in last hour”, “rain yesterday” etc, the rule is also triggered at every full hour.
    The rule itself is then pretty straight forward:

  • If the seesaw flips: Update “Rain Current Hour” and “Rain Today”.

  • At every full hour: Write “Current Hour” to “Last Hour”. And if it’s at midnight, write “rain today” to “Rain yesterday”.

Code:

var RainCurrentHour, RainToday, TotalPulses, RainTotal;


if (event.type == 'ItemStateChangedEvent') {
  console.error('Pfad "Regenmengen-Sensor" wurde ausgelöst');
  RainCurrentHour = items.getItem('RainCurrentHour').numericState;
  RainCurrentHour = (typeof RainCurrentHour === 'number' ? RainCurrentHour : 0) + 0.303030303;
  items.getItem('RainCurrentHour').sendCommand(RainCurrentHour);
  RainToday = items.getItem('RainToday').numericState;
  RainToday = (typeof RainToday === 'number' ? RainToday : 0) + 0.303030303;
  items.getItem('RainToday').sendCommand(RainToday);
  TotalPulses = items.getItem('RainTotalNumberOfPulses').numericState;
  TotalPulses = (typeof TotalPulses === 'number' ? TotalPulses : 0) + 1;
  items.getItem('RainTotalNumberOfPulses').sendCommand(TotalPulses);
  RainTotal = TotalPulses * 0.303030303;
  items.getItem('RainTotal').sendCommand(RainTotal);
} else if (event.type == 'TimerEvent') {
  console.error('Trigger zur vollen Stunde: Stunden-Counter zurücksetzen');
  items.getItem('RainPastHour').sendCommand(items.getItem('RainCurrentHour').numericState);
  items.getItem('RainCurrentHour').sendCommand(0);
  if (((time.ZonedDateTime.now()).hour()) == 0) {
    console.error('Trigger nachts um 00:00: Tages-Counter zurücksetzen');
    items.getItem('RainYesterday').sendCommand(items.getItem('RainToday').numericState);
    items.getItem('RainToday').sendCommand(0);
  }
}

Appendix

Edge case for “why sensors can fail”

One week I was wondering why the sensor did not send values anymore, even though it was raining heavily. The root cause could be found easily: Huge snails climbed on top of the sensor and (since the sensor is not that heavy) flipped it over. :smiley: Since the sensor has two holes at the bottom, this can easily be avoided by mounting it on a plate.


Funny detail: The snail not only flipped over the sensor, but also (for the picture) blocked the water hole with its body. :smiley: Another edge case for "why sensors can fail.

Why not using an ESP (instead of a parasoll)

Before using a parasoll, I tried out an ESP to capture the impulses and send them to openHAB. While this approach worked perfectly fine for my DIY water flow meter, using this approach did not work well for the as a rain gauge following reasons:

  • A rain gauge has to be placed far away from buildings (otherwise the readings could be off), which makes it difficult to supply electricity to the sensor (you’d have to lie a cable). Yes, ESPs do support deep sleep functions and could run on battery as well, but implementing (and testing) this is tricky and time-consuming.
  • Related to that: The sensor should have a reliable battery management (to report low battery to openHAB) and battery changes should be easy. Same here: Could be realized with an ESP as well, but just a lot easier with a Parasoll.
  • The WH-SP-RG rain gauge captures the pulses via a reed switch, which are known for bouncing. The de-bouncing can be done in hardware or in software (e.g. via the debounce-commands if Tasmota is being used). However, even after spending countless hours trying out both methods, I still suffered either from phantom pulses (too many) or missed pulses (too few). And since a mild rain often only consists of one or two pulses, missing a pulse or having too many is not an option.
  • Having a custom-made sensor “out in the rain” is not a good combination, at least in my experience. Of course there are many ways to protect electronics from water, but at least I’ve not managed to keep a custom-made sensor dry and alive for more than two years.

That’s it. Happy to hear your thoughts and improvement suggestions! :slight_smile:

8 Likes