Heating · Energy monitoring
Oil boiler via Optolink in Home Assistant
A Viessmann Vitoladens 300-W brought into the smart home through a self-built optical read head – reading and writing, entirely local.
View project →A 3D-printed tipping-bucket rain gauge, connected to the smart home via an ESP8266 and ESPHome – with a calibration that turns counted tips into genuinely reliable millimetres of rainfall.
From this article on Amazon (Germany):
Wemos D1 mini (ESP8266)* ·
reed switch*
Marked *: affiliate links. As an Amazon Associate I earn from qualifying purchases.
Weather data from the internet applies to the next town, not to your own garden. Anyone who wants to automate irrigation, shading or a cistern needs the rainfall figure on site – as a dependable measurement, not an estimate. The goal was a standalone rain gauge that measures locally, works without any cloud service and delivers clean long-term statistics in Home Assistant.
The mechanism uses the classic tipping-bucket principle: a funnel collects the water and feeds it into a two-chamber seesaw. Once a chamber is full it tips over, empties and triggers a reed switch. Each tip corresponds to a defined volume of water – the number of pulses gives the rainfall.
The housing parts come from an open-source 3D model (see sources below) and were printed in-house. A Wemos D1 mini reads the reed switch via an interrupt-capable GPIO with an internal pull-up. The firmware is built with ESPHome; the connection to Home Assistant runs over the native API on the local network – no cloud service and no manufacturer account.
All parts of the model are printed: funnel, base, bucket, mesh, electronics lid, mounting and cable plug. Three pins are used on the D1 mini. The printed D numbers are not the GPIO numbers: D1 is GPIO5, not GPIO1. Anyone entering the GPIO number in ESPHome has to convert.
| Label | GPIO | Function |
|---|---|---|
| D5 | GPIO14 | reed switch of the bucket, internal pull-up, inverted, 10 ms debounce |
| D2 | GPIO4 | I²C SDA for the BME280 (work in progress) |
| D1 | GPIO5 | I²C SCL for the BME280 (work in progress) |
Search on Amazon.de: Wemos D1 mini (ESP8266)* · reed switch*
This is the point where most rebuilds stay inaccurate: a rain gauge counts tips, but what you need is millimetres. The conversion factor depends on two quantities – the tipping volume of the bucket and the collecting area of the funnel.
What counts is the inner funnel edge, not the outer dimension: water landing on the 1.2 mm wall crown splits roughly in half. I did not estimate the area; I cut it from the funnel’s STL file and measured it.
One millimetre of rainfall is one litre per square metre. One millilitre on 124.88 cm² therefore gives 0.080076 mm, and:
mm per tip = tipping volume [ml] × 0.080076
At 7.0 ml tipping volume that is 0.561 mm per tip, at 8.0 ml 0.641 mm. The difference is bigger than it looks: anyone calculating with 0.64, i.e. 8 ml, whose bucket actually tips at 7 ml reports about 14 % too much rain.
So do not rely on a nominal volume – manufacturing tolerances in printing shift the tipping volume noticeably. The check: pour 500 ml of water into the funnel as a thin stream, do not tip it in or it spills over, and count the tips that arrive in Home Assistant – not the mechanically visible ones. With this area, 500 ml equal 40.04 mm of rain.
mm per tip = poured ml × 0.080076 ÷ counted tips
About 62 to 63 tips mean 8 ml per tip, about 71 to 72 tips 7 ml. My own 500 ml test is still to come; until then the device uses the provisional value for 7 ml. I will add the result here.
The distinction matters: on some tipping mechanisms the reed switch only triggers on every second movement, depending on magnet position. Counting mechanically hides a factor of two – and the gauge permanently reads half the real value. Calibrating against the pulses actually counted rules this error out.
A reading on its own does not make a useful analysis. Three things separate a number on a dashboard from real statistics:
state_class: total_increasing. A utility_meter in
Home Assistant turns it into daily, monthly and yearly values.device_class: precipitation in mm fits. A rate may only carry
precipitation_intensity in mm/h, mm/d, in/h or in/d; a sensor in mm/min stays
without a device class.binary_sensor with delayed_on and
delayed_off filters of 10 ms each; with one tip every few minutes that
costs nothing.The core of the ESPHome configuration, trimmed to bucket, total counter and sum. Wi-Fi and API
keys live in secrets.yaml, not in plain text:
globals:
# mm per tip = tipping volume [ml] × 0.080076
# provisional 7 ml → 0.56 until the 500 ml test is done
- id: rain_mm_per_tip
type: float
restore_value: no
initial_value: '0.56'
# total counter: survives a restart, not a power cut
- id: rain_total_count
type: int
restore_value: true
initial_value: '0'
binary_sensor:
- platform: gpio
name: "Regenmesser-Eimer"
pin:
number: 14 # D5 on the Wemos D1 mini
mode: INPUT_PULLUP
inverted: true
filters:
- delayed_on: 10ms # debounce the reed switch
- delayed_off: 10ms
on_press:
then:
- globals.set:
id: rain_total_count
value: !lambda 'return id(rain_total_count) + 1;'
sensor:
- platform: template
name: "Niederschlag gesamt"
unit_of_measurement: "mm"
device_class: precipitation
state_class: total_increasing
accuracy_decimals: 2
update_interval: 60s
lambda: |-
return id(rain_total_count) * id(rain_mm_per_tip);
wifi:
ssid: !secret wifi_ssid
password: !secret wifi_password
api:
encryption:
key: !secret api_encryption_key
The total counter is kept with restore_value in the ESP8266’s RTC memory – that is
where ESPHome stores it on this chip unless restore_from_flash is enabled. It
survives a restart but not a power cut. That is deliberate: with total_increasing,
Home Assistant treats a jump to zero as a counter reset, and the flash memory is spared.
Daily, monthly and yearly totals are created in Home Assistant. The entity ID follows from
the device and sensor name and has to be adapted to your own installation;
delta_values is not needed because the source already is a cumulative counter:
utility_meter:
# adapt the entity ID to your installation
niederschlag_taeglich:
source: sensor.regenmesser_niederschlag_gesamt
cycle: daily
niederschlag_monatlich:
source: sensor.regenmesser_niederschlag_gesamt
cycle: monthly
niederschlag_jaehrlich:
source: sensor.regenmesser_niederschlag_gesamt
cycle: yearly
The same housing holds a BME280 on the I²C bus, address 0x76. Two points for rebuilding:
As of today the module is faulty. ESPHome reports “SCL is held low” and “Found no devices” and marks the sensor as FAILED. Measuring gave about 20 Ω between SCL and ground directly on the module, but no short at the D1 mini. So the fault is on the module, probably a solder bridge between the adjacent GND and SCL pins. The rain gauge keeps running unaffected.
The counting is quick to build. The time went elsewhere:
/dev/ttyUSB0. The browser was Firefox as a Snap
package. Firefox supports Web Serial since version 151, yet as a Snap it still did not see the
port. esptool on the command line worked reliably.pip install esptool fails on current Ubuntu
with “externally-managed-environment” (PEP 668). The way out is a separate virtual
environment or pipx. Since esptool 5 the commands use hyphens, such as
write-flash and chip-id; the old underscore names still run with a
warning and will be removed in the next major release.The rain gauge is a small device, but it stands for the approach I apply to larger systems too: local instead of cloud, open standards instead of vendor lock-in – and a measurement only counts once it has been checked against reality. That same diligence later decides whether energy monitoring delivers dependable figures or merely plausible-looking ones.
This project builds on open-source work by others. The sources used:
The licence terms of each source continue to apply unchanged. Please check them directly with the provider before rebuilding.
Links marked with an asterisk are affiliate links. As an Amazon Associate I earn from qualifying purchases; the price is unchanged for you. What I recommend does not depend on it.
Would you like to integrate your own sensors, a weather station or irrigation into Home Assistant? Get in touch – the initial consultation is free.