{"id":19,"date":"2025-06-04T23:29:53","date_gmt":"2025-06-04T21:29:53","guid":{"rendered":"https:\/\/blog.bratfisch.net\/?p=19"},"modified":"2025-07-25T23:17:48","modified_gmt":"2025-07-25T21:17:48","slug":"a-beelogger-on-esp32-basis-part-4-rain-sensor","status":"publish","type":"post","link":"https:\/\/blog.bratfisch.net\/index.php\/2025\/06\/04\/a-beelogger-on-esp32-basis-part-4-rain-sensor\/","title":{"rendered":"A beelogger on ESP32 basis, part 4: Test setup: The rain sensor"},"content":{"rendered":"\n<p>I bought a rain gauge from china, it&#8217;s a spare part for the &#8220;misol&#8221; weather stations, just search for &#8220;rain gauge sensor aliexpress&#8221; for the product, it was less than 15\u20ac. Technically it&#8217;s just a hall sensor.<\/p>\n\n\n\n<div class=\"wp-block-columns is-layout-flex wp-container-core-columns-is-layout-28f84493 wp-block-columns-is-layout-flex\">\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\" style=\"flex-basis:100%\">\n<figure class=\"wp-block-gallery has-nested-images columns-default is-cropped wp-block-gallery-1 is-layout-flex wp-block-gallery-is-layout-flex\">\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"960\" height=\"960\" data-id=\"135\" src=\"https:\/\/blog.bratfisch.net\/wp-content\/uploads\/2025\/06\/image-7.png\" alt=\"\" class=\"wp-image-135\" srcset=\"https:\/\/blog.bratfisch.net\/wp-content\/uploads\/2025\/06\/image-7.png 960w, https:\/\/blog.bratfisch.net\/wp-content\/uploads\/2025\/06\/image-7-300x300.png 300w, https:\/\/blog.bratfisch.net\/wp-content\/uploads\/2025\/06\/image-7-150x150.png 150w, https:\/\/blog.bratfisch.net\/wp-content\/uploads\/2025\/06\/image-7-768x768.png 768w\" sizes=\"auto, (max-width: 960px) 100vw, 960px\" \/><\/figure>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"1024\" data-id=\"307\" src=\"https:\/\/blog.bratfisch.net\/wp-content\/uploads\/2025\/06\/image-11.png\" alt=\"\" class=\"wp-image-307\" srcset=\"https:\/\/blog.bratfisch.net\/wp-content\/uploads\/2025\/06\/image-11.png 1024w, https:\/\/blog.bratfisch.net\/wp-content\/uploads\/2025\/06\/image-11-300x300.png 300w, https:\/\/blog.bratfisch.net\/wp-content\/uploads\/2025\/06\/image-11-150x150.png 150w, https:\/\/blog.bratfisch.net\/wp-content\/uploads\/2025\/06\/image-11-768x768.png 768w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"1024\" data-id=\"310\" src=\"https:\/\/blog.bratfisch.net\/wp-content\/uploads\/2025\/06\/image-12.png\" alt=\"\" class=\"wp-image-310\" srcset=\"https:\/\/blog.bratfisch.net\/wp-content\/uploads\/2025\/06\/image-12.png 1024w, https:\/\/blog.bratfisch.net\/wp-content\/uploads\/2025\/06\/image-12-300x300.png 300w, https:\/\/blog.bratfisch.net\/wp-content\/uploads\/2025\/06\/image-12-150x150.png 150w, https:\/\/blog.bratfisch.net\/wp-content\/uploads\/2025\/06\/image-12-768x768.png 768w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n<\/figure>\n<\/div>\n<\/div>\n\n\n\n<div class=\"wp-block-columns is-layout-flex wp-container-core-columns-is-layout-28f84493 wp-block-columns-is-layout-flex\">\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\" style=\"flex-basis:100%\"><\/div>\n<\/div>\n\n\n\n<p>For my test-setup, I simply cut off the connector and connected the wires directly to GND and GPIO4 and used the internal pull-up resistor:<\/p>\n\n\n\n<figure class=\"wp-block-image aligncenter size-full is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"693\" height=\"750\" src=\"https:\/\/blog.bratfisch.net\/wp-content\/uploads\/2025\/06\/beelogger-rain-sensor.png\" alt=\"\" class=\"wp-image-274\" style=\"width:auto;height:300px\" srcset=\"https:\/\/blog.bratfisch.net\/wp-content\/uploads\/2025\/06\/beelogger-rain-sensor.png 693w, https:\/\/blog.bratfisch.net\/wp-content\/uploads\/2025\/06\/beelogger-rain-sensor-277x300.png 277w\" sizes=\"auto, (max-width: 693px) 100vw, 693px\" \/><\/figure>\n\n\n\n<p>Adding it to esphome is straight forward and easy. I&#8217;m using the <a href=\"https:\/\/esphome.io\/components\/sensor\/pulse_counter.html\" data-type=\"link\" data-id=\"https:\/\/esphome.io\/components\/sensor\/pulse_counter.html\">pulse counter component<\/a>, it uses the <a href=\"https:\/\/docs.espressif.com\/projects\/esp-idf\/en\/latest\/api-reference\/peripherals\/pcnt.html\">pulse counter peripheral of the ESP32<\/a> and works in standby-modes:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>substitutions:\n  update_interval: 5s\n\nsensors:\n - platform: pulse_counter\n    name: \"Rainfall Pulse Counter\"\n    id: rainfall_pulse_counter\n    use_pcnt: true\n    count_mode: \n      falling_edge: INCREMENT\n      rising_edge: DISABLE\n    pin:\n      number: GPIO4\n      inverted: true\n      mode:\n        input: true\n        pullup: true\n    unit_of_measurement: \"mm\"\n    icon: \"mdi:water\"\n    update_interval: ${update_interval}\n    filters:\n      # I'm unsure what value is correct, I'll have to measure it myself\n      - multiply: 0.2794\n      # - multiply: 0.367\n      - debounce: 10ms\n    total:\n      name: \"Rainfall Total Pulses\"\n\n  - platform: template\n    name: \"Hourly Rainfall\"\n    id: hourly_rainfall\n    unit_of_measurement: \"mm\"\n    icon: \"mdi:weather-rainy\"\n    update_interval: never\n\n  - platform: template\n    name: \"Daily Rainfall\"\n    id: daily_rainfall\n    unit_of_measurement: \"mm\"\n    icon: \"mdi:weather-pouring\"\n    update_interval: never\n\n  - platform: template\n    name: \"Rainfall Accumulator\"\n    id: rainfall_accumulator\n    unit_of_measurement: \"mm\"\n    icon: \"mdi:counter\"\n    update_interval: never\n    internal: true  # Hide from Home Assistant\n\ninterval:\n  # Every minute: add current pulse count to accumulator\n  - interval: 60s\n    then:\n      - lambda: |-\n          float current = id(rainfall_pulse_counter).state;\n          id(rainfall_accumulator).publish_state(id(rainfall_accumulator).state + current);\n\n  # Every hour: publish hourly total and reset accumulator\n  - interval: 1h\n    then:\n      - lambda: |-\n          float total = id(rainfall_accumulator).state;\n          id(hourly_rainfall).publish_state(total);\n          id(rainfall_accumulator).publish_state(0);\n\n  # Every day at midnight: publish daily total and reset accumulator\ntime:\n  - platform: homeassistant\n    on_time:\n      - seconds: 0\n        minutes: 0\n        hours: 0\n        then:\n          - lambda: |-\n              float total = id(rainfall_accumulator).state;\n              id(daily_rainfall).publish_state(total);\n              id(rainfall_accumulator).publish_state(0);<\/code><\/pre>\n\n\n\n<p>The value &#8220;0.2794&#8221; is explained here in the datasheets I found in <a href=\"https:\/\/github.com\/Nik71git\/stazione-meteo\/wiki\" data-type=\"link\" data-id=\"https:\/\/github.com\/Nik71git\/stazione-meteo\/wiki\">this wiki<\/a> that seem to match my hardware:<br><a href=\"https:\/\/github.com\/Nik71git\/ESP32-weather-station\/files\/10190321\/sensor.datasheet.pdf\">datasheet_1<\/a><br><a href=\"https:\/\/github.com\/Nik71git\/ESP32-weather-station\/files\/10190323\/sensor.datasheet.2.pdf\">datasheet_2<\/a><\/p>\n\n\n\n<p><br>The value &#8220;0.367&#8221; is explained here:<br><a href=\"https:\/\/community.home-assistant.io\/t\/how-to-measure-integration-of-rain-pulse-counter-into-daily-value\/136709\" data-type=\"link\" data-id=\"https:\/\/community.home-assistant.io\/t\/how-to-measure-integration-of-rain-pulse-counter-into-daily-value\/136709\">https:\/\/community.home-assistant.io\/t\/how-to-measure-integration-of-rain-pulse-counter-into-daily-value\/136709<\/a><\/p>\n\n\n\n<p>I don&#8217;t know yet which one is correct, I&#8217;ll do some measurements.<\/p>\n\n\n\n<p><br><\/p>\n","protected":false},"excerpt":{"rendered":"<p>I bought a rain gauge from china, it&#8217;s a spare part for the &#8220;misol&#8221; weather stations, just search for &#8220;rain gauge sensor aliexpress&#8221; for the product, it was less than 15\u20ac. Technically it&#8217;s just a hall sensor. For my test-setup, I simply cut off the connector and connected the wires directly to GND and GPIO4 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[3,4,5],"class_list":["post-19","post","type-post","status-publish","format-standard","hentry","category-allgemein","tag-beelogger","tag-esp32","tag-esphome"],"_links":{"self":[{"href":"https:\/\/blog.bratfisch.net\/index.php\/wp-json\/wp\/v2\/posts\/19","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.bratfisch.net\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.bratfisch.net\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.bratfisch.net\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.bratfisch.net\/index.php\/wp-json\/wp\/v2\/comments?post=19"}],"version-history":[{"count":75,"href":"https:\/\/blog.bratfisch.net\/index.php\/wp-json\/wp\/v2\/posts\/19\/revisions"}],"predecessor-version":[{"id":1025,"href":"https:\/\/blog.bratfisch.net\/index.php\/wp-json\/wp\/v2\/posts\/19\/revisions\/1025"}],"wp:attachment":[{"href":"https:\/\/blog.bratfisch.net\/index.php\/wp-json\/wp\/v2\/media?parent=19"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.bratfisch.net\/index.php\/wp-json\/wp\/v2\/categories?post=19"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.bratfisch.net\/index.php\/wp-json\/wp\/v2\/tags?post=19"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}