Many weather sensors just report a cumulative rainfall amount to their display unit. That is, when installed the sensor will start with 0 millimeters, and then as rain falls, it will just keep adding to that number, until the sensor loses power, or is reset.
Since it took me a long time to reach a working solution, I am posting this information to save people looking for the same hours and hours of fruitless searching, and frustrating experimentation.
Acurite 5n1 Message Capture And Conversion To MQTT
One such sensor is the Acurite 5n1.
The details of capturing the messages from the sensor are beyond the scope of this article.
But in summary, this is done using any RTL-SDR USB dongle, with the excellent rtl_433 program, and some Python glue code to start rtl_433, then capture the message and transform it to JSON, and send it to the MQTT server.
From MQTT, the messages are captured to any application that is subscribed to the topic. This includes Home Assistant and Weewx.
Acurite 5n1 MQTT Message Format
A sample partial message from the above sensor transformed into MQTT JSON format is as follows:
{
"time": "2022-08-16 11:54:46",
"model": "Acurite-5n1",
"subtype": 49,
"id": 1234,
...
"wind_avg_km_h": 4.3112,
"wind_dir_deg": 135,
"rain_mm": 42.12,
}
The field "rain_mm" keeps increasing as more rain falls, and then resets to zero if there is a power loss on the sensor.
The fact that the 'rain_mm' amount is cumulative poses a challenge to some applications, but not others. For example, Weewx handles all this internally without any special configuration.
Other applications do not have such built-in smarts, and need to be told how to calculate rainfall properly, by minute, week, month, ...etc.
One application that I use is Grafana which is an interactive visualization tool, with an underlying InfluxDB time series database that is fed from Home Assistant MQTT.
The key here is to use non_negative_difference() for the bar graph, and adding cumulative_sum() for the gauge, as follows:
Grafana InfluxDB Panel Bar Graph For Rainfall
This panel will display a bar graph for the time range that is selected.
FROM default mm WHERE entity_id = local_rainfall
SELECT field(value), last(), non_negative_difference()
GROUP BY time($__interval)
Grafana InfluxDB Panel For Rainfall Amount
This panel will display the cumulative amount of rain for the time range that is selected.
FROM default mm WHERE entity_id = local_rainfall
SELECT field(value), last(), non_negative_difference(), cumulative_sum()
GROUP BY time($__interval)
The above two panels will look like this:
Most Comments
Most commented on articles ...