Keep us updated
sure thing! I hope I will have the initial setup next week! This week is much too hectic to be able to work on this!
But I will come back with an update!
@parrel, thank you for sharing your projects. I have done the rain meter and planning to do a few chair occupancy sensors. What a hacky way to use the door sensor Human ingenuity won’t stop to amaze me.
I have one comment. Normally rainfall calculations are done on some area (in meter squared) so in the template you would need to devide rainfall by catchment area and the unit would be mm / m2.
If you have a precipitation forecast in your country, you can make a graph with the rain gauge and the forecast! I used Apexcharts and the data_generator to get a 2 hour forecast in the graph.
I have managed to bring all the parts together on this gauge. The battery seems to be charging from the small solar pannel I modified. I used a solar pannel from an ikea string of lights that I had in the shed.
The problem I have is with the software part. I have used some of the sensors others have setup but I can’t get it working.
In my configuration.yaml I have several includes like this:
sensor: !include config/sensors.yaml
template: !include config/templates.yaml
binary_sensor: !include config/binary_sensor.yaml
In the sensors.yaml I have setup two sensors for this rain gauge:
- platform: history_stats
name: "Raingauge tips"
entity_id: binary_sensor.rain_meter
state: 'off'
type: count
start: '{{ now().replace(hour=0, minute=0, second=0) }}'
end: '{{ now() }}'
- platform: template
sensors:
rain_today:
friendly_name: "Rain today"
unit_of_measurement: "mm"
value_template: >-
{% set count = states('sensor.raingauge_tips') | int(0) %}
{% if states.sensor.date_time_iso.last_changed - states.sensor.rain_today.last_changed > timedelta(minutes=60) %}
{% set mm_per_pulse = 0.30303 %}
{% else %}
{% set mm_per_pulse = 0.30303 %}
{% endif %}
{% set mm = count * mm_per_pulse %}
{% if states('sensor.raingauge_tips') != 'unknown' %}
{{ mm }}
{% else %}
{{ states('sensor.rain_today') }}
{% endif %}
rain_per_hour:
friendly_name: "Rain per hour"
unit_of_measurement: 'mm/h'
value_template: >-
{% if state_attr('binary_sensor.rain','gradient') != None and state_attr('binary_sensor.rain','gradient') > 0 and state_attr('binary_sensor.rain','gradient') < 0.0278 %}
{{ (state_attr('binary_sensor.rain','gradient')*3600) | round(1) }}
{% else %}
0
{% endif %}
I liked the idea to have the rain per hour option too.
In the binary_sensor.yaml I have:
- platform: trend
sensors:
rain:
entity_id: sensor.rain_today
min_gradient: 0.000138889
max_samples: 3
Unfortunately these don’t work as expected. There are these errors in the logs:
TemplateError('UndefinedError: 'None' has no attribute 'last_changed'') while processing template 'Template("{% set count = states('sensor.raingauge_tips') | int(0) %} {% if states.sensor.date_time_iso.last_changed - states.sensor.rain_today.last_changed > timedelta(minutes=60) %} {% set mm_per_pulse = 0.30303 %} {% else %} {% set mm_per_pulse = 0.30303 %} {% endif %} {% set mm = count * mm_per_pulse %} {% if states('sensor.raingauge_tips') != 'unknown' %} {{ mm }} {% else %} {{ states('sensor.rain_today') }} {% endif %}")' for attribute '_attr_native_value' in entity 'sensor.rain_today'
and this:
Error while processing template: Template("{% set count = states('sensor.raingauge_tips') | int(0) %} {% if states.sensor.date_time_iso.last_changed - states.sensor.rain_today.last_changed > timedelta(minutes=60) %} {% set mm_per_pulse = 0.30303 %} {% else %} {% set mm_per_pulse = 0.30303 %} {% endif %} {% set mm = count * mm_per_pulse %} {% if states('sensor.raingauge_tips') != 'unknown' %} {{ mm }} {% else %} {{ states('sensor.rain_today') }} {% endif %}")
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/helpers/template.py", line 409, in async_render
render_result = _render_with_context(self.template, compiled, **kwargs)
File "/usr/src/homeassistant/homeassistant/helpers/template.py", line 1842, in _render_with_context
return template.render(**kwargs)
File "/usr/local/lib/python3.9/site-packages/jinja2/environment.py", line 1301, in render
self.environment.handle_exception()
File "/usr/local/lib/python3.9/site-packages/jinja2/environment.py", line 936, in handle_exception
raise rewrite_traceback_stack(source=source)
File "<template>", line 1, in top-level template code
jinja2.exceptions.UndefinedError: 'None' has no attribute 'last_changed'
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/helpers/template.py", line 525, in async_render_to_info
render_info._result = self.async_render(variables, strict=strict, **kwargs)
File "/usr/src/homeassistant/homeassistant/helpers/template.py", line 411, in async_render
raise TemplateError(err) from err
homeassistant.exceptions.TemplateError: UndefinedError: 'None' has no attribute 'last_changed'
I am quite confused about why this isn’t working. The binary sensor called rain
has an unknown state when I check it. The sensor rain_today
appears as unavailable. here is a screenshot with all the created sensors and their states:
Ignore the binary_sensor.rain_sensor
as that’s a rain sensor from my sprinklers.
Can someone help me out with this?
Hi All,
how did you fix the case when there is no state change of the gauge over a period of days?
My gauge sensor is since three days in the off mode (no rain), so having a history_stats sensor checking for the off state will report always 1 which results in a wrong value of rain_today sensor.
Thanks so much for this write up, it was really easy to follow. I didn’t want to wait for the gauge to arrive so I 3D printed one Zigbee Rain Gauge by CHARL13 - Thingiverse. I used the Sonoff contact switch but I don’t see why the Aqara wouldn’t fit either, it’s quite roomy. Just waiting for rain now!
Hey @parrel , great project and implementation.
Which one (forecast) did you use? I’m currently evaluating good weather forecasting services in the UK, so i’m very interested in this.
One more thing, on the placement of the reed sensor. I noticed someone saying that the tipping scale needs to be in balance. Currently i have one side go open and one side go closed. Is that not correct?
Finally is the restarting thing still an issue ? Do i need to create inverted sensors ?
Thanks,
Hi, thanks @atv!
I’m using Buienalarm, it’s a Dutch weather forecast and I’m not sure if it will work in the UK. But what you need is basically a list with times and the expected rainfall. Then with some Javascript you (or we) can make the forecast in the graph.
I’m not really sure what you mean with the tipping scale. My reed sensor is in the middle, and will only trigger for a millisecond when it tips to the other side. Then I count those triggered states with the history sensor.
The restarting issue was something I’ve never experienced, it seemed to be related zo Zigbee2MQTT and I use ZHA. I’m not sure if you still need to create the inverted sensors.
Ah, cool. I’ll go and check that out too.
In a previous post you mentioned:
Looks like the device has some internal debouncing system. What you could try is to move the reed sensor to one side of the bucket so if it’s tipped to the right the sensor is ‘on’ and to the left it’s ‘off’. You would have to modify the yaml if you go this route.
Mine’s also in the middle. There’s actually only very few devices where the aqara fits and works properly i find. Ah i also found a post from @doubleUS saying that
I also use an Aqara doorsensor. My default state is open . Make sure that the scale is in this state in both rest positions. Only if the scale is in balance it should have the state closed . The placement of the reed relay is quite important.
I don’t see how i can put the scale in rest position where it’s open for both. It’s either open or closed?
PS i just restarted, even though it registers the aqara as open, i did not see any increase in history stats. So that’s good
I’m still not really sure what the issue is. But to be honest, just follow the steps of the original post and you should be good.
What gauge do you have?
Hi All,
I have followed this post and rain gauge is working 100%. Have an issue with the template sensor. Every time I restart HA the template sensor drops to 0 and then back to original amount. Then my Weekly\Monthly\Yearly sensors adds the rainfall_today amount on top of the original amount.
Have anyone had the same or know how to fix this?
Thank you in advance
Johann, I think the availability line fixes this, here is mine.
- platform: template
sensors:
daily_rain:
friendly_name: Daily Rain
unit_of_measurement: mm
value_template: >-
{% set count = states('sensor.daily_gauge_flips') | int(0) %}
{% set mm_per_pulse = 0.30303 %}
{% set mm = count * mm_per_pulse %}
{{ mm|round(1, 'floor') }}
availability_template: "{{ (states('sensor.daily_gauge_flips') not in ('unknown', 'unavailable')) }}"
Thanx BigG. all good now
Same as yours. The question was about positioning of the reed switch.
I just downed a 20oz/600ml cup down the counter though, but it measures about 33.9mm ? Is that correct?
If you have the same gauge and the aqara sensor, you should just place the reed sensor in the middle.
That does not seem right. 1mm rain = 5,5ml so 600/5,5 should measure 109mm. However how did you test it? Because if you just poured the whole cup in there at once there is a big chance that you’re spilling a lot of water. You should simulate rain drops. One drop at a time and wait till it tips. I would suggest you use less water to test it.
I didn’t spill anything but i’m thinking maybe the tip does (inside the unit) once there is more water then it can hold it will go over? Although i would also expect the funnel to account for how much one side of the scale can hold.
I’ll re-test and do it more slowly.
Yes that what i meant . It takes some time for it to tip, and all the water that goes through the funnel at that moment will spill and won’t count.
It’s obviously not made for 100mm of rain in a minute.
Gotcha. I just tested with a Calpol syringe of 5ml and that was counted as 0.3mm. So something still not right. I’m using your exact sensor code.
I’ll try with 2 syringes/10ml and see what that brings. There may have been water left in the previous tip to throw it off but even then it seems on the low end. Maybe i just need to wait for actual rain to see if it’s really off much.
I didn’t calibrate anything as i got the exact same model but i’ll measure it nonetheless.
Try to tip it by hand and see if every tip is registered