I created an Accumulated rainfall sensor based on Dark Sky precipitation intensity. I have used it for a week and it is proportional to actual rainfall. I suggest if you need it represent actually rainfall, is to calibrate its reading to actually rainfall using a ratio.
I use it to know when to turn on a drain pump so I only need to know the level when the pump should go on, not the real rainfall measurement. I reset the measurement when the pump drains but you could change it to end of day or something like that.
Thanks Rob – Reading through the Python code that makes sense, I initially was reading through the Wikipedia article on Reimann sums and wasn’t getting it.
But reading through the source of the sensor this looks straight forward:
try:
# integration as the Riemann integral of previous measures.
area = 0
elapsed_time = (new_state.last_updated
- old_state.last_updated).total_seconds()
if self._method == TRAPEZOIDAL_METHOD:
area = (Decimal(new_state.state)
+ Decimal(old_state.state))*Decimal(elapsed_time)/2
elif self._method == LEFT_METHOD:
area = Decimal(old_state.state)*Decimal(elapsed_time)
elif self._method == RIGHT_METHOD:
area = Decimal(new_state.state)*Decimal(elapsed_time)
integral = area / (self._unit_prefix * self._unit_time)
assert isinstance(integral, Decimal)
I’ve setup both the integration sensor and your template sensor and will monitor them for awhile. Thank you!
So also the template sensor example is not correct. It triggers off of sensor.time so it will sum up the value whenever that entity_id updates.
The template sensor really needs to only be evaluated when sensor.dark_sky_precip_intensity is updated, but then also needs to reset at midnight — AND – it gets more complicated because by default sensor.dark_sky_precip_intensity updates every five minutes with the projected “rate” of rainfall in inches for the next hour.
If you simply sum up these values you will again have a grossly exaggerated rain fall total.
If you take the dark_sky_precip_intensity every minute for an hour and then divide the total by 60, should it give you the average rain per hour expected for the next hour?
Do you think the total of the template sensor is proportional to the actual rainfall?
For example, in your hastbin data, I note the sensor increased by 1 point from 12:45 to 17:19 and then another 1 point till 18:12. Was the actual rain fall during those times about equal?