Tipping rain gauge mqtt config for cumulative ( hour/day) graphing

Thanks! Certainly better:
2019-12-08_13-38

Now let me go and pour some rain into it and see how that goes…

Actually the template is not correct I just read the bit about “rained” being the message. Try this:

value_template: >
  {% if value == 'Rained' %}
    {{ states('sensor.rain_gauge')|float + 0.3537 }}
  {% else %}
    {{ states('sensor.rain_gauge')|float }}
  {% endif %}

Though I suspect this will not work either. This will only work if your di mini sends something other than ‘Rained’ after the ‘Rained’ message.

It would be a lot better if your d1 mini sent the number of bucket tips as the message rather than ‘Rained’. Then the template is just:

value_template: "{{ value * 0.3537 }}"

If you want a daily rain amount, use this sensor in the utility meter.

Yup - "{{ value * 0.3537 }}" throws TypeError: unsupported operand type(s) for /: 'str' and 'float'

The second one seems to be working - going to recompile the d1 mini, cause I like keeping it simple and will report back…

Right - So I recompiled the wemos firmware (shout if anyone wants it) to return a number, instead of a string - so now my config looks like:

 - platform: mqtt
    name: "rain_guage"
    state_topic: "sensor/rainswitch"
    icon: mdi:weather-rainy
    value_template: "{{ float(value) * 0.3537 }}"
    unit_of_measurement: 'mm'

Now - the problem is, the wemos only sends a 1 each time the bucket tips - I don’t get it to add up over time or anything.

Anyway - then I add

utility_meter:
  rain_daily:
    source: sensor.rain_guage
    cycle: daily
  rain_monthly:
    source: sensor.rain_guage
    cycle: monthly
  rain_weekly:
    source: sensor.rain_guage
    cycle: weekly

Now we wait a bit to see if things add up over time :grin:

Could you share your code? I’m interested in making it myself.

Any chance you would share the firmware? I would love to take a crack at making one…

Would be awesome if you cna share the D1mini code and how you hooked the misol to the mini

Also interested in details on the hardware and firmware integration

I’m very interested if this is working for you. I’ve set up a weather station a few months back. We finally had some rain yesterday and I got to see the rain gauge in action. Unfortunately, it’s not reporting what I was hoping.

The code (for ESPHome) looks like this:

time:
  - platform: homeassistant
    on_time:
      - seconds: 0
        minutes: 0
        hours: /1
        then:
          - sensor.integration.reset: rainfall_per_hour
  - platform: homeassistant
    on_time:
      - seconds: 0
        minutes: 0
        hours: 0
        then:
          - sensor.integration.reset: rainfall_per_day

sensor:
  - platform: pulse_counter
    pin: 
      number: D6
      mode: INPUT_PULLUP
    unit_of_measurement: 'in'
    name: 'Rainfall Per Minute'
    icon: 'mdi:weather-rainy'
    id: rainfall_per_minute
    count_mode:
      rising_edge: DISABLE
      falling_edge: INCREMENT
    internal_filter: 50us
    update_interval: 60s
    filters:
      - multiply: 0.011
    accuracy_decimals: 3

  - platform: integration
    name: "Rainfall Per Hour"
    id: rainfall_per_hour
    time_unit: h
    unit_of_measurement: 'in'
    sensor: rainfall_per_minute
    accuracy_decimals: 3

  - platform: integration
    name: "Rainfall Per Day"
    id: rainfall_per_day
    time_unit: d
    unit_of_measurement: 'in'
    sensor: rainfall_per_minute
    accuracy_decimals: 3

Charts look like this:
image image image

At first glance, it appears to be working but then if you look at the scales, something is wrong. The daily accumulation for yesterday only reached 0.4" while the rainfall per minute reached nearly 2.9" at some point. Anyway, I noticed that you’re using the utility_meter integrator. I might try that and see if it’s more like what I’d expect.

I’m sort of assuming that there’s a wiring or signaling problem because it’s very hard to believe that we got 2.9" in one minute (263 beats of the tip in one minute) but I’d like the math in ESPHome to line up at least for the accumulation/integration.

Thanks,
-Greg

Right - I see what there’s been some interest here…

What I’ve now settled on is as follows - On the wemos d1 mini, I switched from my custom written stuff to ESPHome. The ESPHome Yaml is:

esphome:
  name: misol_rainguage
  platform: ESP8266
  board: d1_mini

wifi:
  ssid: "SSID"
  password: "PW"
  use_address: "IP"

  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "Rainguage Fallback Hotspot"
    password: "PW"

captive_portal:

# Enable logging
logger:

# Enable Home Assistant API
api:
  password: "PW"

ota:
  password: "PW"

sensor:
  - platform: pulse_counter
    pin:
      number: D3
      mode: INPUT_PULLUP
      inverted: True
    internal_filter: 6us
    unit_of_measurement: "mm"
    name: 'Rainfall'
    accuracy_decimals: 3
    filters:
      - multiply: 0.367
      - debounce: 1s

The “Internal Filter” combined with the “debounce” seems to mean my measurement is correct (i.e. its only reading each switch event).

Naturally - you’ll have to add the ESPHome stuff to Home Assistant as well.

In my configuration.yaml

I put:

utility_meter:
  rain_daily:
    source: sensor.rainfall
    cycle: daily
  rain_weekly:
    source: sensor.rainfall
    cycle: weekly
  rain_monthly:
    source: sensor.rainfall
    cycle: monthly
  rain_yearly:
    source: sensor.rainfall
    cycle: yearly

Then in lovelace:

type: entities
entities:
  - entity: sensor.rainfall
  - entity: sensor.rain_daily
  - entity: sensor.rain_weekly
  - entity: sensor.rain_monthly
  - entity: sensor.rain_yearly

Gives something like this.

rain-guage

Naturally - you can add your various graphs etc. as you wish.

Much easier and simpler than what I was doing - hacking my own c code…

Yeah - first my gauge wasn’t reading much @ 13us (the default) - so I moved it down to 6us on the ‘internal_filter’ and upped the ‘debounce’ to 1s - seems to be ok now …

I’ll try out the debounce and see if that helps… now I just need some more rain. :cloud_with_rain:

That may solve the 2.9" measurement but still doesn’t address why the per-day accumulation is so much less than I’d expect. :neutral_face:

Yeah - I can see that you’re doing your accumulation on the measuring device.

My approach is to get raw data from the device and let the accumulation be done via HA.

You could just simply add the “utility_meter” stuff I’ve done in HA on your “rainfall_per_minute” sensor and see how that works - compare it to your device figures and if it gives you better results, then away you go…

I agree, I managed to get this working by just logging the tips of the rain gauge to influxdb, and having a cron job poll the influxdb and log the last 24 hours to a different influxdb value


! crontab
*/5 * * * * perl /home/radmin/homescripts/rain_gauge_sum.pl

! rain_gauge_sum.pl
`
#!/usr/bin/perl

our $key_name=“RainGauge”;
my $value=&GetCurrentSum;
&PostValue($value);

sub GetCurrentSum
{

@output=influx -format=csv -execute 'SELECT sum(*) FROM "RainGauge" where time > now() - 24h' -database=udp_loggers;
foreach (@output)
{
chomp();
($key,$time_val,$value) = split (/,/);
if ($key eq $key_name) { return $value;

}

}
die “key not found $key_name\n”;
}

sub PostValue
{ my $value_post=shift;
print influx -execute 'INSERT RainGaugeSum,name=value value=$value_post' -database=udp_loggers;

}

!

`

fyi, the graph loses accuracy as I had 2 days of power outage on 10/29, hence the slope…
Future enhancements could be to calibrate to estimate inches of rainfall, instead of just tips of the rain bucket…

I wanted to mention that I got this to work (completely from inside ESPHome):

image

ESPHome creates two integration sensors one for each accumulation.

time:
  - platform: homeassistant
    timezone: America/Somewhere
    on_time:
      - seconds: 0
        minutes: 0
        hours: /1
        then:
          - sensor.integration.reset: rainfall_per_hour
      - seconds: 0
        minutes: 0
        hours: 0
        then:
          - sensor.integration.reset: rainfall_per_day

sensor:
  - platform: pulse_counter
    pin: 
      number: D6
      mode: INPUT_PULLUP
    unit_of_measurement: 'in'
    name: 'Rainfall Per Minute'
    icon: 'mdi:weather-rainy'
    id: rainfall_per_minute
    count_mode:
      rising_edge: DISABLE
      falling_edge: INCREMENT
    internal_filter: 50us
    update_interval: 60s
    filters:
      - multiply: 0.011
      - debounce: 400ms
    accuracy_decimals: 3

  - platform: integration
    name: "Rainfall Per Hour"
    id: rainfall_per_hour
    time_unit: min
    unit_of_measurement: 'in'
    sensor: rainfall_per_minute
    accuracy_decimals: 3

  - platform: integration
    name: "Rainfall Per Day"
    id: rainfall_per_day
    time_unit: min
    unit_of_measurement: 'in'
    sensor: rainfall_per_minute
    accuracy_decimals: 3

It resets in accordance with the time thresholds (on the minute, on the hour, on the day, on the month) but I really want to display a running average in the chart and I’m having a hard time wrapping my head around how to do that (maybe I shouldn’t use the integration sensor since I have to reset it manually?) I wonder if a template sensor (updated every 60s) with a sliding_window_moving_average is more what I want… I’ll have to play with that a little.

Hi,

I have read the course but somehow I am not quite able to get by, someone may be able to help me a little.

I also use the rain sensor from Misol, which I connected to a Wemo D1 mini with Tasmota.
I transmit the counting pulse via MQTT as a switch (end position = off, movement is ON; 1 off-on-off is a pulse)
However, I cannot set up an evaluation in mm / qm according to time intervals.

I created a rain sensor as follows.

sensor rain:
  platform: mqtt
  state_topic: "stat/Wetterstation2/POWER"
  name: "Regen"

Sensor1

But the conversion and expanded display somehow doesn’t work

best regards

Gerald

Yeah - not sure how to count mqtt events.

Using esphome’s pulse counter worked for me.
In fact, I’ve moved most of my devices off tasmota to esphome - it is way easier to manage for me.

Hi ,

Has anyone succeeded to deep sleep the Wemos and wake up on the first “tip” of the bucket.?

I’m using the tipping bucket with a Coolcam door sensor and it’s far from reliable so am looking for an alternative but the power consumption of the D1 is draining the 18650 too fast (solar panel charged)
Any guidance is more than appreciated !

Is the complete ESPhome code available, including the MQTT?

I’m a very new beginner in ESPhome and tryning to learn by examples.

I saw the MQTT entry, but did not nderstand how it’s triggered from the sensor pulse_counter.

Thx in advance!