Rain meter for Home Assistant

This is a rain meter created with a 3D printer and connected to Home Assistant.



Parts needed:
- 3D printer
- Aqara door sensor
- Neodyn magnet, 12x2 mm

Get the STL files from Thingiverse:


The idea is that a cradle fills up on one side with rain water, when there is enough water will the cradle tip over and the door sensor react.


I wasn't able to use the magnet that is supplied with the door sensor as that one is too heavy.

Assembly

Take a piece of filament and use that as a hinge, make it long enough so it can't slide out, but not as long as it will touch the sides of the housing. Place the door sensor with its bottom away from the magnet and the button up.

Home Assistant

Add the door sensor to Home Assistant using for example ZHA, Zigbee Home Automation, using for example a Conbee USB stick.

Add a couple of sensors to HA:
(Change binary_sensor.rainmeter to your own name)

sensor:
  - platform: history_stats
    name: rainsensor_flips_on
    entity_id: binary_sensor.rainmeter
    state: 'off'
    type: count
    start: '{{ now() - timedelta(hours=24)}}'
    end: '{{ now() }}'
  - platform: history_stats
    name: rainsensor_flips_off
    entity_id: binary_sensor.rainmeter
    state: 'on'
    type: count
    start: '{{ now() - timedelta(hours=24)}}'
    end: '{{ now() }}'

And templates:

template:
  - sensor:
    - name: rainsensor_flips
      unique_id: rainsensor_flips
      state: "{{ (states('sensor.rainsensor_flips_on') | int + states('sensor.rainsensor_flips_off') | int - 1) }}"
  - sensor:
    - name: rainfall_today
      unit_of_measurement: mm
      state_class: total_increasing
      unique_id: rainfall_today
      state: >-
        {% set count = states('sensor.rainsensor_flips') | int(0) %}
        {% set mm = count * 0.768398 %}
        {% if count >= 0 %}
          {{ mm|round(1, 'floor') }}
        {% endif %}
      availability: "{{ (states('sensor.rainsensor_flips') not in ('unknown', 'unavailable')) }}"

Comments